ea13782a28d80f87d39a117853117ef0075512cf
[reactos.git] / rosapps / applications / sysutils / systeminfo / systeminfo.c
1 /*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16 /* Copyright (C) 2007, Dmitry Chapyshev <lentind@yandex.ru> */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <ctype.h>
22 #include <windows.h>
23 #include <io.h>
24
25 #include "resource.h"
26
27 #define BUFFER_SIZE 32767
28
29 /* Load from resource and convert to OEM */
30 static
31 BOOL
32 GetOemStrings(UINT rcID, LPSTR OutMsg)
33 {
34 TCHAR Msg[BUFFER_SIZE];
35 if (LoadString(GetModuleHandle(NULL), rcID, (LPTSTR)Msg, BUFFER_SIZE))
36 {
37 CharToOem(Msg, OutMsg);
38 return TRUE;
39 }
40 return FALSE;
41 }
42
43 /* Load data from registry */
44 static
45 BOOL
46 GetRegistryValue(HKEY hKeyName, LPCTSTR SubKey, LPCTSTR ValueName, LPCTSTR Buf)
47 {
48 DWORD CharCount = BUFFER_SIZE;
49 HKEY hKey;
50 LONG lRet;
51
52 CharCount = BUFFER_SIZE;
53 lRet = RegOpenKeyEx(hKeyName,
54 SubKey,
55 0,
56 KEY_QUERY_VALUE,
57 &hKey);
58 if (lRet != ERROR_SUCCESS) return FALSE;
59 lRet = RegQueryValueEx(hKey,
60 ValueName,
61 NULL,
62 NULL,
63 (LPBYTE)Buf,
64 &CharCount);
65 if (lRet != ERROR_SUCCESS) return FALSE;
66 return TRUE;
67 }
68
69 /* Show usage */
70 static
71 VOID
72 Usage(VOID)
73 {
74 TCHAR Buf[BUFFER_SIZE];
75 if(GetOemStrings(IDS_USAGE,Buf)) printf("%s",Buf);
76 }
77
78 /* Print all system information */
79 VOID
80 AllSysInfo(VOID)
81 {
82 DWORD CharCount = BUFFER_SIZE;
83 OSVERSIONINFO VersionInfo;
84 BOOL bOsVersionInfoEx;
85 SYSTEM_INFO SysInfo;
86 TCHAR Buf[BUFFER_SIZE],Tmp[BUFFER_SIZE], Msg[BUFFER_SIZE];
87 MEMORYSTATUS memory;
88 unsigned int DIV = 1024;
89 TIME_ZONE_INFORMATION TimeZoneInfo;
90
91 GetSystemInfo(&SysInfo);
92
93 // getting computer name
94 CharCount = BUFFER_SIZE;
95 if(!GetComputerName(Buf,&CharCount)) printf("Error getting: GetComputerName");
96 if(GetOemStrings(IDS_HOST_NAME,Msg)) fprintf(stderr,Msg,Buf);
97
98 //getting OS Name
99 GetRegistryValue(HKEY_LOCAL_MACHINE,
100 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
101 TEXT("ProductName"),
102 Buf);
103 if(GetOemStrings(IDS_OS_NAME,Msg)) fprintf(stderr,Msg,Buf);
104
105 //getting OS Version
106 ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFO));
107 VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
108 if(!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*)&VersionInfo)))
109 {
110 VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
111 if (!GetVersionEx((OSVERSIONINFO*)&VersionInfo))
112 return;
113 }
114 if (VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
115 {
116 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
117 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
118 TEXT("CSDVersion"),
119 Buf))
120 if(GetOemStrings(IDS_OS_VERSION,Msg))
121 fprintf(stderr, Msg,
122 (int)VersionInfo.dwMajorVersion,
123 (int)VersionInfo.dwMinorVersion,
124 (int)VersionInfo.dwBuildNumber,
125 Buf);
126 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
127 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
128 TEXT("CurrentBuildNumber"),
129 Buf))
130 if(GetOemStrings(IDS_OS_BUILD,Msg)) fprintf(stderr,Msg,Buf);
131 }
132
133 //getting OS Manufacturer
134
135 //getting OS Configuration
136
137 //getting OS Build Type
138 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
139 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
140 TEXT("CurrentType"),
141 Buf))
142 if(GetOemStrings(IDS_OS_BUILD_TYPE,Msg)) fprintf(stderr,Msg,Buf);
143
144 //getting Registered Owner
145 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
146 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
147 TEXT("RegisteredOwner"),
148 Buf))
149 if(GetOemStrings(IDS_REG_OWNER,Msg)) fprintf(stderr,Msg,Buf);
150
151 //getting Registered Organization
152 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
153 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
154 TEXT("RegisteredOrganization"),
155 Buf))
156 if(GetOemStrings(IDS_REG_ORG,Msg)) fprintf(stderr,Msg,Buf);
157
158 //getting Product ID
159 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
160 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
161 TEXT("ProductId"),
162 Buf))
163 if(GetOemStrings(IDS_PRODUCT_ID,Msg)) fprintf(stderr,Msg,Buf);
164
165 //getting Install Date
166 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
167 TEXT("SOFTWARE\\Microsoft\\WBEM\\CIMOM"),
168 TEXT("SetupDate"),
169 Buf))
170 if(GetOemStrings(IDS_INST_DATE,Msg)) fprintf(stderr,Msg,Buf);
171
172 //getting Install Time
173 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
174 TEXT("SOFTWARE\\Microsoft\\WBEM\\CIMOM"),
175 TEXT("SetupTime"),
176 Buf))
177 if(GetOemStrings(IDS_INST_TIME,Msg)) fprintf(stderr,Msg,Buf);
178
179 //getting System Up Time
180
181 //getting System Manufacturer
182
183 //getting System Model
184
185 //getting System type
186 switch (SysInfo.wProcessorArchitecture)
187 {
188 case PROCESSOR_ARCHITECTURE_UNKNOWN:
189 if(GetOemStrings(IDS_SYS_TYPE_UNKNOWN,Msg)) printf("%s",Msg);
190 break;
191 case PROCESSOR_ARCHITECTURE_INTEL:
192 if(GetOemStrings(IDS_SYS_TYPE_X86,Msg)) printf("%s",Msg);
193 break;
194 case PROCESSOR_ARCHITECTURE_IA64:
195 if(GetOemStrings(IDS_SYS_TYPE_IA64,Msg)) printf("%s",Msg);
196 break;
197 case PROCESSOR_ARCHITECTURE_AMD64:
198 if(GetOemStrings(IDS_SYS_TYPE_AMD64,Msg)) printf("%s",Msg);
199 break;
200 }
201
202 //getting Processor(s)
203 if(GetOemStrings(IDS_PROCESSORS,Msg))
204 {
205 unsigned int i;
206 fprintf(stderr,Msg,(unsigned int)SysInfo.dwNumberOfProcessors);
207 for(i = 0; i < (unsigned int)SysInfo.dwNumberOfProcessors; i++)
208 {
209 sprintf(Tmp,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%u",i);
210 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
211 (LPCTSTR)Tmp,
212 TEXT("Identifier"),
213 Buf))
214 printf(" [0%u]: %s",i+1,Buf);
215 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
216 (LPCTSTR)Tmp,
217 TEXT("VendorIdentifier"),
218 Buf))
219 printf(" %s\n",Buf);
220 }
221 }
222
223 //getting BIOS Version
224 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
225 TEXT("HARDWARE\\DESCRIPTION\\System"),
226 TEXT("SystemBiosVersion"),
227 Buf))
228 if(GetOemStrings(IDS_BIOS_VERSION,Msg)) fprintf(stderr,Msg,Buf);
229
230 //gettings BIOS date
231 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
232 TEXT("HARDWARE\\DESCRIPTION\\System"),
233 TEXT("SystemBiosDate"),
234 Buf))
235 if(GetOemStrings(IDS_BIOS_DATE,Msg)) fprintf(stderr,Msg,Buf);
236
237 //getting ReactOS Directory
238 if(!GetWindowsDirectory(Buf,BUFFER_SIZE)) printf("Error getting: GetWindowsDirectory");
239 if(GetOemStrings(IDS_ROS_DIR,Msg)) fprintf(stderr,Msg,Buf);
240
241 //getting System Directory
242 if(!GetSystemDirectory(Buf,BUFFER_SIZE)) printf("Error getting: GetSystemDirectory");
243 if(GetOemStrings(IDS_SYS_DIR,Msg)) fprintf(stderr,Msg,Buf);
244
245 //getting Boot Device
246 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
247 TEXT("SYSTEM\\Setup"),
248 TEXT("SystemPartition"),
249 Buf))
250 if(GetOemStrings(IDS_BOOT_DEV,Msg)) fprintf(stderr,Msg,Buf);
251
252 //getting System Locale
253 if (GetRegistryValue(HKEY_CURRENT_USER,
254 TEXT("Control Panel\\International"),
255 TEXT("Locale"),
256 Tmp))
257 if (GetRegistryValue(HKEY_CLASSES_ROOT,
258 TEXT("MIME\\Database\\Rfc1766"),
259 (LPTSTR)Tmp,
260 Buf))
261 if(GetOemStrings(IDS_SYS_LOCALE,Msg)) fprintf(stderr,Msg,Buf);
262
263 //getting Input Locale
264 if (GetRegistryValue(HKEY_CURRENT_USER,
265 TEXT("Keyboard Layout\\Preload"),
266 TEXT("1"),
267 Buf))
268 {
269 int i,j;
270 for(j = 0, i = 4; i <= 8; j++, i++) Tmp[j] = Buf[i];
271 if (GetRegistryValue(HKEY_CLASSES_ROOT,
272 TEXT("MIME\\Database\\Rfc1766"),
273 (LPTSTR)Tmp,
274 Buf))
275 if(GetOemStrings(IDS_INPUT_LOCALE,Msg)) fprintf(stderr,Msg,Buf);
276 }
277
278 //getting Time Zone
279 GetTimeZoneInformation(&TimeZoneInfo);
280 sprintf(Tmp,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%S",TimeZoneInfo.StandardName);
281 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
282 (LPCTSTR)Tmp,
283 TEXT("Display"),
284 Buf))
285 if(GetOemStrings(IDS_TIME_ZONE,Msg)) fprintf(stderr,Msg,Buf);
286
287 //getting Total Physical Memory
288 GlobalMemoryStatus(&memory);
289 if(GetOemStrings(IDS_TOTAL_PHYS_MEM,Msg))
290 fprintf(stderr,
291 Msg,
292 memory.dwTotalPhys/(DIV*DIV),
293 memory.dwTotalPhys/DIV);
294
295 //getting Available Physical Memory
296 if(GetOemStrings(IDS_AVAIL_PHISICAL_MEM,Msg))
297 fprintf(stderr,
298 Msg,
299 memory.dwAvailPhys/(DIV*DIV),
300 memory.dwAvailPhys/DIV);
301
302 //getting Virtual Memory: Max Size
303 if(GetOemStrings(IDS_VIRT_MEM_MAX,Msg))
304 fprintf(stderr,
305 Msg,
306 memory.dwTotalVirtual/(DIV*DIV),
307 memory.dwTotalVirtual/DIV);
308
309 //getting Virtual Memory: Available
310 if(GetOemStrings(IDS_VIRT_MEM_AVAIL,Msg))
311 fprintf(stderr,
312 Msg,
313 memory.dwAvailVirtual/(DIV*DIV),
314 memory.dwAvailVirtual/DIV);
315
316 //getting Virtual Memory: In Use
317 if(GetOemStrings(IDS_VIRT_MEM_INUSE,Msg))
318 fprintf(stderr,
319 Msg,
320 (memory.dwTotalVirtual-memory.dwAvailVirtual)/(DIV*DIV),
321 (memory.dwTotalVirtual-memory.dwAvailVirtual)/DIV);
322
323 //getting Page File Location(s)
324 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
325 TEXT("SYSTEM\\ControlSet001\\Control\\Session Manager\\Memory Management"),
326 TEXT("PagingFiles"),
327 Buf))
328 {
329 int i;
330 for(i = 0; i < strlen((char*)Buf); i++)
331 {
332 if (Buf[i] == ' ')
333 {
334 Buf[i] = '\0';
335 break;
336 }
337 }
338 if(GetOemStrings(IDS_PAGEFILE_LOC,Msg)) fprintf(stderr,Msg,Buf);
339 }
340
341 //getting Domain
342 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
343 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"),
344 TEXT("CachePrimaryDomain"),
345 Buf))
346 if(GetOemStrings(IDS_DOMINE,Msg)) fprintf(stderr,Msg,Buf);
347
348 //getting Logon Server
349
350 //getting NetWork Card(s)
351 if(GetOemStrings(IDS_NETWORK_CARDS,Msg))
352 {
353
354 }
355 }
356
357 /* Main program */
358 int
359 main(int argc, char *argv[])
360 {
361 char str[] = "/?";
362 if (argc > 1 && !strcmp(argv[1], str))
363 {
364 Usage();
365 return 0;
366 }
367 AllSysInfo();
368 return 0;
369 }