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