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