1fbd274acd95d45d4815dafff3dd8b2e38e264dd
[reactos.git] / rosapps / tests / hivetest / hivetest.c
1 #include <stdarg.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <windows.h>
5 #include <ddk/ntddk.h>
6 #include <rosrtl/string.h>
7
8 HANDLE OutputHandle;
9 HANDLE InputHandle;
10
11 void dprintf(char* fmt, ...)
12 {
13 va_list args;
14 char buffer[255];
15
16 va_start(args,fmt);
17 vsprintf(buffer,fmt,args);
18 WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
19 va_end(args);
20 }
21
22 void do_enumeratekey(PWSTR Name)
23 {
24 ULONG Index,Length,i;
25 KEY_BASIC_INFORMATION KeyInformation[5];
26 NTSTATUS Status;
27 OBJECT_ATTRIBUTES ObjectAttributes;
28 HANDLE hKey1;
29 UNICODE_STRING KeyName;
30
31 RtlInitUnicodeString(&KeyName, Name);
32 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
33 , NULL, NULL);
34 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
35 dprintf("NtEnumerateKey : \n");
36 Index=0;
37 while(Status == STATUS_SUCCESS)
38 {
39 Status=NtEnumerateKey(hKey1,Index++,KeyBasicInformation
40 ,&KeyInformation[0], sizeof(KeyInformation)
41 ,&Length);
42 if(Status== STATUS_SUCCESS)
43 {
44 dprintf("\tSubKey Name = ");
45 for (i=0;i<KeyInformation[0].NameLength/2;i++)
46 dprintf("%C",KeyInformation[0].Name[i]);
47 dprintf("\n");
48 }
49 }
50 NtClose(hKey1);
51 }
52
53
54 void CreateKeyTest(void)
55 {
56 HKEY hKey;
57 OBJECT_ATTRIBUTES ObjectAttributes;
58 UNICODE_STRING KeyName;
59 NTSTATUS Status;
60
61 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
62 RtlRosInitUnicodeStringFromLiteral(&KeyName,
63 L"\\Registry\\Machine\\Software\\testkey");
64 InitializeObjectAttributes(&ObjectAttributes,
65 &KeyName,
66 OBJ_CASE_INSENSITIVE,
67 NULL,
68 NULL);
69 dprintf("NtCreateKey:\n");
70 Status = NtCreateKey(&hKey,
71 KEY_ALL_ACCESS,
72 &ObjectAttributes,
73 0,
74 NULL,
75 REG_OPTION_NON_VOLATILE,
76 NULL);
77 dprintf(" Status = %lx\n",Status);
78 if (NT_SUCCESS(Status))
79 {
80 NtClose(hKey);
81 }
82 }
83
84
85 void DeleteKeyTest(void)
86 {
87 OBJECT_ATTRIBUTES ObjectAttributes;
88 UNICODE_STRING KeyName;
89 HKEY hKey;
90 NTSTATUS Status;
91
92 dprintf("Delete key '\\Registry\\Machine\\Software\\testkey':\n");
93 RtlRosInitUnicodeStringFromLiteral(&KeyName,
94 L"\\Registry\\Machine\\Software\\testkey");
95 InitializeObjectAttributes(&ObjectAttributes,
96 &KeyName,
97 OBJ_CASE_INSENSITIVE,
98 NULL,
99 NULL);
100 dprintf("NtOpenKey:\n");
101 Status = NtOpenKey(&hKey,
102 KEY_ALL_ACCESS,
103 &ObjectAttributes);
104 dprintf(" Status = %lx\n",Status);
105 if (!NT_SUCCESS(Status))
106 return;
107
108 dprintf("NtDeleteKey:\n");
109 Status = NtDeleteKey(hKey);
110 dprintf(" Status = %lx\n",Status);
111 NtClose(hKey);
112 }
113
114
115 void EnumerateKeyTest(void)
116 {
117 HKEY hKey = NULL;
118 OBJECT_ATTRIBUTES ObjectAttributes;
119 NTSTATUS Status;
120 UNICODE_STRING KeyName;
121 ULONG Index;
122 ULONG Length;
123 ULONG i;
124 KEY_BASIC_INFORMATION KeyInformation[5];
125
126 dprintf("Enumerate key '\\Registry\\Machine\\Software':\n");
127 RtlRosInitUnicodeStringFromLiteral(&KeyName,
128 L"\\Registry\\Machine\\Software");
129 InitializeObjectAttributes(&ObjectAttributes,
130 &KeyName,
131 OBJ_CASE_INSENSITIVE,
132 NULL,
133 NULL);
134 dprintf("NtOpenKey:\n");
135 Status = NtOpenKey(&hKey,
136 KEY_ALL_ACCESS,
137 &ObjectAttributes);
138 dprintf(" Status = %lx\n", Status);
139 if (!NT_SUCCESS(Status))
140 return;
141
142 dprintf("NtQueryKey:\n");
143 Status = NtQueryKey(hKey,
144 KeyBasicInformation,
145 &KeyInformation[0],
146 sizeof(KeyInformation),
147 &Length);
148 dprintf(" Status = %lx\n", Status);
149 if (NT_SUCCESS(Status))
150 {
151 dprintf("\tKey Name = ");
152 for (i = 0; i < KeyInformation[0].NameLength / 2; i++)
153 dprintf("%C", KeyInformation[0].Name[i]);
154 dprintf("\n");
155 }
156
157 dprintf("NtEnumerateKey:\n");
158 Index=0;
159 while(NT_SUCCESS(Status))
160 {
161 Status = NtEnumerateKey(hKey,
162 Index,
163 KeyBasicInformation,
164 &KeyInformation[0],
165 sizeof(KeyInformation),
166 &Length);
167 if (NT_SUCCESS(Status))
168 {
169 dprintf("\tSubKey Name = ");
170 for (i = 0; i < KeyInformation[0].NameLength / 2; i++)
171 dprintf("%C", KeyInformation[0].Name[i]);
172 dprintf("\n");
173 }
174 Index++;
175 }
176
177 dprintf("NtClose:\n");
178 Status = NtClose(hKey);
179 dprintf(" Status = %lx\n", Status);
180 }
181
182
183 void SetValueTest1(void)
184 {
185 HKEY hKey;
186 OBJECT_ATTRIBUTES ObjectAttributes;
187 UNICODE_STRING KeyName;
188 UNICODE_STRING ValueName;
189 NTSTATUS Status;
190
191 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
192 RtlRosInitUnicodeStringFromLiteral(&KeyName,
193 L"\\Registry\\Machine\\Software\\testkey");
194 InitializeObjectAttributes(&ObjectAttributes,
195 &KeyName,
196 OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
197 NULL,
198 NULL);
199 dprintf("NtCreateKey:\n");
200 Status = NtCreateKey(&hKey,
201 KEY_ALL_ACCESS,
202 &ObjectAttributes,
203 0,
204 NULL,
205 REG_OPTION_NON_VOLATILE,
206 NULL);
207 dprintf(" Status = %lx\n",Status);
208 if (!NT_SUCCESS(Status))
209 return;
210
211 RtlRosInitUnicodeStringFromLiteral(&ValueName,
212 L"TestValue");
213 dprintf("NtSetValueKey:\n");
214 Status = NtSetValueKey(hKey,
215 &ValueName,
216 0,
217 REG_SZ,
218 (PVOID)L"TestString",
219 24);
220 dprintf(" Status = %lx\n",Status);
221
222 NtClose(hKey);
223 }
224
225
226 void SetValueTest2(void)
227 {
228 HKEY hKey;
229 OBJECT_ATTRIBUTES ObjectAttributes;
230 UNICODE_STRING KeyName;
231 UNICODE_STRING ValueName;
232 NTSTATUS Status;
233
234 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
235 RtlRosInitUnicodeStringFromLiteral(&KeyName,
236 L"\\Registry\\Machine\\Software\\testkey");
237 InitializeObjectAttributes(&ObjectAttributes,
238 &KeyName,
239 OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
240 NULL,
241 NULL);
242 dprintf("NtCreateKey:\n");
243 Status = NtCreateKey(&hKey,
244 KEY_ALL_ACCESS,
245 &ObjectAttributes,
246 0,
247 NULL,
248 REG_OPTION_NON_VOLATILE,
249 NULL);
250 dprintf(" Status = %lx\n",Status);
251 if (!NT_SUCCESS(Status))
252 return;
253
254 RtlRosInitUnicodeStringFromLiteral(&ValueName,
255 L"TestValue");
256 dprintf("NtSetValueKey:\n");
257 Status = NtSetValueKey(hKey,
258 &ValueName,
259 0,
260 REG_DWORD,
261 (PVOID)"reac",
262 4);
263 dprintf(" Status = %lx\n",Status);
264
265 NtClose(hKey);
266 }
267
268
269 void DeleteValueTest(void)
270 {
271 OBJECT_ATTRIBUTES ObjectAttributes;
272 UNICODE_STRING KeyName;
273 UNICODE_STRING ValueName;
274 HKEY KeyHandle;
275 NTSTATUS Status;
276
277 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
278 RtlRosInitUnicodeStringFromLiteral(&KeyName,
279 L"\\Registry\\Machine\\Software\\testkey");
280 InitializeObjectAttributes(&ObjectAttributes,
281 &KeyName,
282 OBJ_CASE_INSENSITIVE,
283 NULL,
284 NULL);
285 Status=NtOpenKey(&KeyHandle,
286 MAXIMUM_ALLOWED,
287 &ObjectAttributes);
288 dprintf(" Status = %lx\n", Status);
289 if (!NT_SUCCESS(Status))
290 return;
291
292 dprintf("Delete value:\n");
293 RtlRosInitUnicodeStringFromLiteral(&ValueName,
294 L"TestValue");
295 Status = NtDeleteValueKey(KeyHandle,
296 &ValueName);
297 dprintf(" Status = %lx\n", Status);
298
299 dprintf("Close key:\n");
300 Status = NtClose(KeyHandle);
301 dprintf(" Status = %lx\n", Status);
302 }
303
304
305 void EnumerateValueTest(void)
306 {
307 KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
308 OBJECT_ATTRIBUTES ObjectAttributes;
309 UNICODE_STRING KeyName;
310 ULONG Index,Length,i;
311 HKEY hKey = NULL;
312 NTSTATUS Status;
313
314 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
315 RtlRosInitUnicodeStringFromLiteral(&KeyName,
316 L"\\Registry\\Machine\\Software\\testkey");
317 InitializeObjectAttributes(&ObjectAttributes,
318 &KeyName,
319 OBJ_CASE_INSENSITIVE,
320 NULL,
321 NULL);
322 Status=NtOpenKey(&hKey,
323 MAXIMUM_ALLOWED,
324 &ObjectAttributes);
325 dprintf(" Status = %lx\n", Status);
326 if (!NT_SUCCESS(Status))
327 return;
328
329 dprintf("Enumerate values:\n");
330 Index = 0;
331 while (Status == STATUS_SUCCESS)
332 {
333 Status = NtEnumerateValueKey(hKey,
334 Index++,
335 KeyValueFullInformation,
336 &KeyValueInformation[0],
337 sizeof(KeyValueInformation),
338 &Length);
339 if (Status == STATUS_SUCCESS)
340 {
341 dprintf(" Value:DO=%d, DL=%d, NL=%d, Name = ",
342 KeyValueInformation[0].DataOffset,
343 KeyValueInformation[0].DataLength,
344 KeyValueInformation[0].NameLength);
345 for (i = 0; i < KeyValueInformation[0].NameLength / 2; i++)
346 dprintf("%C", KeyValueInformation[0].Name[i]);
347 dprintf(", Type = %d\n", KeyValueInformation[0].Type);
348
349 if (KeyValueInformation[0].Type == REG_SZ)
350 dprintf(" Value = %S\n",
351 ((char*)&KeyValueInformation[0]+KeyValueInformation[0].DataOffset));
352
353 if (KeyValueInformation[0].Type == REG_DWORD)
354 dprintf(" Value = %X\n",
355 *((DWORD*)((char*)&KeyValueInformation[0]+KeyValueInformation[0].DataOffset)));
356 }
357 }
358
359 dprintf("NtClose:\n");
360 Status = NtClose(hKey);
361 dprintf(" Status = %lx\n", Status);
362 }
363
364
365
366
367 void test1(void)
368 {
369 HKEY hKey = NULL, hKey1;
370 OBJECT_ATTRIBUTES ObjectAttributes;
371 NTSTATUS Status;
372 #if 0
373 UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry");
374 #endif
375 UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry\\Machine\\Software");
376 ULONG Index,Length,i;
377 KEY_BASIC_INFORMATION KeyInformation[5];
378
379 #if 0
380 dprintf("NtOpenKey \\Registry : ");
381 #endif
382 dprintf("NtOpenKey \\Registry\\Machine\\Software : ");
383 InitializeObjectAttributes(&ObjectAttributes,
384 &KeyName,
385 OBJ_CASE_INSENSITIVE,
386 NULL,
387 NULL);
388 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
389 dprintf("\t\t\t\tStatus =%x\n",Status);
390 if(Status==0)
391 {
392 dprintf("NtQueryKey : ");
393 Status=NtQueryKey(hKey1,KeyBasicInformation
394 ,&KeyInformation[0], sizeof(KeyInformation)
395 ,&Length);
396 dprintf("\t\t\t\t\tStatus =%x\n",Status);
397 if (Status == STATUS_SUCCESS)
398 {
399 dprintf("\tKey Name = ");
400 for (i=0;i<KeyInformation[0].NameLength/2;i++)
401 dprintf("%C",KeyInformation[0].Name[i]);
402 dprintf("\n");
403 }
404 dprintf("NtEnumerateKey : \n");
405 Index=0;
406 while(Status == STATUS_SUCCESS)
407 {
408 Status=NtEnumerateKey(hKey1,Index++,KeyBasicInformation
409 ,&KeyInformation[0], sizeof(KeyInformation)
410 ,&Length);
411 if(Status== STATUS_SUCCESS)
412 {
413 dprintf("\tSubKey Name = ");
414 for (i=0;i<KeyInformation[0].NameLength/2;i++)
415 dprintf("%C",KeyInformation[0].Name[i]);
416 dprintf("\n");
417 }
418 }
419 dprintf("NtClose : ");
420 Status = NtClose( hKey1 );
421 dprintf("\t\t\t\t\tStatus =%x\n",Status);
422 }
423 NtClose(hKey);
424
425 #if 0
426 dprintf("NtOpenKey \\Registry\\Machine : ");
427 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine");
428 InitializeObjectAttributes(&ObjectAttributes,
429 &KeyName,
430 OBJ_CASE_INSENSITIVE,
431 NULL,
432 NULL);
433 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
434 dprintf("\t\t\tStatus =%x\n",Status);
435
436 dprintf("NtOpenKey System\\Setup : ");
437 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"System\\Setup");
438 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
439 , hKey1 , NULL);
440 Status = NtOpenKey ( &hKey, KEY_READ , &ObjectAttributes);
441 dprintf("\t\t\tStatus =%x\n",Status);
442 if(Status==0)
443 {
444 dprintf("NtQueryValueKey : ");
445 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"CmdLine");
446 Status=NtQueryValueKey(hKey,&KeyName,KeyValueFullInformation
447 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
448 ,&Length);
449 dprintf("\t\t\t\tStatus =%x\n",Status);
450 if (Status == STATUS_SUCCESS)
451 {
452 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
453 ,KeyValueInformation[0].DataOffset
454 ,KeyValueInformation[0].DataLength
455 ,KeyValueInformation[0].NameLength);
456 for (i=0;i<10 && i<KeyValueInformation[0].NameLength/2;i++)
457 dprintf("%C",KeyValueInformation[0].Name[i]);
458 dprintf("\n");
459 dprintf("\t\tType = %d\n",KeyValueInformation[0].Type);
460 if (KeyValueInformation[0].Type == REG_SZ)
461 dprintf("\t\tValue = %S\n",
462 (PWCHAR)((PCHAR)&KeyValueInformation[0] + KeyValueInformation[0].DataOffset));
463 }
464 dprintf("NtEnumerateValueKey : \n");
465 Index=0;
466 while(Status == STATUS_SUCCESS)
467 {
468 Status=NtEnumerateValueKey(hKey,Index++,KeyValueFullInformation
469 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
470 ,&Length);
471 if(Status== STATUS_SUCCESS)
472 {
473 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
474 ,KeyValueInformation[0].DataOffset
475 ,KeyValueInformation[0].DataLength
476 ,KeyValueInformation[0].NameLength);
477 for (i=0;i<KeyValueInformation[0].NameLength/2;i++)
478 dprintf("%C",KeyValueInformation[0].Name[i]);
479 dprintf(", Type = %d\n",KeyValueInformation[0].Type);
480 if (KeyValueInformation[0].Type == REG_SZ)
481 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation[0]
482 +KeyValueInformation[0].DataOffset));
483 }
484 }
485 dprintf("NtClose : ");
486 Status = NtClose( hKey );
487 dprintf("\t\t\t\t\tStatus =%x\n",Status);
488 }
489 NtClose( hKey1 );
490 #endif
491 }
492
493
494 void test3(void)
495 {
496 HKEY hKey;
497 OBJECT_ATTRIBUTES ObjectAttributes;
498 UNICODE_STRING KeyName;
499 NTSTATUS Status;
500 char Buffer[10];
501 DWORD Result;
502 dprintf("NtCreateKey non volatile: \n");
503 dprintf(" \\Registry\\Machine\\Software\\test3reactos: ");
504 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
505 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
506 , NULL, NULL);
507 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
508 ,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
509 dprintf("\t\tStatus=%x\n",Status);
510 NtClose(hKey);
511 #if 0
512 do_enumeratekey(L"\\Registry\\Machine\\Software");
513 dprintf("NtOpenKey: ");
514 Status=NtOpenKey( &hKey, MAXIMUM_ALLOWED, &ObjectAttributes);
515 dprintf("\t\tStatus=%x\n",Status);
516 NtClose(hKey);
517 dprintf(" ...\\test3 :");
518 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3");
519 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
520 , NULL, NULL);
521 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
522 ,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
523 dprintf("\t\t\t\t\tStatus=%x\n",Status);
524 dprintf("NtOpenKey: ");
525 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
526 dprintf("\t\tStatus=%x\n",Status);
527 NtClose(hKey);
528 dprintf(" ...\\testNonVolatile :");
529 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"TestNonVolatile");
530 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
531 , hKey1, NULL);
532 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
533 ,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
534 dprintf("\t\t\t\tStatus=%x\n",Status);
535 NtClose(hKey1);
536 RtlRosInitUnicodeStringFromLiteral(&ValueName, L"TestREG_SZ");
537 dprintf("NtSetValueKey reg_sz: ");
538 Status=NtSetValueKey(hKey,&ValueName,0,REG_SZ,(PVOID)L"Test Reg_sz",24);
539 dprintf("\t\t\t\tStatus=%x\n",Status);
540 RtlRosInitUnicodeStringFromLiteral(&ValueName, L"TestDWORD");
541 dprintf("NtSetValueKey reg_dword: ");
542 Status=NtSetValueKey(hKey,&ValueName,0,REG_DWORD,(PVOID)"reac",4);
543 dprintf("\t\t\tStatus=%x\n",Status);
544 NtClose(hKey);
545 dprintf("NtOpenKey \\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile : ");
546 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile");
547 InitializeObjectAttributes(&ObjectAttributes,
548 &KeyName,
549 OBJ_CASE_INSENSITIVE,
550 NULL,
551 NULL);
552 Status=NtOpenKey( &hKey, MAXIMUM_ALLOWED, &ObjectAttributes);
553 dprintf("\t\t\t\tStatus =%x\n",Status);
554 if(Status==0)
555 {
556 dprintf("NtEnumerateValueKey : \n");
557 Index=0;
558 while(Status == STATUS_SUCCESS)
559 {
560 Status=NtEnumerateValueKey(hKey,Index++,KeyValueFullInformation
561 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
562 ,&Length);
563 if(Status== STATUS_SUCCESS)
564 {
565 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
566 ,KeyValueInformation[0].DataOffset
567 ,KeyValueInformation[0].DataLength
568 ,KeyValueInformation[0].NameLength);
569 for (i=0;i<KeyValueInformation[0].NameLength/2;i++)
570 dprintf("%C",KeyValueInformation[0].Name[i]);
571 dprintf(", Type = %d\n",KeyValueInformation[0].Type);
572 if (KeyValueInformation[0].Type == REG_SZ)
573 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation[0]
574 +KeyValueInformation[0].DataOffset));
575 }
576 }
577 }
578 NtClose(hKey);
579 #endif
580
581 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
582 ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
583 if (Buffer[0] != 'y' && Buffer[0] != 'Y') return;
584 #if 0
585 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonvolatile");
586 InitializeObjectAttributes(&ObjectAttributes,
587 &KeyName,
588 OBJ_CASE_INSENSITIVE,
589 NULL,
590 NULL);
591 dprintf("NtOpenKey : ");
592 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
593 dprintf("\t\t\t\tStatus =%x\n",Status);
594 dprintf("NtDeleteKey : ");
595 Status=NtDeleteKey(hKey);
596 dprintf("\t\t\t\tStatus =%x\n",Status);
597 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3");
598 InitializeObjectAttributes(&ObjectAttributes,
599 &KeyName,
600 OBJ_CASE_INSENSITIVE,
601 NULL,
602 NULL);
603 dprintf("NtOpenKey : ");
604 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
605 dprintf("\t\t\t\tStatus =%x\n",Status);
606 dprintf("NtDeleteKey : ");
607 Status=NtDeleteKey(hKey);
608 dprintf("\t\t\t\tStatus =%x\n",Status);
609 NtClose(hKey);
610 #endif
611 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
612 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
613 InitializeObjectAttributes(&ObjectAttributes,
614 &KeyName,
615 OBJ_CASE_INSENSITIVE,
616 NULL,
617 NULL);
618 dprintf("NtOpenKey : ");
619 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
620 dprintf("\t\t\t\tStatus =%x\n",Status);
621 dprintf("NtDeleteKey : ");
622 Status=NtDeleteKey(hKey);
623 dprintf("\t\t\t\tStatus =%x\n",Status);
624 NtClose(hKey);
625 }
626
627 void test4(void)
628 {
629 HKEY hKey = NULL,hKey1;
630 DWORD dwDisposition;
631 DWORD dwError;
632 DWORD RegDataType, RegDataSize;
633 BOOL GlobalFifoEnable;
634 HKEY hPortKey;
635 DWORD RegDisposition;
636 WCHAR szClass[260];
637 DWORD cchClass;
638 DWORD cSubKeys;
639 DWORD cchMaxSubkey;
640 DWORD cchMaxClass;
641 DWORD cValues;
642 DWORD cchMaxValueName;
643 DWORD cbMaxValueData;
644 DWORD cbSecurityDescriptor;
645 FILETIME ftLastWriteTime;
646 SYSTEMTIME LastWriteTime;
647
648 dprintf ("RegOpenKeyExW HKLM\\System\\Setup: ");
649 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
650 L"System\\Setup",
651 0,
652 KEY_ALL_ACCESS,
653 &hKey1);
654 dprintf("\t\tdwError =%x\n",dwError);
655 if (dwError == ERROR_SUCCESS)
656 {
657 dprintf("RegQueryInfoKeyW: ");
658 cchClass=260;
659 dwError = RegQueryInfoKeyW(hKey1
660 , szClass, &cchClass, NULL, &cSubKeys
661 , &cchMaxSubkey, &cchMaxClass, &cValues, &cchMaxValueName
662 , &cbMaxValueData, &cbSecurityDescriptor, &ftLastWriteTime);
663 dprintf ("\t\t\t\tdwError %x\n", dwError);
664 FileTimeToSystemTime(&ftLastWriteTime,&LastWriteTime);
665 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
666 ,LastWriteTime.wMonth
667 ,LastWriteTime.wDay
668 ,LastWriteTime.wYear
669 ,LastWriteTime.wHour
670 ,LastWriteTime.wMinute
671 ,LastWriteTime.wSecond
672 ,LastWriteTime.wMilliseconds
673 );
674 }
675
676
677 dprintf ("RegOpenKeyExW: ");
678 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
679 L"System\\ControlSet001\\Services\\Serial",
680 0,
681 KEY_ALL_ACCESS,
682 &hKey);
683 dprintf ("\t\t\t\t\tdwError %x\n", dwError);
684 RegDataSize = sizeof(GlobalFifoEnable);
685 if (dwError == ERROR_SUCCESS)
686 {
687 dprintf ("RegQueryValueExW: ");
688 dwError = RegQueryValueExW(hKey,
689 L"ForceFifoEnable",
690 NULL,
691 &RegDataType,
692 (PBYTE)&GlobalFifoEnable,
693 &RegDataSize);
694 dprintf("\t\t\t\tdwError =%x\n",dwError);
695 if (dwError == 0)
696 {
697 dprintf("\tValue:DT=%d, DS=%d, Value=%d\n"
698 ,RegDataType
699 ,RegDataSize
700 ,GlobalFifoEnable);
701 }
702 }
703 dprintf ("RegCreateKeyExW: ");
704 dwError = RegCreateKeyExW(hKey,
705 L"Parameters\\Serial001",
706 0,
707 NULL,
708 0,
709 KEY_ALL_ACCESS,
710 NULL,
711 &hPortKey,
712 &RegDisposition
713 );
714 dprintf ("\t\t\t\tdwError %x\n", dwError);
715
716 dprintf ("RegCreateKeyExW: ");
717 dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
718 L"Software\\test4reactos\\test",
719 0,
720 NULL,
721 REG_OPTION_NON_VOLATILE,
722 KEY_ALL_ACCESS,
723 NULL,
724 &hKey,
725 &dwDisposition);
726
727 dprintf ("\t\t\t\tdwError %x ", dwError);
728 dprintf ("dwDisposition %x\n", dwDisposition);
729 if (dwError == ERROR_SUCCESS)
730 {
731 dprintf ("RegSetValueExW: ");
732 dwError = RegSetValueExW (hKey,
733 L"TestValue",
734 0,
735 REG_SZ,
736 (BYTE*)L"TestString",
737 20);
738
739 dprintf ("\t\t\t\tdwError %x\n", dwError);
740 dprintf ("RegCloseKey: ");
741 dwError = RegCloseKey (hKey);
742 dprintf ("\t\t\t\t\tdwError %x\n", dwError);
743 }
744 dprintf ("\n\n");
745
746 hKey = NULL;
747
748 dprintf ("RegCreateKeyExW: ");
749 dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
750 L"software\\Test",
751 0,
752 NULL,
753 REG_OPTION_VOLATILE,
754 KEY_ALL_ACCESS,
755 NULL,
756 &hKey,
757 &dwDisposition);
758
759 dprintf ("\t\t\t\tdwError %x ", dwError);
760 dprintf ("dwDisposition %x\n", dwDisposition);
761
762
763 if (dwError == ERROR_SUCCESS)
764 {
765 dprintf("RegQueryInfoKeyW: ");
766 cchClass=260;
767 dwError = RegQueryInfoKeyW(hKey
768 , szClass, &cchClass, NULL, &cSubKeys
769 , &cchMaxSubkey, &cchMaxClass, &cValues, &cchMaxValueName
770 , &cbMaxValueData, &cbSecurityDescriptor, &ftLastWriteTime);
771 dprintf ("\t\t\t\tdwError %x\n", dwError);
772 FileTimeToSystemTime(&ftLastWriteTime,&LastWriteTime);
773 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
774 ,LastWriteTime.wMonth
775 ,LastWriteTime.wDay
776 ,LastWriteTime.wYear
777 ,LastWriteTime.wHour
778 ,LastWriteTime.wMinute
779 ,LastWriteTime.wSecond
780 ,LastWriteTime.wMilliseconds
781 );
782 dprintf ("RegCloseKey: ");
783 dwError = RegCloseKey (hKey);
784 dprintf ("\t\t\t\t\tdwError %x\n", dwError);
785 }
786 dprintf ("\nTests done...\n");
787 }
788
789 void test5(void)
790 {
791 HKEY hKey;
792 OBJECT_ATTRIBUTES ObjectAttributes;
793 UNICODE_STRING KeyName;
794 NTSTATUS Status;
795
796 dprintf("NtOpenKey : \n");
797 dprintf(" \\Registry\\Machine\\Software\\reactos : ");
798 RtlRosInitUnicodeStringFromLiteral(&KeyName,L"\\Registry\\Machine\\Software\\reactos");
799 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
800 , NULL, NULL);
801 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
802 dprintf("\t\tStatus=%x\n",Status);
803 dprintf("NtFlushKey : \n");
804 Status = NtFlushKey(hKey);
805 dprintf("\t\tStatus=%x\n",Status);
806 dprintf("NtCloseKey : \n");
807 Status=NtClose(hKey);
808 dprintf("\t\tStatus=%x\n",Status);
809 }
810
811 /* registry link create test */
812 void test6(void)
813 {
814 HKEY hKey;
815 OBJECT_ATTRIBUTES ObjectAttributes;
816 UNICODE_STRING KeyName,ValueName;
817 NTSTATUS Status;
818 KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
819 ULONG Length,i;
820
821 dprintf("Create target key\n");
822 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Reactos\n");
823 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Reactos");
824 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
825 , NULL, NULL);
826 Status = NtCreateKey(&hKey, KEY_ALL_ACCESS , &ObjectAttributes
827 ,0,NULL, REG_OPTION_VOLATILE,NULL);
828 dprintf(" NtCreateKey() called (Status %lx)\n",Status);
829 if (!NT_SUCCESS(Status))
830 return;
831
832 dprintf("Create target value\n");
833 dprintf(" Value: TestValue = 'Test String'\n");
834 RtlRosInitUnicodeStringFromLiteral(&ValueName, L"TestValue");
835 Status=NtSetValueKey(hKey,&ValueName,0,REG_SZ,(PVOID)L"TestString",22);
836 dprintf(" NtSetValueKey() called (Status %lx)\n",Status);
837 if (!NT_SUCCESS(Status))
838 return;
839
840 dprintf("Close target key\n");
841 NtClose(hKey);
842
843
844 dprintf("Create link key\n");
845 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
846 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Test");
847 InitializeObjectAttributes(&ObjectAttributes,
848 &KeyName,
849 OBJ_CASE_INSENSITIVE | OBJ_OPENLINK,
850 NULL,
851 NULL);
852 Status = NtCreateKey(&hKey,
853 KEY_ALL_ACCESS | KEY_CREATE_LINK,
854 &ObjectAttributes,
855 0,
856 NULL,
857 REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK,
858 NULL);
859 dprintf(" NtCreateKey() called (Status %lx)\n",Status);
860 if (!NT_SUCCESS(Status))
861 return;
862
863 dprintf("Create link value\n");
864 dprintf(" Value: SymbolicLinkValue = '\\Registry\\Machine\\SOFTWARE\\Reactos'\n");
865 RtlRosInitUnicodeStringFromLiteral(&ValueName, L"SymbolicLinkValue");
866 Status=NtSetValueKey(hKey,&ValueName,0,REG_LINK,(PVOID)L"\\Registry\\Machine\\SOFTWARE\\Reactos",68);
867 dprintf(" NtSetValueKey() called (Status %lx)\n",Status);
868 if (!NT_SUCCESS(Status))
869 {
870 dprintf("Creating link value failed! Test failed!\n");
871 NtClose(hKey);
872 return;
873 }
874
875 dprintf("Close link key\n");
876 NtClose(hKey);
877
878 dprintf("Open link key\n");
879 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
880 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Test");
881 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_OPENIF
882 , NULL, NULL);
883 Status = NtCreateKey(&hKey, KEY_ALL_ACCESS , &ObjectAttributes
884 ,0,NULL, REG_OPTION_VOLATILE, NULL);
885 dprintf(" NtCreateKey() called (Status %lx)\n",Status);
886 if (!NT_SUCCESS(Status))
887 return;
888
889 dprintf("Query value\n");
890 dprintf(" Value: TestValue\n");
891 RtlRosInitUnicodeStringFromLiteral(&ValueName, L"TestValue");
892 Status=NtQueryValueKey(hKey,
893 &ValueName,
894 KeyValueFullInformation,
895 &KeyValueInformation[0],
896 sizeof(KeyValueInformation),
897 &Length);
898 dprintf(" NtQueryValueKey() called (Status %lx)\n",Status);
899 if (Status == STATUS_SUCCESS)
900 {
901 dprintf(" Value: Type %d DataLength %d NameLength %d Name '",
902 KeyValueInformation[0].Type,
903 KeyValueInformation[0].DataLength,
904 KeyValueInformation[0].NameLength);
905 for (i=0; i < KeyValueInformation[0].NameLength / sizeof(WCHAR); i++)
906 dprintf("%C",KeyValueInformation[0].Name[i]);
907 dprintf("'\n");
908 if (KeyValueInformation[0].Type == REG_SZ)
909 dprintf(" Value '%S'\n",
910 KeyValueInformation[0].Name+1
911 +KeyValueInformation[0].NameLength/2);
912 }
913
914 dprintf("Close link key\n");
915 NtClose(hKey);
916
917 dprintf("Test successful!\n");
918 }
919
920 /* registry link delete test */
921 void test7(void)
922 {
923 HKEY hKey;
924 OBJECT_ATTRIBUTES ObjectAttributes;
925 UNICODE_STRING KeyName,ValueName;
926 NTSTATUS Status;
927
928 dprintf("Open link key\n");
929 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
930 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Test");
931 InitializeObjectAttributes(&ObjectAttributes,
932 &KeyName,
933 OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_OPENLINK,
934 NULL,
935 NULL);
936 Status = NtCreateKey(&hKey,
937 KEY_ALL_ACCESS,
938 &ObjectAttributes,
939 0,
940 NULL,
941 REG_OPTION_VOLATILE | REG_OPTION_OPEN_LINK,
942 NULL);
943 dprintf(" NtCreateKey() called (Status %lx)\n",Status);
944 if (!NT_SUCCESS(Status))
945 {
946 dprintf("Could not open the link key. Please run the link create test first!\n");
947 return;
948 }
949
950 dprintf("Delete link value\n");
951 RtlRosInitUnicodeStringFromLiteral(&ValueName, L"SymbolicLinkValue");
952 Status = NtDeleteValueKey(hKey,
953 &ValueName);
954 dprintf(" NtDeleteValueKey() called (Status %lx)\n",Status);
955
956 dprintf("Delete link key\n");
957 Status=NtDeleteKey(hKey);
958 dprintf(" NtDeleteKey() called (Status %lx)\n",Status);
959
960 dprintf("Close link key\n");
961 NtClose(hKey);
962 }
963
964
965 void test8(void)
966 {
967 OBJECT_ATTRIBUTES ObjectAttributes;
968 UNICODE_STRING KeyName;
969 NTSTATUS Status;
970 LONG dwError;
971 TOKEN_PRIVILEGES NewPrivileges;
972 HANDLE Token,hKey;
973 LUID Luid;
974 BOOLEAN bRes;
975 Status=NtOpenProcessToken(GetCurrentProcess()
976 ,TOKEN_ADJUST_PRIVILEGES,&Token);
977 // ,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&Token);
978 dprintf("\t\t\t\tStatus =%x\n",Status);
979 // bRes=LookupPrivilegeValueA(NULL,SE_RESTORE_NAME,&Luid);
980 // dprintf("\t\t\t\tbRes =%x\n",bRes);
981 NewPrivileges.PrivilegeCount = 1;
982 NewPrivileges.Privileges[0].Luid = Luid;
983 // NewPrivileges.Privileges[0].Luid.u.LowPart=18;
984 // NewPrivileges.Privileges[0].Luid.u.HighPart=0;
985 NewPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
986
987 // Status = NtAdjustPrivilegesToken(
988 bRes = AdjustTokenPrivileges(
989 Token,
990 FALSE,
991 &NewPrivileges,
992 0,
993 NULL,
994 NULL
995 );
996 dprintf("\t\t\t\tbRes =%x\n",bRes);
997
998 // Status=NtClose(Token);
999 // dprintf("\t\t\t\tStatus =%x\n",Status);
1000
1001
1002 RtlRosInitUnicodeStringFromLiteral(&KeyName,L"test5");
1003 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
1004 , NULL, NULL);
1005 Status = NtLoadKey(HKEY_LOCAL_MACHINE,&ObjectAttributes);
1006 dprintf("\t\t\t\tStatus =%x\n",Status);
1007 dwError=RegLoadKey(HKEY_LOCAL_MACHINE,"def"
1008 ,"test5");
1009 dprintf("\t\t\t\tdwError =%x\n",dwError);
1010
1011 dprintf("NtOpenKey \\Registry\\Machine : ");
1012 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine");
1013 InitializeObjectAttributes(&ObjectAttributes,
1014 &KeyName,
1015 OBJ_CASE_INSENSITIVE,
1016 NULL,
1017 NULL);
1018 Status=NtOpenKey( &hKey, MAXIMUM_ALLOWED, &ObjectAttributes);
1019 dprintf("\t\t\tStatus =%x\n",Status);
1020 RtlRosInitUnicodeStringFromLiteral(&KeyName,L"test5");
1021 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
1022 , NULL, NULL);
1023 Status = NtLoadKey(hKey,&ObjectAttributes);
1024 dprintf("\t\t\t\tStatus =%x\n",Status);
1025 }
1026
1027 void test9(void)
1028 {
1029 HKEY hKey = NULL, hKey1;
1030 OBJECT_ATTRIBUTES ObjectAttributes;
1031 NTSTATUS Status;
1032 UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry");
1033 ULONG Index,Length,i;
1034 KEY_BASIC_INFORMATION KeyInformation[5];
1035 KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
1036
1037 dprintf("NtOpenKey \\Registry : ");
1038 InitializeObjectAttributes(&ObjectAttributes,
1039 &KeyName,
1040 OBJ_CASE_INSENSITIVE,
1041 NULL,
1042 NULL);
1043 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
1044 dprintf("\t\t\t\tStatus =%x\n",Status);
1045 if (Status == 0) {
1046 dprintf("NtQueryKey : ");
1047 Status = NtQueryKey(hKey1, KeyBasicInformation, &KeyInformation[0], sizeof(KeyInformation), &Length);
1048 dprintf("\t\t\t\t\tStatus =%x\n",Status);
1049 if (Status == STATUS_SUCCESS) {
1050 dprintf("\tKey Name = ");
1051 for (i=0;i<KeyInformation[0].NameLength/2;i++)
1052 dprintf("%C",KeyInformation[0].Name[i]);
1053 dprintf("\n");
1054 }
1055
1056 dprintf("NtEnumerateKey : \n");
1057 Index = 0;
1058 while (Status == STATUS_SUCCESS) {
1059 Status = NtEnumerateKey(hKey1,Index++,KeyBasicInformation,&KeyInformation[0], sizeof(KeyInformation),&Length);
1060 if (Status == STATUS_SUCCESS) {
1061 dprintf("\tSubKey Name = ");
1062 for (i = 0; i < KeyInformation[0].NameLength / 2; i++)
1063 dprintf("%C",KeyInformation[0].Name[i]);
1064 dprintf("\n");
1065 }
1066 }
1067 dprintf("NtClose : ");
1068 Status = NtClose( hKey1 );
1069 dprintf("\t\t\t\t\tStatus =%x\n",Status);
1070 }
1071 NtClose(hKey); // RobD - hKey unused so-far, should this have been hKey1 ???
1072
1073 dprintf("NtOpenKey \\Registry\\Machine : ");
1074 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine");
1075 InitializeObjectAttributes(&ObjectAttributes,
1076 &KeyName,
1077 OBJ_CASE_INSENSITIVE,
1078 NULL,
1079 NULL);
1080 Status = NtOpenKey(&hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
1081 dprintf("\t\t\tStatus =%x\n",Status);
1082
1083 //Status of c0000001 opening \Registry\Machine\System\CurrentControlSet\Services\Tcpip\Linkage
1084
1085 // dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
1086 // RtlRosInitUnicodeStringFromLiteral(&KeyName, L"System\\CurrentControlSet\\Services\\Tcpip");
1087 #if 1
1088 dprintf("NtOpenKey System\\ControlSet001\\Services\\Tcpip\\Parameters : ");
1089 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"System\\ControlSet001\\Services\\Tcpip\\Parameters");
1090 #else
1091 dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
1092 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"System\\CurrentControlSet\\Services\\Tcpip");
1093 #endif
1094 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, hKey1 , NULL);
1095 Status = NtOpenKey(&hKey, KEY_READ , &ObjectAttributes);
1096 dprintf("\t\t\tStatus =%x\n",Status);
1097 if (Status == 0) {
1098 dprintf("NtQueryValueKey : ");
1099 RtlRosInitUnicodeStringFromLiteral(&KeyName, L"NameServer");
1100 Status = NtQueryValueKey(hKey, &KeyName, KeyValueFullInformation, &KeyValueInformation[0], sizeof(KeyValueInformation), &Length);
1101 dprintf("\t\t\t\tStatus =%x\n",Status);
1102 if (Status == STATUS_SUCCESS) {
1103 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
1104 ,KeyValueInformation[0].DataOffset
1105 ,KeyValueInformation[0].DataLength
1106 ,KeyValueInformation[0].NameLength);
1107 for (i = 0; i < 10 && i < KeyValueInformation[0].NameLength / 2; i++)
1108 dprintf("%C", KeyValueInformation[0].Name[i]);
1109 dprintf("\n");
1110 dprintf("\t\tType = %d\n", KeyValueInformation[0].Type);
1111 if (KeyValueInformation[0].Type == REG_SZ)
1112 //dprintf("\t\tValue = %S\n", KeyValueInformation[0].Name + 1 + KeyValueInformation[0].NameLength / 2);
1113 dprintf("\t\tValue = %S\n", KeyValueInformation[0].Name + KeyValueInformation[0].NameLength / 2);
1114 }
1115 dprintf("NtEnumerateValueKey : \n");
1116 Index = 0;
1117 while (Status == STATUS_SUCCESS) {
1118 Status = NtEnumerateValueKey(hKey, Index++, KeyValueFullInformation, &KeyValueInformation[0], sizeof(KeyValueInformation), &Length);
1119 if (Status == STATUS_SUCCESS) {
1120 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
1121 ,KeyValueInformation[0].DataOffset
1122 ,KeyValueInformation[0].DataLength
1123 ,KeyValueInformation[0].NameLength);
1124 for (i = 0; i < KeyValueInformation[0].NameLength / 2; i++)
1125 dprintf("%C", KeyValueInformation[0].Name[i]);
1126 dprintf(", Type = %d\n", KeyValueInformation[0].Type);
1127 if (KeyValueInformation[0].Type == REG_SZ)
1128 dprintf("\t\tValue = %S\n", ((char*)&KeyValueInformation[0]+KeyValueInformation[0].DataOffset));
1129 if (KeyValueInformation[0].Type == REG_DWORD)
1130 dprintf("\t\tValue = %X\n", *((DWORD*)((char*)&KeyValueInformation[0]+KeyValueInformation[0].DataOffset)));
1131 }
1132 }
1133 dprintf("NtClose : ");
1134 Status = NtClose(hKey);
1135 dprintf("\t\t\t\t\tStatus =%x\n", Status);
1136 }
1137 NtClose(hKey1);
1138 }
1139
1140
1141 int main(int argc, char* argv[])
1142 {
1143 char Buffer[10];
1144 DWORD Result;
1145
1146 AllocConsole();
1147 InputHandle = GetStdHandle(STD_INPUT_HANDLE);
1148 OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
1149 while(1)
1150 {
1151 dprintf("choose test :\n");
1152 dprintf(" 0 = Exit\n");
1153 dprintf(" 1 = Create key\n");
1154 dprintf(" 2 = Delete key\n");
1155 dprintf(" 3 = Enumerate key\n");
1156 dprintf(" 4 = Set value (REG_SZ)\n");
1157 dprintf(" 5 = Set value (REG_DWORD)\n");
1158 dprintf(" 6 = Delete value\n");
1159 dprintf(" 7 = Enumerate value\n");
1160 ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
1161 switch (Buffer[0])
1162 {
1163 case '0':
1164 return(0);
1165
1166 case '1':
1167 CreateKeyTest();
1168 break;
1169
1170 case '2':
1171 DeleteKeyTest();
1172 break;
1173
1174 case '3':
1175 EnumerateKeyTest();
1176 break;
1177
1178 case '4':
1179 SetValueTest1();
1180 break;
1181
1182 case '5':
1183 SetValueTest2();
1184 break;
1185
1186 case '6':
1187 DeleteValueTest();
1188 break;
1189
1190 case '7':
1191 EnumerateValueTest();
1192 break;
1193 }
1194 }
1195 return(0);
1196 }