work on registry
[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
22 int main(int argc, char* argv[])
23 {
24 HKEY hKey = NULL,hKey1;
25 DWORD dwDisposition;
26 DWORD dwError;
27 DWORD Err, RegDataType, RegDataSize, OldComPortNumber;
28 OBJECT_ATTRIBUTES ObjectAttributes;
29 HANDLE StConfigHandle;
30 ULONG Disposition;
31 NTSTATUS Status;
32 UNICODE_STRING KeyName;
33 BOOL GlobalFifoEnable;
34 HKEY hPortKey;
35 DWORD RegDisposition;
36 ULONG Index,Length,i;
37 KEY_BASIC_INFORMATION KeyInformation[5];
38 KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
39
40 AllocConsole();
41 InputHandle = GetStdHandle(STD_INPUT_HANDLE);
42 OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
43
44 dprintf("NtOpenKey \\Registry : ");
45 RtlInitUnicodeString(&KeyName, L"\\Registry");
46 InitializeObjectAttributes(&ObjectAttributes,
47 &KeyName,
48 OBJ_CASE_INSENSITIVE,
49 NULL,
50 NULL);
51 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
52 dprintf("\t\t\t\tStatus =%x\n",Status);
53 if(Status==0)
54 {
55 dprintf("NtQueryKey : ");
56 Status=NtQueryKey(hKey1,KeyBasicInformation
57 ,&KeyInformation[0], sizeof(KeyInformation)
58 ,&Length);
59 dprintf("\t\t\t\t\tStatus =%x\n",Status);
60 if (Status == STATUS_SUCCESS)
61 {
62 dprintf("\tKey Name = ");
63 for (i=0;i<KeyInformation[0].NameLength/2;i++)
64 dprintf("%C",KeyInformation[0].Name[i]);
65 dprintf("\n");
66 }
67 dprintf("NtEnumerateKey : \n");
68 Index=0;
69 while(Status == STATUS_SUCCESS)
70 {
71 Status=NtEnumerateKey(hKey1,Index++,KeyBasicInformation
72 ,&KeyInformation[0], sizeof(KeyInformation)
73 ,&Length);
74 if(Status== STATUS_SUCCESS)
75 {
76 dprintf("\tSubKey Name = ");
77 for (i=0;i<KeyInformation[0].NameLength/2;i++)
78 dprintf("%C",KeyInformation[0].Name[i]);
79 dprintf("\n");
80 }
81 }
82 dprintf("NtCloseKey : ");
83 Status = NtClose( hKey1 );
84 dprintf("\t\t\t\t\tStatus =%x\n",Status);
85 }
86
87 dprintf("NtOpenKey \\Registry\\Machine : ");
88 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine");
89 InitializeObjectAttributes(&ObjectAttributes,
90 &KeyName,
91 OBJ_CASE_INSENSITIVE,
92 NULL,
93 NULL);
94 Status=NtOpenKey( &hKey1, MAXIMUM_ALLOWED, &ObjectAttributes);
95 dprintf("\t\t\tStatus =%x\n",Status);
96
97 dprintf("NtOpenKey System\\Setup : ");
98 RtlInitUnicodeString(&KeyName, L"System\\Setup");
99 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
100 , hKey1 , NULL);
101 Status = NtOpenKey ( &hKey, KEY_READ , &ObjectAttributes);
102 dprintf("\t\t\tStatus =%x\n",Status);
103 if(Status==0)
104 {
105 dprintf("NtQueryValueKey : ");
106 RtlInitUnicodeString(&KeyName, L"CmdLine");
107 Status=NtQueryValueKey(hKey,&KeyName,KeyValueFullInformation
108 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
109 ,&Length);
110 dprintf("\t\t\t\tStatus =%x\n",Status);
111 if (Status == STATUS_SUCCESS)
112 {
113 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
114 ,KeyValueInformation[0].DataOffset
115 ,KeyValueInformation[0].DataLength
116 ,KeyValueInformation[0].NameLength);
117 for (i=0;i<10 && i<KeyValueInformation[0].NameLength/2;i++)
118 dprintf("%C",KeyValueInformation[0].Name[i]);
119 dprintf("\n");
120 dprintf("\t\tType = %d\n",KeyValueInformation[0].Type);
121 if (KeyValueInformation[0].Type == REG_SZ)
122 dprintf("\t\tValue = %S\n",KeyValueInformation[0].Name+1
123 +KeyValueInformation[0].NameLength/2);
124 }
125 dprintf("NtEnumerateValueKey : \n");
126 Index=0;
127 while(Status == STATUS_SUCCESS)
128 {
129 Status=NtEnumerateValueKey(hKey,Index++,KeyValueFullInformation
130 ,&KeyValueInformation[0], sizeof(KeyValueInformation)
131 ,&Length);
132 if(Status== STATUS_SUCCESS)
133 {
134 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
135 ,KeyValueInformation[0].DataOffset
136 ,KeyValueInformation[0].DataLength
137 ,KeyValueInformation[0].NameLength);
138 for (i=0;i<KeyValueInformation[0].NameLength/2;i++)
139 dprintf("%C",KeyValueInformation[0].Name[i]);
140 dprintf(", Type = %d\n",KeyValueInformation[0].Type);
141 if (KeyValueInformation[0].Type == REG_SZ)
142 dprintf("\t\tValue = %S\n",((char*)&KeyValueInformation[0]
143 +KeyValueInformation[0].DataOffset));
144 }
145 }
146 dprintf("NtCloseKey : ");
147 Status = NtClose( hKey1 );
148 dprintf("\t\t\t\t\tStatus =%x\n",Status);
149 }
150
151
152 return 0;
153
154
155 dprintf ("RegOpenKeyExW HKLM\\System\\ControlSet001: ");
156 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
157 L"System\\ControlSet001",
158 0,
159 KEY_ALL_ACCESS,
160 &hKey);
161 dprintf ("dwError %x\n", dwError);
162 /*
163 Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
164 ,0,NULL,REG_OPTION_VOLATILE,NULL);
165 dprintf("Status=%x\n",Status);
166 */
167
168
169 dprintf ("RegOpenKeyExW: ");
170 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
171 L"System\\ControlSet001\\Services\\Serial",
172 0,
173 KEY_ALL_ACCESS,
174 &hKey);
175 dprintf ("dwError %x\n", dwError);
176 RegDataSize = sizeof(GlobalFifoEnable);
177 if (dwError == ERROR_SUCCESS)
178 {
179 dprintf ("RegQueryValueExW: ");
180 dwError = RegQueryValueExW(hKey,
181 L"ForceFifoEnable",
182 NULL,
183 &RegDataType,
184 (PBYTE)&GlobalFifoEnable,
185 &RegDataSize);
186 dprintf ("dwError %x\n", dwError);
187 }
188 dprintf ("RegCreateKeyExW: ");
189 dwError = RegCreateKeyExW(hKey,
190 L"Parameters\\Serial001",
191 0,
192 NULL,
193 0,
194 KEY_ALL_ACCESS,
195 NULL,
196 &hPortKey,
197 &RegDisposition
198 );
199 dprintf ("dwError %x\n", dwError);
200
201 dprintf ("RegCreateKeyExW: ");
202 dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
203 // L"System\\ControlSet001\\Services\\Serial\\Test",
204 L"Software\\reactos\\test",
205 0,
206 NULL,
207 REG_OPTION_NON_VOLATILE,
208 KEY_ALL_ACCESS,
209 NULL,
210 &hKey,
211 &dwDisposition);
212
213 dprintf ("dwError %x ", dwError);
214 dprintf ("dwDisposition %x\n", dwDisposition);
215 if (dwError == ERROR_SUCCESS)
216 {
217 dprintf ("RegSetValueExW: ");
218 dwError = RegSetValueExW (hKey,
219 L"TestValue",
220 0,
221 REG_SZ,
222 L"TestString",
223 20);
224
225 dprintf ("dwError %x\n", dwError);
226 dprintf ("RegCloseKey: ");
227 dwError = RegCloseKey (hKey);
228 dprintf ("dwError %x\n", dwError);
229 }
230 dprintf ("\n\n");
231
232 hKey = NULL;
233
234 dprintf ("RegCreateKeyExW:\n");
235 dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
236 L"software\\Test",
237 0,
238 NULL,
239 REG_OPTION_VOLATILE,
240 KEY_ALL_ACCESS,
241 NULL,
242 &hKey,
243 &dwDisposition);
244
245 dprintf ("dwError %x ", dwError);
246 dprintf ("dwDisposition %x\n", dwDisposition);
247
248 #if 0
249 dprintf ("RegQueryKeyExW:\n");
250
251 #endif
252 if (dwError == ERROR_SUCCESS)
253 {
254 dprintf ("RegCloseKey:\n");
255 dwError = RegCloseKey (hKey);
256 dprintf ("dwError %x\n", dwError);
257 }
258
259 dprintf ("\nTests done...\n");
260
261 return 0;
262 }
263