bugs corrected
[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;
58 ULONG Index,Length,i;
59 KEY_BASIC_INFORMATION KeyInformation[5];
60 KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
61
62 AllocConsole();
63 InputHandle = GetStdHandle(STD_INPUT_HANDLE);
64 OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
65
66 dprintf("NtOpenKey \\Registry : ");
67 RtlInitUnicodeString(&KeyName, L"\\Registry");
68 InitializeObjectAttributes(&ObjectAttributes,
69 &KeyName,
70 OBJ_CASE_INSENSITIVE,
71 NULL,
72 NULL);
73 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
74 dprintf("\t\t\t\tStatus =%x\n",Status);
75 if(Status==0)
76 {
77 dprintf("NtQueryKey : ");
78 Status=NtQueryKey(hKey1,KeyBasicInformation
79 ,&KeyInformation[0], sizeof(KeyInformation)
80 ,&Length);
81 dprintf("\t\t\t\t\tStatus =%x\n",Status);
82 if (Status == STATUS_SUCCESS)
83 {
84 dprintf("\tKey Name = ");
85 for (i=0;i<KeyInformation[0].NameLength/2;i++)
86 dprintf("%C",KeyInformation[0].Name[i]);
87 dprintf("\n");
88 }
89 dprintf("NtEnumerateKey : \n");
90 Index=0;
91 while(Status == STATUS_SUCCESS)
92 {
93 Status=NtEnumerateKey(hKey1,Index++,KeyBasicInformation
94 ,&KeyInformation[0], sizeof(KeyInformation)
95 ,&Length);
96 if(Status== STATUS_SUCCESS)
97 {
98 dprintf("\tSubKey Name = ");
99 for (i=0;i<KeyInformation[0].NameLength/2;i++)
100 dprintf("%C",KeyInformation[0].Name[i]);
101 dprintf("\n");
102 }
103 }
104 dprintf("NtClose : ");
105 Status = NtClose( hKey1 );
106 dprintf("\t\t\t\t\tStatus =%x\n",Status);
107 }
108 NtClose(hKey);
109
110 dprintf("NtOpenKey \\Registry\\Machine : ");
111 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine");
112 InitializeObjectAttributes(&ObjectAttributes,
113 &KeyName,
114 OBJ_CASE_INSENSITIVE,
115 NULL,
116 NULL);
117 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
118 dprintf("\t\t\tStatus =%x\n",Status);
119
120 dprintf("NtOpenKey System\\Setup : ");
121 RtlInitUnicodeString(&KeyName, L"System\\Setup");
122 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
123 , hKey1 , NULL);
124 Status = NtOpenKey ( &hKey, KEY_READ , &ObjectAttributes);
125 dprintf("\t\t\tStatus =%x\n",Status);
126 if(Status==0)
127 {
128 dprintf("NtQueryValueKey : ");
129 RtlInitUnicodeString(&KeyName, L"CmdLine");
130 Status=NtQueryValueKey(hKey,&KeyName,KeyValueFullInformation
131 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
132 ,&Length);
133 dprintf("\t\t\t\tStatus =%x\n",Status);
134 if (Status == STATUS_SUCCESS)
135 {
136 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
137 ,KeyValueInformation[0].DataOffset
138 ,KeyValueInformation[0].DataLength
139 ,KeyValueInformation[0].NameLength);
140 for (i=0;i<10 && i<KeyValueInformation[0].NameLength/2;i++)
141 dprintf("%C",KeyValueInformation[0].Name[i]);
142 dprintf("\n");
143 dprintf("\t\tType = %d\n",KeyValueInformation[0].Type);
144 if (KeyValueInformation[0].Type == REG_SZ)
145 dprintf("\t\tValue = %S\n",KeyValueInformation[0].Name+1
146 +KeyValueInformation[0].NameLength/2);
147 }
148 dprintf("NtEnumerateValueKey : \n");
149 Index=0;
150 while(Status == STATUS_SUCCESS)
151 {
152 Status=NtEnumerateValueKey(hKey,Index++,KeyValueFullInformation
153 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
154 ,&Length);
155 if(Status== STATUS_SUCCESS)
156 {
157 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
158 ,KeyValueInformation[0].DataOffset
159 ,KeyValueInformation[0].DataLength
160 ,KeyValueInformation[0].NameLength);
161 for (i=0;i<KeyValueInformation[0].NameLength/2;i++)
162 dprintf("%C",KeyValueInformation[0].Name[i]);
163 dprintf(", Type = %d\n",KeyValueInformation[0].Type);
164 if (KeyValueInformation[0].Type == REG_SZ)
165 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation[0]
166 +KeyValueInformation[0].DataOffset));
167 }
168 }
169 dprintf("NtClose : ");
170 Status = NtClose( hKey );
171 dprintf("\t\t\t\t\tStatus =%x\n",Status);
172 }
173 NtClose( hKey1 );
174 }
175
176 void test2(void)
177 {
178 HKEY hKey,hKey1;
179 OBJECT_ATTRIBUTES ObjectAttributes;
180 UNICODE_STRING KeyName,ValueName;
181 NTSTATUS Status;
182 KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
183 ULONG Index,Length,i;
184 char Buffer[10];
185 DWORD Result;
186 dprintf("NtCreateKey volatile: \n");
187 dprintf(" \\Registry\\Machine\\Software\\test2reactos: ");
188 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test2reactos");
189 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
190 , NULL, NULL);
191 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
192 ,0,NULL,REG_OPTION_VOLATILE,NULL);
193 dprintf("\t\tStatus=%x\n",Status);
194 NtClose(hKey);
195 do_enumeratekey(L"\\Registry\\Machine\\Software");
196 dprintf(" ...\\test2 :");
197 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test2reactos\\test2");
198 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
199 , NULL, NULL);
200 Status = NtCreateKey ( &hKey1, KEY_ALL_ACCESS , &ObjectAttributes
201 ,0,NULL,REG_OPTION_VOLATILE,NULL);
202 dprintf("\t\t\t\t\tStatus=%x\n",Status);
203 dprintf(" ...\\TestVolatile :");
204 RtlInitUnicodeString(&KeyName, L"TestVolatile");
205 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
206 , hKey1, NULL);
207 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
208 ,0,NULL,REG_OPTION_VOLATILE,NULL);
209 dprintf("\t\t\t\tStatus=%x\n",Status);
210 NtClose(hKey1);
211 RtlInitUnicodeString(&ValueName, L"TestREG_SZ");
212 dprintf("NtSetValueKey reg_sz: ");
213 Status=NtSetValueKey(hKey,&ValueName,0,REG_SZ,(PVOID)L"Test Reg_sz",24);
214 dprintf("\t\t\t\tStatus=%x\n",Status);
215 RtlInitUnicodeString(&ValueName, L"TestDWORD");
216 dprintf("NtSetValueKey reg_dword: ");
217 Status=NtSetValueKey(hKey,&ValueName,0,REG_DWORD,(PVOID)"reac",4);
218 dprintf("\t\t\tStatus=%x\n",Status);
219 NtClose(hKey);
220 dprintf("NtOpenKey \\Registry\\Machine\\Software\\test2reactos\\test2\\TestVolatile : ");
221 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test2reactos\\test2\\TestVolatile");
222 InitializeObjectAttributes(&ObjectAttributes,
223 &KeyName,
224 OBJ_CASE_INSENSITIVE,
225 NULL,
226 NULL);
227 Status=NtOpenKey( &hKey, MAXIMUM_ALLOWED, &ObjectAttributes);
228 dprintf("\t\t\t\tStatus =%x\n",Status);
229 if(Status==0)
230 {
231 dprintf("NtEnumerateValueKey : \n");
232 Index=0;
233 while(Status == STATUS_SUCCESS)
234 {
235 Status=NtEnumerateValueKey(hKey,Index++,KeyValueFullInformation
236 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
237 ,&Length);
238 if(Status== STATUS_SUCCESS)
239 {
240 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
241 ,KeyValueInformation[0].DataOffset
242 ,KeyValueInformation[0].DataLength
243 ,KeyValueInformation[0].NameLength);
244 for (i=0;i<KeyValueInformation[0].NameLength/2;i++)
245 dprintf("%C",KeyValueInformation[0].Name[i]);
246 dprintf(", Type = %d\n",KeyValueInformation[0].Type);
247 if (KeyValueInformation[0].Type == REG_SZ)
248 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation[0]
249 +KeyValueInformation[0].DataOffset));
250 }
251 }
252 }
253 NtClose(hKey);
254 dprintf("delete \\Registry\\Machine\\software\\test2reactos ?");
255 ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
256 if (Buffer[0] != 'y' && Buffer[0] != 'Y') return;
257 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test2reactos\\test2\\TestVolatile");
258 InitializeObjectAttributes(&ObjectAttributes,
259 &KeyName,
260 OBJ_CASE_INSENSITIVE,
261 NULL,
262 NULL);
263 dprintf("NtOpenKey : ");
264 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
265 dprintf("\t\t\t\tStatus =%x\n",Status);
266 dprintf("NtDeleteKey : ");
267 Status=NtDeleteKey(hKey);
268 dprintf("\t\t\t\tStatus =%x\n",Status);
269 NtClose(hKey);
270 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test2reactos\\test2");
271 InitializeObjectAttributes(&ObjectAttributes,
272 &KeyName,
273 OBJ_CASE_INSENSITIVE,
274 NULL,
275 NULL);
276 dprintf("NtOpenKey : ");
277 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
278 dprintf("\t\t\t\tStatus =%x\n",Status);
279 dprintf("NtDeleteKey : ");
280 Status=NtDeleteKey(hKey);
281 dprintf("\t\t\t\tStatus =%x\n",Status);
282 NtClose(hKey);
283 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test2reactos");
284 InitializeObjectAttributes(&ObjectAttributes,
285 &KeyName,
286 OBJ_CASE_INSENSITIVE,
287 NULL,
288 NULL);
289 dprintf("NtOpenKey : ");
290 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
291 dprintf("\t\t\t\tStatus =%x\n",Status);
292 dprintf("NtDeleteKey : ");
293 Status=NtDeleteKey(hKey);
294 dprintf("\t\t\t\tStatus =%x\n",Status);
295 NtClose(hKey);
296 }
297
298 void test3(void)
299 {
300 HKEY hKey,hKey1;
301 OBJECT_ATTRIBUTES ObjectAttributes;
302 UNICODE_STRING KeyName,ValueName;
303 NTSTATUS Status;
304 KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
305 ULONG Index,Length,i;
306 char Buffer[10];
307 DWORD Result;
308 dprintf("NtCreateKey non volatile: \n");
309 dprintf(" \\Registry\\Machine\\Software\\test3reactos: ");
310 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
311 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
312 , NULL, NULL);
313 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
314 ,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
315 dprintf("\t\tStatus=%x\n",Status);
316 NtClose(hKey);
317 do_enumeratekey(L"\\Registry\\Machine\\Software");
318 dprintf("NtOpenKey: ");
319 Status=NtOpenKey( &hKey, MAXIMUM_ALLOWED, &ObjectAttributes);
320 dprintf("\t\tStatus=%x\n",Status);
321 NtClose(hKey);
322 dprintf(" ...\\test3 :");
323 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3");
324 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
325 , NULL, NULL);
326 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
327 ,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
328 dprintf("\t\t\t\t\tStatus=%x\n",Status);
329 dprintf("NtOpenKey: ");
330 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
331 dprintf("\t\tStatus=%x\n",Status);
332 NtClose(hKey);
333 dprintf(" ...\\testNonVolatile :");
334 RtlInitUnicodeString(&KeyName, L"TestNonVolatile");
335 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
336 , hKey1, NULL);
337 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
338 ,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
339 dprintf("\t\t\t\tStatus=%x\n",Status);
340 NtClose(hKey1);
341 RtlInitUnicodeString(&ValueName, L"TestREG_SZ");
342 dprintf("NtSetValueKey reg_sz: ");
343 Status=NtSetValueKey(hKey,&ValueName,0,REG_SZ,(PVOID)L"Test Reg_sz",24);
344 dprintf("\t\t\t\tStatus=%x\n",Status);
345 RtlInitUnicodeString(&ValueName, L"TestDWORD");
346 dprintf("NtSetValueKey reg_dword: ");
347 Status=NtSetValueKey(hKey,&ValueName,0,REG_DWORD,(PVOID)"reac",4);
348 dprintf("\t\t\tStatus=%x\n",Status);
349 NtClose(hKey);
350 dprintf("NtOpenKey \\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile : ");
351 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile");
352 InitializeObjectAttributes(&ObjectAttributes,
353 &KeyName,
354 OBJ_CASE_INSENSITIVE,
355 NULL,
356 NULL);
357 Status=NtOpenKey( &hKey, MAXIMUM_ALLOWED, &ObjectAttributes);
358 dprintf("\t\t\t\tStatus =%x\n",Status);
359 if(Status==0)
360 {
361 dprintf("NtEnumerateValueKey : \n");
362 Index=0;
363 while(Status == STATUS_SUCCESS)
364 {
365 Status=NtEnumerateValueKey(hKey,Index++,KeyValueFullInformation
366 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
367 ,&Length);
368 if(Status== STATUS_SUCCESS)
369 {
370 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
371 ,KeyValueInformation[0].DataOffset
372 ,KeyValueInformation[0].DataLength
373 ,KeyValueInformation[0].NameLength);
374 for (i=0;i<KeyValueInformation[0].NameLength/2;i++)
375 dprintf("%C",KeyValueInformation[0].Name[i]);
376 dprintf(", Type = %d\n",KeyValueInformation[0].Type);
377 if (KeyValueInformation[0].Type == REG_SZ)
378 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation[0]
379 +KeyValueInformation[0].DataOffset));
380 }
381 }
382 }
383 NtClose(hKey);
384 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
385 ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
386 if (Buffer[0] != 'y' && Buffer[0] != 'Y') return;
387 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonvolatile");
388 InitializeObjectAttributes(&ObjectAttributes,
389 &KeyName,
390 OBJ_CASE_INSENSITIVE,
391 NULL,
392 NULL);
393 dprintf("NtOpenKey : ");
394 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
395 dprintf("\t\t\t\tStatus =%x\n",Status);
396 dprintf("NtDeleteKey : ");
397 Status=NtDeleteKey(hKey);
398 dprintf("\t\t\t\tStatus =%x\n",Status);
399 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos\\test3");
400 InitializeObjectAttributes(&ObjectAttributes,
401 &KeyName,
402 OBJ_CASE_INSENSITIVE,
403 NULL,
404 NULL);
405 dprintf("NtOpenKey : ");
406 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
407 dprintf("\t\t\t\tStatus =%x\n",Status);
408 dprintf("NtDeleteKey : ");
409 Status=NtDeleteKey(hKey);
410 dprintf("\t\t\t\tStatus =%x\n",Status);
411 NtClose(hKey);
412 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
413 InitializeObjectAttributes(&ObjectAttributes,
414 &KeyName,
415 OBJ_CASE_INSENSITIVE,
416 NULL,
417 NULL);
418 dprintf("NtOpenKey : ");
419 Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
420 dprintf("\t\t\t\tStatus =%x\n",Status);
421 dprintf("NtDeleteKey : ");
422 Status=NtDeleteKey(hKey);
423 dprintf("\t\t\t\tStatus =%x\n",Status);
424 NtClose(hKey);
425 }
426
427 void test4(void)
428 {
429 HKEY hKey = NULL,hKey1;
430 DWORD dwDisposition;
431 DWORD dwError;
432 DWORD RegDataType, RegDataSize;
433 BOOL GlobalFifoEnable;
434 HKEY hPortKey;
435 DWORD RegDisposition;
436 WCHAR szClass[260];
437 DWORD cchClass;
438 DWORD cSubKeys;
439 DWORD cchMaxSubkey;
440 DWORD cchMaxClass;
441 DWORD cValues;
442 DWORD cchMaxValueName;
443 DWORD cbMaxValueData;
444 DWORD cbSecurityDescriptor;
445 FILETIME ftLastWriteTime;
446 SYSTEMTIME LastWriteTime;
447
448 dprintf ("RegOpenKeyExW HKLM\\System\\Setup: ");
449 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
450 L"System\\Setup",
451 0,
452 KEY_ALL_ACCESS,
453 &hKey1);
454 dprintf("\t\tdwError =%x\n",dwError);
455 if (dwError == ERROR_SUCCESS)
456 {
457 dprintf("RegQueryInfoKeyW: ");
458 cchClass=260;
459 dwError = RegQueryInfoKeyW(hKey1
460 , szClass, &cchClass, NULL, &cSubKeys
461 , &cchMaxSubkey, &cchMaxClass, &cValues, &cchMaxValueName
462 , &cbMaxValueData, &cbSecurityDescriptor, &ftLastWriteTime);
463 dprintf ("\t\t\t\tdwError %x\n", dwError);
464 FileTimeToSystemTime(&ftLastWriteTime,&LastWriteTime);
465 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
466 ,LastWriteTime.wMonth
467 ,LastWriteTime.wDay
468 ,LastWriteTime.wYear
469 ,LastWriteTime.wHour
470 ,LastWriteTime.wMinute
471 ,LastWriteTime.wSecond
472 ,LastWriteTime.wMilliseconds
473 );
474 }
475
476
477 dprintf ("RegOpenKeyExW: ");
478 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
479 L"System\\ControlSet001\\Services\\Serial",
480 0,
481 KEY_ALL_ACCESS,
482 &hKey);
483 dprintf ("\t\t\t\t\tdwError %x\n", dwError);
484 RegDataSize = sizeof(GlobalFifoEnable);
485 if (dwError == ERROR_SUCCESS)
486 {
487 dprintf ("RegQueryValueExW: ");
488 dwError = RegQueryValueExW(hKey,
489 L"ForceFifoEnable",
490 NULL,
491 &RegDataType,
492 (PBYTE)&GlobalFifoEnable,
493 &RegDataSize);
494 dprintf("\t\t\t\tdwError =%x\n",dwError);
495 if (dwError == 0)
496 {
497 dprintf("\tValue:DT=%d, DS=%d, Value=%d\n"
498 ,RegDataType
499 ,RegDataSize
500 ,GlobalFifoEnable);
501 }
502 }
503 dprintf ("RegCreateKeyExW: ");
504 dwError = RegCreateKeyExW(hKey,
505 L"Parameters\\Serial001",
506 0,
507 NULL,
508 0,
509 KEY_ALL_ACCESS,
510 NULL,
511 &hPortKey,
512 &RegDisposition
513 );
514 dprintf ("\t\t\t\tdwError %x\n", dwError);
515
516 dprintf ("RegCreateKeyExW: ");
517 dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
518 L"Software\\test4reactos\\test",
519 0,
520 NULL,
521 REG_OPTION_NON_VOLATILE,
522 KEY_ALL_ACCESS,
523 NULL,
524 &hKey,
525 &dwDisposition);
526
527 dprintf ("\t\t\t\tdwError %x ", dwError);
528 dprintf ("dwDisposition %x\n", dwDisposition);
529 if (dwError == ERROR_SUCCESS)
530 {
531 dprintf ("RegSetValueExW: ");
532 dwError = RegSetValueExW (hKey,
533 L"TestValue",
534 0,
535 REG_SZ,
536 (BYTE*)L"TestString",
537 20);
538
539 dprintf ("\t\t\t\tdwError %x\n", dwError);
540 dprintf ("RegCloseKey: ");
541 dwError = RegCloseKey (hKey);
542 dprintf ("\t\t\t\t\tdwError %x\n", dwError);
543 }
544 dprintf ("\n\n");
545
546 hKey = NULL;
547
548 dprintf ("RegCreateKeyExW: ");
549 dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
550 L"software\\Test",
551 0,
552 NULL,
553 REG_OPTION_VOLATILE,
554 KEY_ALL_ACCESS,
555 NULL,
556 &hKey,
557 &dwDisposition);
558
559 dprintf ("\t\t\t\tdwError %x ", dwError);
560 dprintf ("dwDisposition %x\n", dwDisposition);
561
562
563 if (dwError == ERROR_SUCCESS)
564 {
565 dprintf("RegQueryInfoKeyW: ");
566 cchClass=260;
567 dwError = RegQueryInfoKeyW(hKey
568 , szClass, &cchClass, NULL, &cSubKeys
569 , &cchMaxSubkey, &cchMaxClass, &cValues, &cchMaxValueName
570 , &cbMaxValueData, &cbSecurityDescriptor, &ftLastWriteTime);
571 dprintf ("\t\t\t\tdwError %x\n", dwError);
572 FileTimeToSystemTime(&ftLastWriteTime,&LastWriteTime);
573 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
574 ,LastWriteTime.wMonth
575 ,LastWriteTime.wDay
576 ,LastWriteTime.wYear
577 ,LastWriteTime.wHour
578 ,LastWriteTime.wMinute
579 ,LastWriteTime.wSecond
580 ,LastWriteTime.wMilliseconds
581 );
582 dprintf ("RegCloseKey: ");
583 dwError = RegCloseKey (hKey);
584 dprintf ("\t\t\t\t\tdwError %x\n", dwError);
585 }
586 dprintf ("\nTests done...\n");
587 }
588
589 void test5(void)
590 {
591 OBJECT_ATTRIBUTES ObjectAttributes;
592 UNICODE_STRING KeyName;
593 NTSTATUS Status;
594 LONG dwError;
595 TOKEN_PRIVILEGES NewPrivileges;
596 HANDLE Token;
597 LUID Luid;
598 BOOLEAN bRes;
599 Status=NtOpenProcessToken(GetCurrentProcess()
600 ,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&Token);
601 dprintf("\t\t\t\tStatus =%x\n",Status);
602 /*
603 bRes=LookupPrivilegeValueA(NULL,SE_RESTORE_NAME,&Luid);
604 dprintf("\t\t\t\tbRes =%x\n",bRes);
605 */
606 NewPrivileges.PrivilegeCount = 1;
607 NewPrivileges.Privileges[0].Luid = Luid;
608 NewPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
609
610 // Status = NtAdjustPrivilegesToken(
611 Status = AdjustTokenPrivileges(
612 Token,
613 FALSE,
614 &NewPrivileges,
615 0,
616 NULL,
617 NULL
618 );
619 dprintf("\t\t\t\tStatus =%x\n",Status);
620
621 Status=NtClose(Token);
622 dprintf("\t\t\t\tStatus =%x\n",Status);
623
624
625 RtlInitUnicodeString(&KeyName,L"test5");
626 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
627 , NULL, NULL);
628 Status = NtLoadKey(HKEY_LOCAL_MACHINE,&ObjectAttributes);
629 dprintf("\t\t\t\tStatus =%x\n",Status);
630 dwError=RegLoadKey(HKEY_LOCAL_MACHINE,"def"
631 ,"test5");
632 dprintf("\t\t\t\tdwError =%x\n",dwError);
633
634 }
635
636 int main(int argc, char* argv[])
637 {
638 char Buffer[10];
639 DWORD Result;
640
641 AllocConsole();
642 InputHandle = GetStdHandle(STD_INPUT_HANDLE);
643 OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
644
645 dprintf("choose test :\n");
646 dprintf(" 1=Ntxxx read functions\n");
647 dprintf(" 2=Ntxxx write functions : volatile keys\n");
648 dprintf(" 3=Ntxxx write functions : non volatile keys\n");
649 dprintf(" 4=Regxxx functions\n");
650 ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
651 switch (Buffer[0])
652 {
653 case '1':
654 test1();
655 break;
656 case '2':
657 test2();
658 break;
659 case '3':
660 test3();
661 break;
662 case '4':
663 test4();
664 break;
665 case '5':
666 test5();
667 break;
668 }
669 return 0;
670 }