00081 {
00082
DWORD Status;
00083
00084 HKEY TestKeyHandle;
00085 HKEY Key1Handle;
00086 HKEY Key2Handle;
00087 HKEY EnvironmentHandle;
00088
00089 WCHAR ValueData[] =
VALUE_DATA;
00090
00091 WCHAR BufferForKeyName[100];
00092 WCHAR BufferForKeyClass[100];
00093 WCHAR BufferForValueEntryName[100];
00094
BYTE BufferForValueEntryData[100];
00095
00096
00097
DWORD DataType;
00098
DWORD DataSize;
00099
DWORD NameSize;
00100
DWORD ClassSize;
00101
00102
00103
DWORD cSubKeys;
00104
DWORD cbMaxSubkey;
00105
DWORD cbMaxClass;
00106
DWORD cValues;
00107
DWORD vbMaxValueName;
00108
DWORD cbMaxValueData;
00109
DWORD cbSecurityDescriptor;
00110 FILETIME ftLastWriteTime;
00111
00112
00113
BYTE BufferForSecurityDescriptor[2048];
00114
00115 HANDLE NotificationEvent;
00116
00117 PWSTR File1 =
L"d:\\File1";
00118 PWSTR File2 =
L"d:\\File2";
00119
DWORD Disposition;
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 NotificationEvent = CreateEvent( NULL,
00144 FALSE,
00145 FALSE,
00146 NULL );
00147
00148
if( NotificationEvent ==
NULL ) {
00149 printf(
"CreateEvent failed, ErrorCode = %d \n", GetLastError() );
00150 }
00151
00152
00153
00154
Status = RegOpenKeyExW( HKEY_CURRENT_USER,
00155 TESTKEY_FULL_NAME,
00156 0,
00157 MAXIMUM_ALLOWED,
00158 &TestKeyHandle );
00159
00160
if(
Status != 0 ) {
00161 printf(
"RegOpenKeyExW failed, Status = %d \n", Status );
00162 }
else {
00163 printf(
"RegOpenKeyExW succeeded \n" );
00164 }
00165
00166
00167
Status = RegOpenKeyW( HKEY_CURRENT_USER,
00168 ENVIRONMENT_NAME,
00169 &EnvironmentHandle );
00170
00171
if(
Status != 0 ) {
00172 printf(
"RegOpenKeyW failed, Status = %d \n", Status );
00173 }
else {
00174 printf(
"RegOpenKeyW succeeded \n" );
00175 }
00176
00177
00178
00179
00180
00181
00182
Status = RegCreateKeyExW( TestKeyHandle,
00183 KEY1_NAME,
00184 NULL,
00185 NULL,
00186 REG_OPTION_NON_VOLATILE,
00187 MAXIMUM_ALLOWED,
00188 NULL,
00189 &Key1Handle,
00190 &Disposition );
00191
00192
if(
Status != 0 ) {
00193 printf(
"RegCreateKeyExW failed, Status = %d \n", Status );
00194 }
else {
00195 printf(
"RegCreateKeyExW succeeded \n" );
00196 }
00197
00198
00199
00200
Status = RegCreateKeyW( TestKeyHandle,
00201 KEY2_NAME,
00202 &Key2Handle );
00203
00204
00205
if(
Status != 0 ) {
00206 printf(
"RegCreateKeyW failed, Status = %d \n", Status );
00207 }
else {
00208 printf(
"RegCreateKeyW succeeded \n" );
00209 }
00210
00211
00212
Status = RegSetValueExW( Key1Handle,
00213 VALUE_NAME,
00214 NULL,
00215 REG_SZ,
00216 ValueData,
00217
sizeof( ValueData ) );
00218
00219
if(
Status != 0 ) {
00220 printf(
"RegSetValueExW failed, Status = %d \n", Status );
00221 }
else {
00222 printf(
"RegSetValueExW succeeded \n" );
00223 }
00224
00225
00226
Status = RegSetValueW( Key1Handle,
00227 NULL,
00228 REG_SZ,
00229 ValueData,
00230
sizeof( ValueData ) );
00231
00232
if(
Status != 0 ) {
00233 printf(
"RegSetValueW failed, Status = %d \n", Status );
00234 }
else {
00235 printf(
"RegSetValueW succeeded \n" );
00236 }
00237
00238
00239
00240
Status = RegFlushKey( Key1Handle );
00241
if(
Status != 0 ) {
00242 printf(
"RegFlushKey failed, Status = %d \n", Status );
00243 }
else {
00244 printf(
"RegFlushKey succeeded \n" );
00245 }
00246
00247
00248
00249
00250 DataSize =
sizeof( BufferForValueEntryData );
00251 memset( BufferForValueEntryData,
'\0', DataSize );
00252
Status = RegQueryValueExW( Key1Handle,
00253 VALUE_NAME,
00254 NULL,
00255 &DataType,
00256 BufferForValueEntryData,
00257 &DataSize );
00258
00259
if(
Status != 0 ) {
00260 printf(
"RegQueryValueExW failed, Status = %d \n", Status );
00261 }
else {
00262 printf(
"RegQueryValueExW succeeded \n" );
00263 }
00264
00265
00266
00267 DataSize =
sizeof( BufferForValueEntryData );
00268 memset( BufferForValueEntryData,
'\0', DataSize );
00269
Status = RegQueryValueW( Key1Handle,
00270 NULL,
00271 BufferForValueEntryData,
00272 &DataSize );
00273
00274
00275
if(
Status != 0 ) {
00276 printf(
"RegQueryValueW failed, Status = %d \n", Status );
00277 }
else {
00278 printf(
"RegQueryValueW succeeded \n" );
00279 }
00280
00281
00282 DataSize =
sizeof( BufferForValueEntryData );
00283 memset( BufferForValueEntryData,
'X', DataSize );
00284 NameSize =
sizeof( BufferForValueEntryName );
00285 memset( BufferForValueEntryName,
'X', NameSize );
00286
00287
Status = RegEnumValueW( Key1Handle,
00288 0,
00289 BufferForValueEntryName,
00290 &NameSize,
00291 NULL,
00292 &DataType,
00293 BufferForValueEntryData,
00294 &DataSize );
00295
00296
00297
if(
Status != 0 ) {
00298 printf(
"RegEnumValueW failed, Status = %d \n", Status );
00299 }
else {
00300 printf(
"RegEnumValueW succeeded \n" );
00301 }
00302
00303
00304 NameSize =
sizeof( BufferForKeyName );
00305 ClassSize =
sizeof( BufferForKeyClass );
00306
Status = RegEnumKeyExW( TestKeyHandle,
00307 0,
00308 BufferForKeyName,
00309 &NameSize,
00310 NULL,
00311 BufferForKeyClass,
00312 &ClassSize,
00313 &ftLastWriteTime );
00314
00315
if(
Status != 0 ) {
00316 printf(
"RegEnumKeyExW failed, Status = %d \n", Status );
00317 }
else {
00318 printf(
"RegEnumKeyExW succeeded \n" );
00319 }
00320
00321
00322 NameSize =
sizeof( BufferForKeyName );
00323
Status = RegEnumKeyW( TestKeyHandle,
00324 0,
00325 BufferForKeyName,
00326 &NameSize );
00327
00328
if(
Status != 0 ) {
00329 printf(
"RegEnumKeyW failed, Status = %d \n", Status );
00330 }
else {
00331 printf(
"RegEnumKeyW succeeded \n" );
00332 }
00333
00334
00335 ClassSize =
sizeof( BufferForKeyClass );
00336
Status = RegQueryInfoKeyW( Key1Handle,
00337 BufferForKeyClass,
00338 &ClassSize,
00339 NULL,
00340 &cSubKeys,
00341 &cbMaxSubkey,
00342 &cbMaxClass,
00343 &cValues,
00344 &vbMaxValueName,
00345 &cbMaxValueData,
00346 &cbSecurityDescriptor,
00347 &ftLastWriteTime );
00348
00349
00350
00351
if(
Status != 0 ) {
00352 printf(
"RegQueryInfoKeyW failed, Status = %d \n", Status );
00353 }
else {
00354 printf(
"RegQueryInfoKeyW succeeded \n" );
00355 }
00356
00357
00358
Status = RegGetKeySecurity( Key1Handle,
00359 DACL_SECURITY_INFORMATION,
00360 ( PSECURITY_DESCRIPTOR )BufferForSecurityDescriptor,
00361 &cbSecurityDescriptor );
00362
00363
if(
Status != 0 ) {
00364 printf(
"RegGetKeySecurity failed, Status = %d \n", Status );
00365 }
else {
00366 printf(
"RegGetKeySecurity succeeded \n" );
00367 }
00368
00369
00370
00371
Status = RegSetKeySecurity( Key1Handle,
00372 DACL_SECURITY_INFORMATION,
00373 ( PSECURITY_DESCRIPTOR )BufferForSecurityDescriptor );
00374
00375
if(
Status != 0 ) {
00376 printf(
"RegSetKeySecurity failed, Status = %d \n", Status );
00377 }
else {
00378 printf(
"RegSetKeySecurity succeeded \n" );
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
Status = RegDeleteValueW( Key1Handle,
00408 VALUE_NAME );
00409
00410
00411
if(
Status != 0 ) {
00412 printf(
"RegDeleteValueW failed, Status = %d \n", Status );
00413 }
else {
00414 printf(
"RegDeleteValueW succeeded \n" );
00415 }
00416
00417
00418
Status = RegCloseKey( Key1Handle );
00419
00420
if(
Status != 0 ) {
00421 printf(
"RegCloseKey failed, Status = %d \n", Status );
00422 }
else {
00423 printf(
"RegCloseKey succeeded \n" );
00424 }
00425
00426
Status = RegDeleteKeyW( TestKeyHandle,
00427 KEY1_NAME );
00428
00429
if(
Status != 0 ) {
00430 printf(
"RegCloseKey failed, Status = %d \n", Status );
00431 }
else {
00432 printf(
"RegCloseKey succeeded \n" );
00433 }
00434
00435
00436
Status = RegNotifyChangeKeyValue( HKEY_CURRENT_USER,
00437 TRUE,
00438 REG_NOTIFY_CHANGE_NAME |
00439 REG_NOTIFY_CHANGE_ATTRIBUTES |
00440 REG_NOTIFY_CHANGE_LAST_SET |
00441 REG_NOTIFY_CHANGE_SECURITY,
00442 NotificationEvent,
00443 TRUE );
00444
00445
if(
Status != 0 ) {
00446 printf(
"RegNotifyChangeKeyValue failed, Status = %d \n", Status );
00447 }
else {
00448 printf(
"RegNotifyChangeKeyValue succeeded \n" );
00449 }
00450
00451
00452
00453
00454
00455
00456 CloseHandle( NotificationEvent );
00457
00458 RegCloseKey( Key2Handle );
00459 RegDeleteKeyW( TestKeyHandle,
00460 KEY2_NAME );
00461
00462
00463 }