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