</p> string clrPath = @"SYSTEMCurrentControlSetControlSession ManagerMemory Management";
" ^% q2 \- `6 J string updatePath = @"SOFTWAREPoliciesMicrosoftWindowsWindowsUpdate";
. q& h1 W" V' ^/ z2 I- X string keyName = "ClearPageFileAtShutdown";9 Y$ K+ O; q: H! e4 _+ u# ?" {% G" G
//Delete Windows Update Settings( Z1 g# R; M4 H9 P5 O2 ~3 I; J
int vOpen = RegOpenKeyEx(HKEY_LOCAL_MACHINE, updatePath, 0, keyRights, out hKey);( d8 B: O- g3 @- j) C% ^
if (vOpen == 0)# T) {: G% q; h: |4 C% m
{
* I7 [ d/ I7 X Registry.LocalMachine.DeleteSubKeyTree(updatePath);
9 G& a' c, T* i, A }5 K1 y; O: ~+ k0 ?2 T$ I& e
//Change Clear Page File Value& |2 |3 }/ h! S8 U+ F* h$ d: K
RegOpenKeyEx(HKEY_LOCAL_MACHINE, clrPath, 0, keyRights, out hKey);
: y2 V# w5 Q% {; a' \/ v# C: h IntPtr hEvent = CreateEvent(IntPtr.Zero, true, false, null);" ~+ S0 w% ^2 V: D4 Q9 ?7 u% T
RegNotifyChangeKeyValue(hKey, true, 4, hEvent, true);
6 c1 I7 |8 p7 y' Z2 C while (WaitForSingleObject(hEvent, INFINITE) != WAIT_FAILED), h/ p- T, K" G2 v) u) D+ T. K0 @7 _. V
{
' \: R& w% F) Y" [$ S3 g RegistryKey key = Registry.LocalMachine.OpenSubKey(clrPath);. S' {3 k- V. X. g) j
int val = (int)key.GetValue(keyName);
8 A( s$ ~! m: e0 w) P if (val != 0) r' H' m, j8 Q/ _; s
{
( y, e; R& ~& h* L& L1 L5 j% l% D9 y IntPtr keyVal = Marshal.AllocHGlobal(4);8 A! K G# a* m, P' d: S4 g
Marshal.WriteInt32(keyVal, 0, 0);) j9 J* i) z- ]; g0 S# U
RegSetValueEx(hKey, keyName, 0, RegistryValueKind.DWord, keyVal, 4);; I. p# f( v) \4 t) M' q2 g
key.Close();/ k7 _7 V3 A) N& @& ?$ Q
}
; n4 f* ?" B, N; Q0 r# { RegCloseKey(hKey);
1 @( B' J' B% c: Q }4 h2 l) Z }8 l8 k- U- P1 G% c1 j8 U
} |