[SYSTEMINFO]
[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 #include <tchar.h>
25
26 #include "resource.h"
27
28 #define BUFFER_SIZE 32767
29 #define B_TO_MB(bytes) ((bytes)/(1024*1024))
30 #define B_TO_KB(bytes) ((bytes)/1024)
31
32 /* Load from resource and convert to OEM */
33 static
34 BOOL
35 GetOemStrings(UINT rcID, LPSTR OutMsg)
36 {
37 TCHAR Msg[BUFFER_SIZE];
38 if (LoadString(GetModuleHandle(NULL), rcID, (LPTSTR)Msg, BUFFER_SIZE))
39 {
40 CharToOem(Msg, OutMsg);
41 return TRUE;
42 }
43 return FALSE;
44 }
45
46 /* Load data from registry */
47 static
48 BOOL
49 GetRegistryValue(HKEY hKeyName, LPCTSTR SubKey, LPCTSTR ValueName, LPCTSTR Buf)
50 {
51 DWORD CharCount = BUFFER_SIZE;
52 HKEY hKey;
53 LONG lRet;
54
55 lRet = RegOpenKeyEx(hKeyName,
56 SubKey,
57 0,
58 KEY_QUERY_VALUE,
59 &hKey);
60 if (lRet != ERROR_SUCCESS) return FALSE;
61 lRet = RegQueryValueEx(hKey,
62 ValueName,
63 NULL,
64 NULL,
65 (LPBYTE)Buf,
66 &CharCount);
67 if (lRet != ERROR_SUCCESS) return FALSE;
68 RegCloseKey(hKey);
69 return TRUE;
70 }
71
72 /* Show usage */
73 static
74 VOID
75 Usage(VOID)
76 {
77 TCHAR Buf[BUFFER_SIZE];
78 if(GetOemStrings(IDS_USAGE, Buf)) printf("%s",Buf);
79 }
80
81 /* Print all system information */
82 VOID
83 AllSysInfo(VOID)
84 {
85 DWORD dwCharCount = BUFFER_SIZE;
86 OSVERSIONINFO VersionInfo;
87 SYSTEM_INFO SysInfo;
88 TCHAR Buf[BUFFER_SIZE], Tmp[BUFFER_SIZE], Msg[BUFFER_SIZE], szSystemDir[MAX_PATH];
89 MEMORYSTATUS MemoryStatus;
90 unsigned int cSeconds;
91 TIME_ZONE_INFORMATION TimeZoneInfo;
92
93 if (!GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0])))
94 printf("Error getting: GetSystemDirectory\n");
95 GetSystemInfo(&SysInfo);
96
97 // getting computer name
98 dwCharCount = BUFFER_SIZE;
99 if (!GetComputerName(Buf, &dwCharCount))
100 printf("Error getting: GetComputerName");
101 if (GetOemStrings(IDS_HOST_NAME, Msg))
102 printf(Msg, Buf);
103
104 //getting OS Name
105 GetRegistryValue(HKEY_LOCAL_MACHINE,
106 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
107 TEXT("ProductName"),
108 Buf);
109 if (GetOemStrings(IDS_OS_NAME, Msg)) printf(Msg, Buf);
110
111 //getting OS Version
112 ZeroMemory(&VersionInfo, sizeof(VersionInfo));
113 VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
114 GetVersionEx(&VersionInfo);
115
116 if (GetOemStrings(IDS_OS_VERSION, Msg))
117 printf(Msg,
118 (unsigned)VersionInfo.dwMajorVersion,
119 (unsigned)VersionInfo.dwMinorVersion,
120 (unsigned)VersionInfo.dwBuildNumber,
121 VersionInfo.szCSDVersion,
122 (unsigned)VersionInfo.dwBuildNumber);
123
124 //getting OS Manufacturer
125
126 //getting OS Configuration
127
128 //getting OS Build Type
129 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
130 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
131 TEXT("CurrentType"),
132 Buf))
133 if (GetOemStrings(IDS_OS_BUILD_TYPE, Msg)) printf(Msg, Buf);
134
135 //getting Registered Owner
136 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
137 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
138 TEXT("RegisteredOwner"),
139 Buf))
140 if (GetOemStrings(IDS_REG_OWNER, Msg)) printf(Msg, Buf);
141
142 //getting Registered Organization
143 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
144 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
145 TEXT("RegisteredOrganization"),
146 Buf))
147 if (GetOemStrings(IDS_REG_ORG, Msg)) printf(Msg, Buf);
148
149 //getting Product ID // use SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate
150 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
151 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
152 TEXT("ProductId"),
153 Buf))
154 if (GetOemStrings(IDS_PRODUCT_ID, Msg)) printf(Msg, Buf);
155
156 //getting Install Date
157 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
158 TEXT("SOFTWARE\\Microsoft\\WBEM\\CIMOM"),
159 TEXT("SetupDate"),
160 Buf))
161 if (GetOemStrings(IDS_INST_DATE, Msg)) printf(Msg, Buf);
162
163 //getting Install Time
164 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
165 TEXT("SOFTWARE\\Microsoft\\WBEM\\CIMOM"),
166 TEXT("SetupTime"),
167 Buf))
168 if (GetOemStrings(IDS_INST_TIME, Msg)) printf(Msg, Buf);
169
170 //getting System Up Time
171 cSeconds = GetTickCount() / 1000;
172 if (GetOemStrings(IDS_UP_TIME, Msg))
173 printf(Msg, cSeconds / (60*60*24), (cSeconds / (60*60)) % 24, (cSeconds / 60) % 60, cSeconds % 60);
174
175 //getting System Manufacturer
176 sprintf(Tmp, "%s\\oeminfo.ini", szSystemDir);
177 GetPrivateProfileString(TEXT("General"),
178 TEXT("Manufacturer"),
179 TEXT("To Be Filled By O.E.M."),
180 Buf,
181 sizeof(Buf)/sizeof(Buf[0]),
182 Tmp);
183 if (GetOemStrings(IDS_SYS_MANUFACTURER, Msg))
184 printf(Msg, Buf);
185
186 //getting System Model
187 GetPrivateProfileString(TEXT("General"),
188 TEXT("Model"),
189 TEXT("To Be Filled By O.E.M."),
190 Buf,
191 sizeof(Buf)/sizeof(Buf[0]),
192 Tmp);
193 if (GetOemStrings(IDS_SYS_MODEL, Msg))
194 printf(Msg, Buf);
195
196 //getting System type
197 switch (SysInfo.wProcessorArchitecture)
198 {
199 case PROCESSOR_ARCHITECTURE_UNKNOWN:
200 if (GetOemStrings(IDS_SYS_TYPE_UNKNOWN, Msg)) printf("%s", Msg);
201 break;
202 case PROCESSOR_ARCHITECTURE_INTEL:
203 if (GetOemStrings(IDS_SYS_TYPE_X86, Msg)) printf("%s", Msg);
204 break;
205 case PROCESSOR_ARCHITECTURE_IA64:
206 if (GetOemStrings(IDS_SYS_TYPE_IA64, Msg)) printf("%s", Msg);
207 break;
208 case PROCESSOR_ARCHITECTURE_AMD64:
209 if (GetOemStrings(IDS_SYS_TYPE_AMD64, Msg)) printf("%s", Msg);
210 break;
211 }
212
213 //getting Processor(s)
214 if (GetOemStrings(IDS_PROCESSORS, Msg))
215 {
216 unsigned int i;
217 printf(Msg, (unsigned int)SysInfo.dwNumberOfProcessors);
218 for(i = 0; i < (unsigned int)SysInfo.dwNumberOfProcessors; i++)
219 {
220 sprintf(Tmp,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%u",i);
221 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
222 (LPCTSTR)Tmp,
223 TEXT("Identifier"),
224 Buf))
225 printf(" [0%u]: %s", i+1, Buf);
226 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
227 (LPCTSTR)Tmp,
228 TEXT("VendorIdentifier"),
229 Buf))
230 printf(" %s\n", Buf);
231 }
232 }
233
234 //getting BIOS Version
235 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
236 TEXT("HARDWARE\\DESCRIPTION\\System"),
237 TEXT("SystemBiosVersion"),
238 Buf))
239 if (GetOemStrings(IDS_BIOS_VERSION, Msg)) printf(Msg, Buf);
240
241 //gettings BIOS date
242 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
243 TEXT("HARDWARE\\DESCRIPTION\\System"),
244 TEXT("SystemBiosDate"),
245 Buf))
246 if (GetOemStrings(IDS_BIOS_DATE, Msg)) printf(Msg, Buf);
247
248 //getting ReactOS Directory
249 if (!GetWindowsDirectory(Buf, BUFFER_SIZE)) printf("Error getting: GetWindowsDirectory");
250 if (GetOemStrings(IDS_ROS_DIR, Msg)) printf(Msg, Buf);
251
252 //getting System Directory
253 if (GetOemStrings(IDS_SYS_DIR, Msg)) printf(Msg, szSystemDir);
254
255 //getting Boot Device
256 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
257 TEXT("SYSTEM\\Setup"),
258 TEXT("SystemPartition"),
259 Buf))
260 if (GetOemStrings(IDS_BOOT_DEV, Msg)) printf(Msg, Buf);
261
262 //getting System Locale
263 if (GetRegistryValue(HKEY_CURRENT_USER,
264 TEXT("Control Panel\\International"),
265 TEXT("Locale"),
266 Tmp))
267 if (GetRegistryValue(HKEY_CLASSES_ROOT,
268 TEXT("MIME\\Database\\Rfc1766"),
269 (LPTSTR)Tmp,
270 Buf))
271 if (GetOemStrings(IDS_SYS_LOCALE, Msg)) printf(Msg, Buf);
272
273 //getting Input Locale
274 if (GetRegistryValue(HKEY_CURRENT_USER,
275 TEXT("Keyboard Layout\\Preload"),
276 TEXT("1"),
277 Buf))
278 {
279 int i,j;
280 for(j = 0, i = 4; i <= 8; j++, i++) Tmp[j] = Buf[i];
281 if (GetRegistryValue(HKEY_CLASSES_ROOT,
282 TEXT("MIME\\Database\\Rfc1766"),
283 (LPTSTR)Tmp,
284 Buf))
285 if (GetOemStrings(IDS_INPUT_LOCALE, Msg)) printf(Msg, Buf);
286 }
287
288 //getting Time Zone
289 GetTimeZoneInformation(&TimeZoneInfo);
290 sprintf(Tmp,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%S",TimeZoneInfo.StandardName);
291 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
292 (LPCTSTR)Tmp,
293 TEXT("Display"),
294 Buf))
295 if (GetOemStrings(IDS_TIME_ZONE, Msg)) printf(Msg, Buf);
296
297 //getting Total Physical Memory
298 GlobalMemoryStatus(&MemoryStatus);
299 if(GetOemStrings(IDS_TOTAL_PHYS_MEM, Msg))
300 printf(Msg,
301 B_TO_MB(MemoryStatus.dwTotalPhys),
302 B_TO_KB(MemoryStatus.dwTotalPhys));
303
304 //getting Available Physical Memory
305 if(GetOemStrings(IDS_AVAIL_PHISICAL_MEM,Msg))
306 printf(Msg,
307 B_TO_MB(MemoryStatus.dwAvailPhys),
308 B_TO_KB(MemoryStatus.dwAvailPhys));
309
310 //getting Virtual Memory: Max Size
311 if(GetOemStrings(IDS_VIRT_MEM_MAX, Msg))
312 printf(Msg,
313 B_TO_MB(MemoryStatus.dwTotalVirtual),
314 B_TO_KB(MemoryStatus.dwTotalVirtual));
315
316 //getting Virtual Memory: Available
317 if(GetOemStrings(IDS_VIRT_MEM_AVAIL, Msg))
318 printf(Msg,
319 B_TO_MB(MemoryStatus.dwAvailVirtual),
320 B_TO_KB(MemoryStatus.dwAvailVirtual));
321
322 //getting Virtual Memory: In Use
323 if(GetOemStrings(IDS_VIRT_MEM_INUSE, Msg))
324 printf(Msg,
325 B_TO_MB(MemoryStatus.dwTotalVirtual-MemoryStatus.dwAvailVirtual),
326 B_TO_KB(MemoryStatus.dwTotalVirtual-MemoryStatus.dwAvailVirtual));
327
328 //getting Page File Location(s)
329 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
330 TEXT("SYSTEM\\ControlSet001\\Control\\Session Manager\\Memory Management"),
331 TEXT("PagingFiles"),
332 Buf))
333 {
334 int i;
335 for(i = 0; i < strlen((char*)Buf); i++)
336 {
337 if (Buf[i] == ' ')
338 {
339 Buf[i] = '\0';
340 break;
341 }
342 }
343 if(GetOemStrings(IDS_PAGEFILE_LOC, Msg)) printf(Msg, Buf);
344 }
345
346 //getting Domain
347 if (GetRegistryValue(HKEY_LOCAL_MACHINE,
348 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"),
349 TEXT("CachePrimaryDomain"),
350 Buf))
351 if(GetOemStrings(IDS_DOMINE, Msg)) printf(Msg, Buf);
352
353 //getting Logon Server
354
355 //getting NetWork Card(s)
356 if(GetOemStrings(IDS_NETWORK_CARDS, Msg))
357 {
358
359 }
360 }
361
362 /* Main program */
363 int
364 main(int argc, char *argv[])
365 {
366 if (argc > 1 && (!strcmp(argv[1], "/?") || !strcmp(argv[1], "-?")))
367 {
368 Usage();
369 return 0;
370 }
371 AllSysInfo();
372 return 0;
373 }