6 #include <rosrtl/string.h>
11 void dprintf(char* fmt
, ...)
17 vsprintf(buffer
,fmt
,args
);
18 WriteConsoleA(OutputHandle
, buffer
, strlen(buffer
), NULL
, NULL
);
22 void do_enumeratekey(PWSTR Name
)
25 KEY_BASIC_INFORMATION KeyInformation
[5];
27 OBJECT_ATTRIBUTES ObjectAttributes
;
29 UNICODE_STRING KeyName
;
31 RtlInitUnicodeString(&KeyName
, Name
);
32 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
34 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
35 dprintf("NtEnumerateKey : \n");
37 while(Status
== STATUS_SUCCESS
)
39 Status
=NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
40 ,&KeyInformation
[0], sizeof(KeyInformation
)
42 if(Status
== STATUS_SUCCESS
)
44 dprintf("\tSubKey Name = ");
45 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
46 dprintf("%C",KeyInformation
[0].Name
[i
]);
54 void CreateKeyTest(void)
57 OBJECT_ATTRIBUTES ObjectAttributes
;
58 UNICODE_STRING KeyName
;
61 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
62 RtlRosInitUnicodeStringFromLiteral(&KeyName
,
63 L
"\\Registry\\Machine\\Software\\testkey");
64 InitializeObjectAttributes(&ObjectAttributes
,
69 dprintf("NtCreateKey:\n");
70 Status
= NtCreateKey(&hKey
,
75 REG_OPTION_NON_VOLATILE
,
77 dprintf(" Status = %lx\n",Status
);
78 if (NT_SUCCESS(Status
))
85 void DeleteKeyTest(void)
87 OBJECT_ATTRIBUTES ObjectAttributes
;
88 UNICODE_STRING KeyName
;
92 dprintf("Delete key '\\Registry\\Machine\\Software\\testkey':\n");
93 RtlRosInitUnicodeStringFromLiteral(&KeyName
,
94 L
"\\Registry\\Machine\\Software\\testkey");
95 InitializeObjectAttributes(&ObjectAttributes
,
100 dprintf("NtOpenKey:\n");
101 Status
= NtOpenKey(&hKey
,
104 dprintf(" Status = %lx\n",Status
);
105 if (!NT_SUCCESS(Status
))
108 dprintf("NtDeleteKey:\n");
109 Status
= NtDeleteKey(hKey
);
110 dprintf(" Status = %lx\n",Status
);
115 void EnumerateKeyTest(void)
118 OBJECT_ATTRIBUTES ObjectAttributes
;
120 UNICODE_STRING KeyName
;
124 KEY_BASIC_INFORMATION KeyInformation
[5];
126 dprintf("Enumerate key '\\Registry\\Machine\\Software':\n");
127 RtlRosInitUnicodeStringFromLiteral(&KeyName
,
128 L
"\\Registry\\Machine\\Software");
129 InitializeObjectAttributes(&ObjectAttributes
,
131 OBJ_CASE_INSENSITIVE
,
134 dprintf("NtOpenKey:\n");
135 Status
= NtOpenKey(&hKey
,
138 dprintf(" Status = %lx\n", Status
);
139 if (!NT_SUCCESS(Status
))
142 dprintf("NtQueryKey:\n");
143 Status
= NtQueryKey(hKey
,
146 sizeof(KeyInformation
),
148 dprintf(" Status = %lx\n", Status
);
149 if (NT_SUCCESS(Status
))
151 dprintf("\tKey Name = ");
152 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
153 dprintf("%C", KeyInformation
[0].Name
[i
]);
157 dprintf("NtEnumerateKey:\n");
159 while(NT_SUCCESS(Status
))
161 Status
= NtEnumerateKey(hKey
,
165 sizeof(KeyInformation
),
167 if (NT_SUCCESS(Status
))
169 dprintf("\tSubKey Name = ");
170 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
171 dprintf("%C", KeyInformation
[0].Name
[i
]);
177 dprintf("NtClose:\n");
178 Status
= NtClose(hKey
);
179 dprintf(" Status = %lx\n", Status
);
183 void SetValueTest1(void)
186 OBJECT_ATTRIBUTES ObjectAttributes
;
187 UNICODE_STRING KeyName
;
188 UNICODE_STRING ValueName
;
191 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
192 RtlRosInitUnicodeStringFromLiteral(&KeyName
,
193 L
"\\Registry\\Machine\\Software\\testkey");
194 InitializeObjectAttributes(&ObjectAttributes
,
196 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
199 dprintf("NtCreateKey:\n");
200 Status
= NtCreateKey(&hKey
,
205 REG_OPTION_NON_VOLATILE
,
207 dprintf(" Status = %lx\n",Status
);
208 if (!NT_SUCCESS(Status
))
211 RtlRosInitUnicodeStringFromLiteral(&ValueName
,
213 dprintf("NtSetValueKey:\n");
214 Status
= NtSetValueKey(hKey
,
218 (PVOID
)L
"TestString",
220 dprintf(" Status = %lx\n",Status
);
226 void SetValueTest2(void)
229 OBJECT_ATTRIBUTES ObjectAttributes
;
230 UNICODE_STRING KeyName
;
231 UNICODE_STRING ValueName
;
234 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
235 RtlRosInitUnicodeStringFromLiteral(&KeyName
,
236 L
"\\Registry\\Machine\\Software\\testkey");
237 InitializeObjectAttributes(&ObjectAttributes
,
239 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
242 dprintf("NtCreateKey:\n");
243 Status
= NtCreateKey(&hKey
,
248 REG_OPTION_NON_VOLATILE
,
250 dprintf(" Status = %lx\n",Status
);
251 if (!NT_SUCCESS(Status
))
254 RtlRosInitUnicodeStringFromLiteral(&ValueName
,
256 dprintf("NtSetValueKey:\n");
257 Status
= NtSetValueKey(hKey
,
263 dprintf(" Status = %lx\n",Status
);
269 void DeleteValueTest(void)
271 OBJECT_ATTRIBUTES ObjectAttributes
;
272 UNICODE_STRING KeyName
;
273 UNICODE_STRING ValueName
;
277 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
278 RtlRosInitUnicodeStringFromLiteral(&KeyName
,
279 L
"\\Registry\\Machine\\Software\\testkey");
280 InitializeObjectAttributes(&ObjectAttributes
,
282 OBJ_CASE_INSENSITIVE
,
285 Status
=NtOpenKey(&KeyHandle
,
288 dprintf(" Status = %lx\n", Status
);
289 if (!NT_SUCCESS(Status
))
292 dprintf("Delete value:\n");
293 RtlRosInitUnicodeStringFromLiteral(&ValueName
,
295 Status
= NtDeleteValueKey(KeyHandle
,
297 dprintf(" Status = %lx\n", Status
);
299 dprintf("Close key:\n");
300 Status
= NtClose(KeyHandle
);
301 dprintf(" Status = %lx\n", Status
);
305 void EnumerateValueTest(void)
307 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
308 OBJECT_ATTRIBUTES ObjectAttributes
;
309 UNICODE_STRING KeyName
;
310 ULONG Index
,Length
,i
;
314 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
315 RtlRosInitUnicodeStringFromLiteral(&KeyName
,
316 L
"\\Registry\\Machine\\Software\\testkey");
317 InitializeObjectAttributes(&ObjectAttributes
,
319 OBJ_CASE_INSENSITIVE
,
322 Status
=NtOpenKey(&hKey
,
325 dprintf(" Status = %lx\n", Status
);
326 if (!NT_SUCCESS(Status
))
329 dprintf("Enumerate values:\n");
331 while (Status
== STATUS_SUCCESS
)
333 Status
= NtEnumerateValueKey(hKey
,
335 KeyValueFullInformation
,
336 &KeyValueInformation
[0],
337 sizeof(KeyValueInformation
),
339 if (Status
== STATUS_SUCCESS
)
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
);
349 if (KeyValueInformation
[0].Type
== REG_SZ
)
350 dprintf(" Value = %S\n",
351 ((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
));
353 if (KeyValueInformation
[0].Type
== REG_DWORD
)
354 dprintf(" Value = %X\n",
355 *((DWORD
*)((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
)));
359 dprintf("NtClose:\n");
360 Status
= NtClose(hKey
);
361 dprintf(" Status = %lx\n", Status
);
369 HKEY hKey
= NULL
, hKey1
;
370 OBJECT_ATTRIBUTES ObjectAttributes
;
373 UNICODE_STRING KeyName
= ROS_STRING_INITIALIZER(L
"\\Registry");
375 UNICODE_STRING KeyName
= ROS_STRING_INITIALIZER(L
"\\Registry\\Machine\\Software");
376 ULONG Index
,Length
,i
;
377 KEY_BASIC_INFORMATION KeyInformation
[5];
380 dprintf("NtOpenKey \\Registry : ");
382 dprintf("NtOpenKey \\Registry\\Machine\\Software : ");
383 InitializeObjectAttributes(&ObjectAttributes
,
385 OBJ_CASE_INSENSITIVE
,
388 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
389 dprintf("\t\t\t\tStatus =%x\n",Status
);
392 dprintf("NtQueryKey : ");
393 Status
=NtQueryKey(hKey1
,KeyBasicInformation
394 ,&KeyInformation
[0], sizeof(KeyInformation
)
396 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
397 if (Status
== STATUS_SUCCESS
)
399 dprintf("\tKey Name = ");
400 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
401 dprintf("%C",KeyInformation
[0].Name
[i
]);
404 dprintf("NtEnumerateKey : \n");
406 while(Status
== STATUS_SUCCESS
)
408 Status
=NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
409 ,&KeyInformation
[0], sizeof(KeyInformation
)
411 if(Status
== STATUS_SUCCESS
)
413 dprintf("\tSubKey Name = ");
414 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
415 dprintf("%C",KeyInformation
[0].Name
[i
]);
419 dprintf("NtClose : ");
420 Status
= NtClose( hKey1
);
421 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
426 dprintf("NtOpenKey \\Registry\\Machine : ");
427 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine");
428 InitializeObjectAttributes(&ObjectAttributes
,
430 OBJ_CASE_INSENSITIVE
,
433 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
434 dprintf("\t\t\tStatus =%x\n",Status
);
436 dprintf("NtOpenKey System\\Setup : ");
437 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"System\\Setup");
438 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
440 Status
= NtOpenKey ( &hKey
, KEY_READ
, &ObjectAttributes
);
441 dprintf("\t\t\tStatus =%x\n",Status
);
444 dprintf("NtQueryValueKey : ");
445 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"CmdLine");
446 Status
=NtQueryValueKey(hKey
,&KeyName
,KeyValueFullInformation
447 ,&KeyValueInformation
[0], sizeof(KeyValueInformation
)
449 dprintf("\t\t\t\tStatus =%x\n",Status
);
450 if (Status
== STATUS_SUCCESS
)
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
]);
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
));
464 dprintf("NtEnumerateValueKey : \n");
466 while(Status
== STATUS_SUCCESS
)
468 Status
=NtEnumerateValueKey(hKey
,Index
++,KeyValueFullInformation
469 ,&KeyValueInformation
[0], sizeof(KeyValueInformation
)
471 if(Status
== STATUS_SUCCESS
)
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
));
485 dprintf("NtClose : ");
486 Status
= NtClose( hKey
);
487 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
497 OBJECT_ATTRIBUTES ObjectAttributes
;
498 UNICODE_STRING KeyName
;
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
507 Status
= NtCreateKey ( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
508 ,0,NULL
,REG_OPTION_NON_VOLATILE
,NULL
);
509 dprintf("\t\tStatus=%x\n",Status
);
512 do_enumeratekey(L
"\\Registry\\Machine\\Software");
513 dprintf("NtOpenKey: ");
514 Status
=NtOpenKey( &hKey
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
515 dprintf("\t\tStatus=%x\n",Status
);
517 dprintf(" ...\\test3 :");
518 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos\\test3");
519 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
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
);
528 dprintf(" ...\\testNonVolatile :");
529 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"TestNonVolatile");
530 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
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
);
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
);
545 dprintf("NtOpenKey \\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile : ");
546 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile");
547 InitializeObjectAttributes(&ObjectAttributes
,
549 OBJ_CASE_INSENSITIVE
,
552 Status
=NtOpenKey( &hKey
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
553 dprintf("\t\t\t\tStatus =%x\n",Status
);
556 dprintf("NtEnumerateValueKey : \n");
558 while(Status
== STATUS_SUCCESS
)
560 Status
=NtEnumerateValueKey(hKey
,Index
++,KeyValueFullInformation
561 ,&KeyValueInformation
[0], sizeof(KeyValueInformation
)
563 if(Status
== STATUS_SUCCESS
)
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
));
581 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
582 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;
583 if (Buffer
[0] != 'y' && Buffer
[0] != 'Y') return;
585 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonvolatile");
586 InitializeObjectAttributes(&ObjectAttributes
,
588 OBJ_CASE_INSENSITIVE
,
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
,
600 OBJ_CASE_INSENSITIVE
,
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
);
611 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
612 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos");
613 InitializeObjectAttributes(&ObjectAttributes
,
615 OBJ_CASE_INSENSITIVE
,
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
);
629 HKEY hKey
= NULL
,hKey1
;
632 DWORD RegDataType
, RegDataSize
;
633 BOOL GlobalFifoEnable
;
635 DWORD RegDisposition
;
642 DWORD cchMaxValueName
;
643 DWORD cbMaxValueData
;
644 DWORD cbSecurityDescriptor
;
645 FILETIME ftLastWriteTime
;
646 SYSTEMTIME LastWriteTime
;
648 dprintf ("RegOpenKeyExW HKLM\\System\\Setup: ");
649 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
654 dprintf("\t\tdwError =%x\n",dwError
);
655 if (dwError
== ERROR_SUCCESS
)
657 dprintf("RegQueryInfoKeyW: ");
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
670 ,LastWriteTime
.wMinute
671 ,LastWriteTime
.wSecond
672 ,LastWriteTime
.wMilliseconds
677 dprintf ("RegOpenKeyExW: ");
678 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
679 L
"System\\ControlSet001\\Services\\Serial",
683 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
684 RegDataSize
= sizeof(GlobalFifoEnable
);
685 if (dwError
== ERROR_SUCCESS
)
687 dprintf ("RegQueryValueExW: ");
688 dwError
= RegQueryValueExW(hKey
,
692 (PBYTE
)&GlobalFifoEnable
,
694 dprintf("\t\t\t\tdwError =%x\n",dwError
);
697 dprintf("\tValue:DT=%d, DS=%d, Value=%d\n"
703 dprintf ("RegCreateKeyExW: ");
704 dwError
= RegCreateKeyExW(hKey
,
705 L
"Parameters\\Serial001",
714 dprintf ("\t\t\t\tdwError %x\n", dwError
);
716 dprintf ("RegCreateKeyExW: ");
717 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
718 L
"Software\\test4reactos\\test",
721 REG_OPTION_NON_VOLATILE
,
727 dprintf ("\t\t\t\tdwError %x ", dwError
);
728 dprintf ("dwDisposition %x\n", dwDisposition
);
729 if (dwError
== ERROR_SUCCESS
)
731 dprintf ("RegSetValueExW: ");
732 dwError
= RegSetValueExW (hKey
,
736 (BYTE
*)L
"TestString",
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
);
748 dprintf ("RegCreateKeyExW: ");
749 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
759 dprintf ("\t\t\t\tdwError %x ", dwError
);
760 dprintf ("dwDisposition %x\n", dwDisposition
);
763 if (dwError
== ERROR_SUCCESS
)
765 dprintf("RegQueryInfoKeyW: ");
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
778 ,LastWriteTime
.wMinute
779 ,LastWriteTime
.wSecond
780 ,LastWriteTime
.wMilliseconds
782 dprintf ("RegCloseKey: ");
783 dwError
= RegCloseKey (hKey
);
784 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
786 dprintf ("\nTests done...\n");
792 OBJECT_ATTRIBUTES ObjectAttributes
;
793 UNICODE_STRING KeyName
;
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
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
);
811 /* registry link create test */
815 OBJECT_ATTRIBUTES ObjectAttributes
;
816 UNICODE_STRING KeyName
,ValueName
;
818 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
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
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
))
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
))
840 dprintf("Close target key\n");
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
,
849 OBJ_CASE_INSENSITIVE
| OBJ_OPENLINK
,
852 Status
= NtCreateKey(&hKey
,
853 KEY_ALL_ACCESS
| KEY_CREATE_LINK
,
857 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
859 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
860 if (!NT_SUCCESS(Status
))
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
))
870 dprintf("Creating link value failed! Test failed!\n");
875 dprintf("Close link key\n");
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
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
))
889 dprintf("Query value\n");
890 dprintf(" Value: TestValue\n");
891 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"TestValue");
892 Status
=NtQueryValueKey(hKey
,
894 KeyValueFullInformation
,
895 &KeyValueInformation
[0],
896 sizeof(KeyValueInformation
),
898 dprintf(" NtQueryValueKey() called (Status %lx)\n",Status
);
899 if (Status
== STATUS_SUCCESS
)
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
]);
908 if (KeyValueInformation
[0].Type
== REG_SZ
)
909 dprintf(" Value '%S'\n",
910 KeyValueInformation
[0].Name
+1
911 +KeyValueInformation
[0].NameLength
/2);
914 dprintf("Close link key\n");
917 dprintf("Test successful!\n");
920 /* registry link delete test */
924 OBJECT_ATTRIBUTES ObjectAttributes
;
925 UNICODE_STRING KeyName
,ValueName
;
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
,
933 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
| OBJ_OPENLINK
,
936 Status
= NtCreateKey(&hKey
,
941 REG_OPTION_VOLATILE
| REG_OPTION_OPEN_LINK
,
943 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
944 if (!NT_SUCCESS(Status
))
946 dprintf("Could not open the link key. Please run the link create test first!\n");
950 dprintf("Delete link value\n");
951 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"SymbolicLinkValue");
952 Status
= NtDeleteValueKey(hKey
,
954 dprintf(" NtDeleteValueKey() called (Status %lx)\n",Status
);
956 dprintf("Delete link key\n");
957 Status
=NtDeleteKey(hKey
);
958 dprintf(" NtDeleteKey() called (Status %lx)\n",Status
);
960 dprintf("Close link key\n");
967 OBJECT_ATTRIBUTES ObjectAttributes
;
968 UNICODE_STRING KeyName
;
971 TOKEN_PRIVILEGES NewPrivileges
;
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
;
987 // Status = NtAdjustPrivilegesToken(
988 bRes
= AdjustTokenPrivileges(
996 dprintf("\t\t\t\tbRes =%x\n",bRes
);
998 // Status=NtClose(Token);
999 // dprintf("\t\t\t\tStatus =%x\n",Status);
1002 RtlRosInitUnicodeStringFromLiteral(&KeyName
,L
"test5");
1003 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
1005 Status
= NtLoadKey(HKEY_LOCAL_MACHINE
,&ObjectAttributes
);
1006 dprintf("\t\t\t\tStatus =%x\n",Status
);
1007 dwError
=RegLoadKey(HKEY_LOCAL_MACHINE
,"def"
1009 dprintf("\t\t\t\tdwError =%x\n",dwError
);
1011 dprintf("NtOpenKey \\Registry\\Machine : ");
1012 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine");
1013 InitializeObjectAttributes(&ObjectAttributes
,
1015 OBJ_CASE_INSENSITIVE
,
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
1023 Status
= NtLoadKey(hKey
,&ObjectAttributes
);
1024 dprintf("\t\t\t\tStatus =%x\n",Status
);
1029 HKEY hKey
= NULL
, hKey1
;
1030 OBJECT_ATTRIBUTES ObjectAttributes
;
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];
1037 dprintf("NtOpenKey \\Registry : ");
1038 InitializeObjectAttributes(&ObjectAttributes
,
1040 OBJ_CASE_INSENSITIVE
,
1043 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
1044 dprintf("\t\t\t\tStatus =%x\n",Status
);
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
]);
1056 dprintf("NtEnumerateKey : \n");
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
]);
1067 dprintf("NtClose : ");
1068 Status
= NtClose( hKey1
);
1069 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
1071 NtClose(hKey
); // RobD - hKey unused so-far, should this have been hKey1 ???
1073 dprintf("NtOpenKey \\Registry\\Machine : ");
1074 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine");
1075 InitializeObjectAttributes(&ObjectAttributes
,
1077 OBJ_CASE_INSENSITIVE
,
1080 Status
= NtOpenKey(&hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
1081 dprintf("\t\t\tStatus =%x\n",Status
);
1083 //Status of c0000001 opening \Registry\Machine\System\CurrentControlSet\Services\Tcpip\Linkage
1085 // dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
1086 // RtlRosInitUnicodeStringFromLiteral(&KeyName, L"System\\CurrentControlSet\\Services\\Tcpip");
1088 dprintf("NtOpenKey System\\ControlSet001\\Services\\Tcpip\\Parameters : ");
1089 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"System\\ControlSet001\\Services\\Tcpip\\Parameters");
1091 dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
1092 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"System\\CurrentControlSet\\Services\\Tcpip");
1094 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
, hKey1
, NULL
);
1095 Status
= NtOpenKey(&hKey
, KEY_READ
, &ObjectAttributes
);
1096 dprintf("\t\t\tStatus =%x\n",Status
);
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
]);
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);
1115 dprintf("NtEnumerateValueKey : \n");
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
)));
1133 dprintf("NtClose : ");
1134 Status
= NtClose(hKey
);
1135 dprintf("\t\t\t\t\tStatus =%x\n", Status
);
1141 int main(int argc
, char* argv
[])
1147 InputHandle
= GetStdHandle(STD_INPUT_HANDLE
);
1148 OutputHandle
= GetStdHandle(STD_OUTPUT_HANDLE
);
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
) ;
1191 EnumerateValueTest();