10 void dprintf(char* fmt
, ...)
16 vsprintf(buffer
,fmt
,args
);
17 WriteConsoleA(OutputHandle
, buffer
, strlen(buffer
), NULL
, NULL
);
23 HKEY hKey
= NULL
,hKey1
;
24 OBJECT_ATTRIBUTES ObjectAttributes
;
26 UNICODE_STRING KeyName
;
28 KEY_BASIC_INFORMATION KeyInformation
[5];
29 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
32 InputHandle
= GetStdHandle(STD_INPUT_HANDLE
);
33 OutputHandle
= GetStdHandle(STD_OUTPUT_HANDLE
);
35 dprintf("NtOpenKey \\Registry : ");
36 RtlInitUnicodeString(&KeyName
, L
"\\Registry");
37 InitializeObjectAttributes(&ObjectAttributes
,
42 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
43 dprintf("\t\t\t\tStatus =%x\n",Status
);
46 dprintf("NtQueryKey : ");
47 Status
=NtQueryKey(hKey1
,KeyBasicInformation
48 ,&KeyInformation
[0], sizeof(KeyInformation
)
50 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
51 if (Status
== STATUS_SUCCESS
)
53 dprintf("\tKey Name = ");
54 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
55 dprintf("%C",KeyInformation
[0].Name
[i
]);
58 dprintf("NtEnumerateKey : \n");
60 while(Status
== STATUS_SUCCESS
)
62 Status
=NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
63 ,&KeyInformation
[0], sizeof(KeyInformation
)
65 if(Status
== STATUS_SUCCESS
)
67 dprintf("\tSubKey Name = ");
68 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
69 dprintf("%C",KeyInformation
[0].Name
[i
]);
73 dprintf("NtClose : ");
74 Status
= NtClose( hKey1
);
75 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
79 dprintf("NtOpenKey \\Registry\\Machine : ");
80 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine");
81 InitializeObjectAttributes(&ObjectAttributes
,
86 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
87 dprintf("\t\t\tStatus =%x\n",Status
);
89 dprintf("NtOpenKey System\\Setup : ");
90 RtlInitUnicodeString(&KeyName
, L
"System\\Setup");
91 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
93 Status
= NtOpenKey ( &hKey
, KEY_READ
, &ObjectAttributes
);
94 dprintf("\t\t\tStatus =%x\n",Status
);
97 dprintf("NtQueryValueKey : ");
98 RtlInitUnicodeString(&KeyName
, L
"CmdLine");
99 Status
=NtQueryValueKey(hKey
,&KeyName
,KeyValueFullInformation
100 ,&KeyValueInformation
[0], sizeof(KeyValueInformation
)
102 dprintf("\t\t\t\tStatus =%x\n",Status
);
103 if (Status
== STATUS_SUCCESS
)
105 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
106 ,KeyValueInformation
[0].DataOffset
107 ,KeyValueInformation
[0].DataLength
108 ,KeyValueInformation
[0].NameLength
);
109 for (i
=0;i
<10 && i
<KeyValueInformation
[0].NameLength
/2;i
++)
110 dprintf("%C",KeyValueInformation
[0].Name
[i
]);
112 dprintf("\t\tType = %d\n",KeyValueInformation
[0].Type
);
113 if (KeyValueInformation
[0].Type
== REG_SZ
)
114 dprintf("\t\tValue = %S\n",KeyValueInformation
[0].Name
+1
115 +KeyValueInformation
[0].NameLength
/2);
117 dprintf("NtEnumerateValueKey : \n");
119 while(Status
== STATUS_SUCCESS
)
121 Status
=NtEnumerateValueKey(hKey
,Index
++,KeyValueFullInformation
122 ,&KeyValueInformation
[0], sizeof(KeyValueInformation
)
124 if(Status
== STATUS_SUCCESS
)
126 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
127 ,KeyValueInformation
[0].DataOffset
128 ,KeyValueInformation
[0].DataLength
129 ,KeyValueInformation
[0].NameLength
);
130 for (i
=0;i
<KeyValueInformation
[0].NameLength
/2;i
++)
131 dprintf("%C",KeyValueInformation
[0].Name
[i
]);
132 dprintf(", Type = %d\n",KeyValueInformation
[0].Type
);
133 if (KeyValueInformation
[0].Type
== REG_SZ
)
134 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation
[0]
135 +KeyValueInformation
[0].DataOffset
));
138 dprintf("NtClose : ");
139 Status
= NtClose( hKey
);
140 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
148 OBJECT_ATTRIBUTES ObjectAttributes
;
149 UNICODE_STRING KeyName
,ValueName
;
151 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
152 ULONG Index
,Length
,i
;
155 dprintf("NtCreateKey volatile: \n");
156 dprintf(" \\Registry\\Machine\\Software\\test2reactos: ");
157 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test2reactos");
158 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
160 Status
= NtCreateKey ( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
161 ,0,NULL
,REG_OPTION_VOLATILE
,NULL
);
162 dprintf("\t\tStatus=%x\n",Status
);
164 dprintf(" ...\\test2 :");
165 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test2reactos\\test2");
166 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
168 Status
= NtCreateKey ( &hKey1
, KEY_ALL_ACCESS
, &ObjectAttributes
169 ,0,NULL
,REG_OPTION_VOLATILE
,NULL
);
170 dprintf("\t\t\t\t\tStatus=%x\n",Status
);
171 dprintf(" ...\\TestVolatile :");
172 RtlInitUnicodeString(&KeyName
, L
"TestVolatile");
173 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
175 Status
= NtCreateKey ( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
176 ,0,NULL
,REG_OPTION_VOLATILE
,NULL
);
177 dprintf("\t\t\t\tStatus=%x\n",Status
);
179 RtlInitUnicodeString(&ValueName
, L
"TestREG_SZ");
180 dprintf("NtSetValueKey reg_sz: ");
181 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_SZ
,(PVOID
)L
"Test Reg_sz",24);
182 dprintf("\t\t\t\tStatus=%x\n",Status
);
183 RtlInitUnicodeString(&ValueName
, L
"TestDWORD");
184 dprintf("NtSetValueKey reg_dword: ");
185 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_DWORD
,(PVOID
)"reac",4);
186 dprintf("\t\t\tStatus=%x\n",Status
);
188 dprintf("NtOpenKey \\Registry\\Machine\\Software\\test2reactos\\test2\\TestVolatile : ");
189 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test2reactos\\test2\\TestVolatile");
190 InitializeObjectAttributes(&ObjectAttributes
,
192 OBJ_CASE_INSENSITIVE
,
195 Status
=NtOpenKey( &hKey
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
196 dprintf("\t\t\t\tStatus =%x\n",Status
);
199 dprintf("NtEnumerateValueKey : \n");
201 while(Status
== STATUS_SUCCESS
)
203 Status
=NtEnumerateValueKey(hKey
,Index
++,KeyValueFullInformation
204 ,&KeyValueInformation
[0], sizeof(KeyValueInformation
)
206 if(Status
== STATUS_SUCCESS
)
208 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
209 ,KeyValueInformation
[0].DataOffset
210 ,KeyValueInformation
[0].DataLength
211 ,KeyValueInformation
[0].NameLength
);
212 for (i
=0;i
<KeyValueInformation
[0].NameLength
/2;i
++)
213 dprintf("%C",KeyValueInformation
[0].Name
[i
]);
214 dprintf(", Type = %d\n",KeyValueInformation
[0].Type
);
215 if (KeyValueInformation
[0].Type
== REG_SZ
)
216 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation
[0]
217 +KeyValueInformation
[0].DataOffset
));
222 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
223 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;
224 if (Buffer
[0] != 'y' && Buffer
[0] != 'Y') return;
225 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test2reactos\\test2\\TestVolatile");
226 InitializeObjectAttributes(&ObjectAttributes
,
228 OBJ_CASE_INSENSITIVE
,
231 dprintf("NtOpenKey : ");
232 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
233 dprintf("\t\t\t\tStatus =%x\n",Status
);
234 dprintf("NtDeleteKey : ");
235 Status
=NtDeleteKey(hKey
);
236 dprintf("\t\t\t\tStatus =%x\n",Status
);
238 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test2reactos\\test2");
239 InitializeObjectAttributes(&ObjectAttributes
,
241 OBJ_CASE_INSENSITIVE
,
244 dprintf("NtOpenKey : ");
245 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
246 dprintf("\t\t\t\tStatus =%x\n",Status
);
247 dprintf("NtDeleteKey : ");
248 Status
=NtDeleteKey(hKey
);
249 dprintf("\t\t\t\tStatus =%x\n",Status
);
251 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test2reactos");
252 InitializeObjectAttributes(&ObjectAttributes
,
254 OBJ_CASE_INSENSITIVE
,
257 dprintf("NtOpenKey : ");
258 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
259 dprintf("\t\t\t\tStatus =%x\n",Status
);
260 dprintf("NtDeleteKey : ");
261 Status
=NtDeleteKey(hKey
);
262 dprintf("\t\t\t\tStatus =%x\n",Status
);
269 OBJECT_ATTRIBUTES ObjectAttributes
;
270 UNICODE_STRING KeyName
,ValueName
;
272 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
273 ULONG Index
,Length
,i
;
276 dprintf("NtCreateKey non volatile: \n");
277 dprintf(" \\Registry\\Machine\\Software\\test3reactos: ");
278 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos");
279 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
281 Status
= NtCreateKey ( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
282 ,0,NULL
,REG_OPTION_NON_VOLATILE
,NULL
);
283 dprintf("\t\tStatus=%x\n",Status
);
285 dprintf(" ...\\test3 :");
286 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos\\test3");
287 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
289 Status
= NtCreateKey ( &hKey1
, KEY_ALL_ACCESS
, &ObjectAttributes
290 ,0,NULL
,REG_OPTION_NON_VOLATILE
,NULL
);
291 dprintf("\t\t\t\t\tStatus=%x\n",Status
);
292 dprintf(" ...\\testNonVolatile :");
293 RtlInitUnicodeString(&KeyName
, L
"TestNonVolatile");
294 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
296 Status
= NtCreateKey ( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
297 ,0,NULL
,REG_OPTION_NON_VOLATILE
,NULL
);
298 dprintf("\t\t\t\tStatus=%x\n",Status
);
300 RtlInitUnicodeString(&ValueName
, L
"TestREG_SZ");
301 dprintf("NtSetValueKey reg_sz: ");
302 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_SZ
,(PVOID
)L
"Test Reg_sz",24);
303 dprintf("\t\t\t\tStatus=%x\n",Status
);
304 RtlInitUnicodeString(&ValueName
, L
"TestDWORD");
305 dprintf("NtSetValueKey reg_dword: ");
306 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_DWORD
,(PVOID
)"reac",4);
307 dprintf("\t\t\tStatus=%x\n",Status
);
309 dprintf("NtOpenKey \\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile : ");
310 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonVolatile");
311 InitializeObjectAttributes(&ObjectAttributes
,
313 OBJ_CASE_INSENSITIVE
,
316 Status
=NtOpenKey( &hKey
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
317 dprintf("\t\t\t\tStatus =%x\n",Status
);
320 dprintf("NtEnumerateValueKey : \n");
322 while(Status
== STATUS_SUCCESS
)
324 Status
=NtEnumerateValueKey(hKey
,Index
++,KeyValueFullInformation
325 ,&KeyValueInformation
[0], sizeof(KeyValueInformation
)
327 if(Status
== STATUS_SUCCESS
)
329 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
330 ,KeyValueInformation
[0].DataOffset
331 ,KeyValueInformation
[0].DataLength
332 ,KeyValueInformation
[0].NameLength
);
333 for (i
=0;i
<KeyValueInformation
[0].NameLength
/2;i
++)
334 dprintf("%C",KeyValueInformation
[0].Name
[i
]);
335 dprintf(", Type = %d\n",KeyValueInformation
[0].Type
);
336 if (KeyValueInformation
[0].Type
== REG_SZ
)
337 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation
[0]
338 +KeyValueInformation
[0].DataOffset
));
343 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
344 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;
345 if (Buffer
[0] != 'y' && Buffer
[0] != 'Y') return;
346 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos\\test3\\testNonvolatile");
347 InitializeObjectAttributes(&ObjectAttributes
,
349 OBJ_CASE_INSENSITIVE
,
352 dprintf("NtOpenKey : ");
353 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
354 dprintf("\t\t\t\tStatus =%x\n",Status
);
355 dprintf("NtDeleteKey : ");
356 Status
=NtDeleteKey(hKey
);
357 dprintf("\t\t\t\tStatus =%x\n",Status
);
358 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos\\test3");
359 InitializeObjectAttributes(&ObjectAttributes
,
361 OBJ_CASE_INSENSITIVE
,
364 dprintf("NtOpenKey : ");
365 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
366 dprintf("\t\t\t\tStatus =%x\n",Status
);
367 dprintf("NtDeleteKey : ");
368 Status
=NtDeleteKey(hKey
);
369 dprintf("\t\t\t\tStatus =%x\n",Status
);
371 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos");
372 InitializeObjectAttributes(&ObjectAttributes
,
374 OBJ_CASE_INSENSITIVE
,
377 dprintf("NtOpenKey : ");
378 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
379 dprintf("\t\t\t\tStatus =%x\n",Status
);
380 dprintf("NtDeleteKey : ");
381 Status
=NtDeleteKey(hKey
);
382 dprintf("\t\t\t\tStatus =%x\n",Status
);
388 HKEY hKey
= NULL
,hKey1
;
391 DWORD RegDataType
, RegDataSize
;
392 BOOL GlobalFifoEnable
;
394 DWORD RegDisposition
;
401 DWORD cchMaxValueName
;
402 DWORD cbMaxValueData
;
403 DWORD cbSecurityDescriptor
;
404 FILETIME ftLastWriteTime
;
405 SYSTEMTIME LastWriteTime
;
407 dprintf ("RegOpenKeyExW HKLM\\System\\Setup: ");
408 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
413 dprintf("\t\tdwError =%x\n",dwError
);
414 if (dwError
== ERROR_SUCCESS
)
416 dprintf("RegQueryInfoKeyW: ");
418 dwError
= RegQueryInfoKeyW(hKey1
419 , szClass
, &cchClass
, NULL
, &cSubKeys
420 , &cchMaxSubkey
, &cchMaxClass
, &cValues
, &cchMaxValueName
421 , &cbMaxValueData
, &cbSecurityDescriptor
, &ftLastWriteTime
);
422 dprintf ("\t\t\t\tdwError %x\n", dwError
);
423 FileTimeToSystemTime(&ftLastWriteTime
,&LastWriteTime
);
424 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
425 ,LastWriteTime
.wMonth
429 ,LastWriteTime
.wMinute
430 ,LastWriteTime
.wSecond
431 ,LastWriteTime
.wMilliseconds
436 dprintf ("RegOpenKeyExW: ");
437 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
438 L
"System\\ControlSet001\\Services\\Serial",
442 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
443 RegDataSize
= sizeof(GlobalFifoEnable
);
444 if (dwError
== ERROR_SUCCESS
)
446 dprintf ("RegQueryValueExW: ");
447 dwError
= RegQueryValueExW(hKey
,
451 (PBYTE
)&GlobalFifoEnable
,
453 dprintf("\t\t\t\tdwError =%x\n",dwError
);
456 dprintf("\tValue:DT=%d, DS=%d, Value=%d\n"
462 dprintf ("RegCreateKeyExW: ");
463 dwError
= RegCreateKeyExW(hKey
,
464 L
"Parameters\\Serial001",
473 dprintf ("\t\t\t\tdwError %x\n", dwError
);
475 dprintf ("RegCreateKeyExW: ");
476 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
477 L
"Software\\test4reactos\\test",
480 REG_OPTION_NON_VOLATILE
,
486 dprintf ("\t\t\t\tdwError %x ", dwError
);
487 dprintf ("dwDisposition %x\n", dwDisposition
);
488 if (dwError
== ERROR_SUCCESS
)
490 dprintf ("RegSetValueExW: ");
491 dwError
= RegSetValueExW (hKey
,
495 (BYTE
*)L
"TestString",
498 dprintf ("\t\t\t\tdwError %x\n", dwError
);
499 dprintf ("RegCloseKey: ");
500 dwError
= RegCloseKey (hKey
);
501 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
507 dprintf ("RegCreateKeyExW: ");
508 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
518 dprintf ("\t\t\t\tdwError %x ", dwError
);
519 dprintf ("dwDisposition %x\n", dwDisposition
);
522 if (dwError
== ERROR_SUCCESS
)
524 dprintf("RegQueryInfoKeyW: ");
526 dwError
= RegQueryInfoKeyW(hKey
527 , szClass
, &cchClass
, NULL
, &cSubKeys
528 , &cchMaxSubkey
, &cchMaxClass
, &cValues
, &cchMaxValueName
529 , &cbMaxValueData
, &cbSecurityDescriptor
, &ftLastWriteTime
);
530 dprintf ("\t\t\t\tdwError %x\n", dwError
);
531 FileTimeToSystemTime(&ftLastWriteTime
,&LastWriteTime
);
532 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
533 ,LastWriteTime
.wMonth
537 ,LastWriteTime
.wMinute
538 ,LastWriteTime
.wSecond
539 ,LastWriteTime
.wMilliseconds
541 dprintf ("RegCloseKey: ");
542 dwError
= RegCloseKey (hKey
);
543 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
545 dprintf ("\nTests done...\n");
548 int main(int argc
, char* argv
[])
554 InputHandle
= GetStdHandle(STD_INPUT_HANDLE
);
555 OutputHandle
= GetStdHandle(STD_OUTPUT_HANDLE
);
557 dprintf("choose test :\n");
558 dprintf(" 1=Ntxxx read functions\n");
559 dprintf(" 2=Ntxxx write functions : volatile keys\n");
560 dprintf(" 3=Ntxxx write functions : non volatile keys\n");
561 dprintf(" 4=Regxxx functions\n");
562 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;