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.
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.
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.
16 /* Copyright (C) 2007, Dmitry Chapyshev <lentind@yandex.ru> */
17 /* Copyright (C) 2011, Rafal Harabien <rafalh1992@o2.pl> */
29 #define BUFFER_SIZE 32767
31 /* Load from resource and convert to OEM */
34 GetOemStrings(UINT rcID
, LPTSTR OutMsg
)
36 TCHAR Msg
[BUFFER_SIZE
];
38 if (LoadString(GetModuleHandle(NULL
), rcID
, (LPTSTR
)Msg
, BUFFER_SIZE
))
40 CharToOem(Msg
, OutMsg
);
46 /* Load data from registry */
49 RegGetSZ(HKEY hKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, LPTSTR Buf
)
51 DWORD dwBytes
= BUFFER_SIZE
*sizeof(TCHAR
), dwType
;
54 /* If SubKy is specified open it */
55 if (lpSubKey
&& RegOpenKeyEx(hKey
,
59 &hKey
) != ERROR_SUCCESS
)
61 //_tprintf("Warning! Cannot open %s. Last error: %lu.\n", lpSubKey, GetLastError());
65 if (RegQueryValueEx(hKey
,
70 &dwBytes
) != ERROR_SUCCESS
|| (dwType
!= REG_SZ
&& dwType
!= REG_MULTI_SZ
))
72 //_tprintf("Warning! Cannot query %s. Last error: %lu, type: %lu.\n", lpValueName, GetLastError(), dwType);
77 /* Close key if we opened it */
81 /* NULL-terminate string */
82 Buf
[min(BUFFER_SIZE
-1, dwBytes
/sizeof(TCHAR
))] = TEXT('\0');
89 RegGetDWORD(HKEY hKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, LPDWORD lpData
)
91 DWORD dwBytes
= sizeof(*lpData
), dwType
;
94 /* If SubKy is specified open it */
95 if (lpSubKey
&& RegOpenKeyEx(hKey
,
99 &hKey
) != ERROR_SUCCESS
)
104 if (RegQueryValueEx(hKey
,
109 &dwBytes
) != ERROR_SUCCESS
|| dwType
!= REG_DWORD
)
111 //_tprintf("Warning! Cannot query %s. Last err: %lu, type: %lu\n", lpValueName, GetLastError(), dwType);
116 /* Close key if we opened it */
125 FormatBytes(LPTSTR Buf
, unsigned cBytes
)
127 TCHAR szMB
[32], Tmp
[BUFFER_SIZE
];
130 itoa(cBytes
/ (1024*1024), szMB
, 10);
135 fmt
.lpDecimalSep
= TEXT("");
136 fmt
.lpThousandSep
= TEXT(" ");
137 fmt
.NegativeOrder
= 0;
138 if(!GetNumberFormat(LOCALE_SYSTEM_DEFAULT
, 0, szMB
, &fmt
, Tmp
, BUFFER_SIZE
))
139 printf("Error! GetNumberFormat failed.\n");
146 FormatDateTime(time_t Time
, LPTSTR lpBuf
)
148 unsigned cchBuf
= BUFFER_SIZE
, i
;
150 const struct tm
*lpTm
;
152 lpTm
= localtime(&Time
);
153 SysTime
.wYear
= (WORD
)(1900 + lpTm
->tm_year
);
154 SysTime
.wMonth
= (WORD
)(1 + lpTm
->tm_mon
);
155 SysTime
.wDayOfWeek
= (WORD
)lpTm
->tm_wday
;
156 SysTime
.wDay
= (WORD
)lpTm
->tm_mday
;
157 SysTime
.wHour
= (WORD
)lpTm
->tm_hour
;
158 SysTime
.wMinute
= (WORD
)lpTm
->tm_min
;
159 SysTime
.wSecond
= (WORD
)lpTm
->tm_sec
;
160 SysTime
.wMilliseconds
= 0;
162 i
= GetDateFormat(LOCALE_SYSTEM_DEFAULT
, 0, &SysTime
, NULL
, lpBuf
, cchBuf
);
164 --i
; /* don't count NULL character */
165 i
+= _stprintf(lpBuf
+ i
, TEXT(", "));
166 GetTimeFormat(LOCALE_SYSTEM_DEFAULT
, 0, &SysTime
, NULL
, lpBuf
+ i
, cchBuf
- i
);
174 TCHAR Buf
[BUFFER_SIZE
];
176 if(GetOemStrings(IDS_USAGE
, Buf
))
180 /* Print all system information */
184 DWORD dwCharCount
= BUFFER_SIZE
, dwTimestamp
;
185 OSVERSIONINFO VersionInfo
;
187 TCHAR Buf
[BUFFER_SIZE
], Tmp
[BUFFER_SIZE
], Msg
[BUFFER_SIZE
], szSystemDir
[MAX_PATH
];
188 const TCHAR
*lpcszSysType
;
189 MEMORYSTATUS MemoryStatus
;
190 unsigned int cSeconds
;
191 TIME_ZONE_INFORMATION TimeZoneInfo
;
194 if (!GetSystemDirectory(szSystemDir
, sizeof(szSystemDir
)/sizeof(szSystemDir
[0])))
196 _tprintf("Error! GetSystemDirectory failed.\n");
200 GetSystemInfo(&SysInfo
);
202 // getting computer name
203 dwCharCount
= BUFFER_SIZE
;
204 if (!GetComputerName(Buf
, &dwCharCount
))
205 _tprintf("Error! GetComputerName failed.\n");
206 else if (GetOemStrings(IDS_HOST_NAME
, Msg
))
209 // open CurrentVersion key
210 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
211 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
214 &hKey
) != ERROR_SUCCESS
)
216 _tprintf("Error! RegOpenKeyEx failed.\n");
221 RegGetSZ(hKey
, NULL
, TEXT("ProductName"), Buf
);
222 if (GetOemStrings(IDS_OS_NAME
, Msg
))
226 ZeroMemory(&VersionInfo
, sizeof(VersionInfo
));
227 VersionInfo
.dwOSVersionInfoSize
= sizeof(VersionInfo
);
228 GetVersionEx(&VersionInfo
);
230 if (GetOemStrings(IDS_OS_VERSION
, Msg
))
232 (unsigned)VersionInfo
.dwMajorVersion
,
233 (unsigned)VersionInfo
.dwMinorVersion
,
234 (unsigned)VersionInfo
.dwBuildNumber
,
235 VersionInfo
.szCSDVersion
,
236 (unsigned)VersionInfo
.dwBuildNumber
);
238 //getting OS Manufacturer
240 //getting OS Configuration
242 //getting OS Build Type
243 RegGetSZ(hKey
, NULL
, TEXT("CurrentType"), Buf
);
244 if (GetOemStrings(IDS_OS_BUILD_TYPE
, Msg
))
247 //getting Registered Owner
248 RegGetSZ(hKey
, NULL
, TEXT("RegisteredOwner"), Buf
);
249 if (GetOemStrings(IDS_REG_OWNER
, Msg
))
252 //getting Registered Organization
253 RegGetSZ(hKey
, NULL
, TEXT("RegisteredOrganization"), Buf
);
254 if (GetOemStrings(IDS_REG_ORG
, Msg
))
258 RegGetSZ(hKey
, NULL
, TEXT("ProductId"), Buf
);
259 if (GetOemStrings(IDS_PRODUCT_ID
, Msg
))
262 //getting Install Date
263 RegGetDWORD(hKey
, NULL
, TEXT("InstallDate"), &dwTimestamp
);
264 FormatDateTime((time_t)dwTimestamp
, Buf
);
265 if (GetOemStrings(IDS_INST_DATE
, Msg
))
268 // close Current Version key now
271 //getting System Up Time
272 cSeconds
= GetTickCount() / 1000;
273 if (GetOemStrings(IDS_UP_TIME
, Msg
))
274 _tprintf(Msg
, cSeconds
/ (60*60*24), (cSeconds
/ (60*60)) % 24, (cSeconds
/ 60) % 60, cSeconds
% 60);
276 //getting System Manufacturer; HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation\Manufacturer for Win >= 6.0
277 sprintf(Tmp
, "%s\\oeminfo.ini", szSystemDir
);
278 GetPrivateProfileString(TEXT("General"),
279 TEXT("Manufacturer"),
280 TEXT("To Be Filled By O.E.M."),
282 sizeof(Buf
)/sizeof(Buf
[0]),
284 if (GetOemStrings(IDS_SYS_MANUFACTURER
, Msg
))
287 //getting System Model; HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation\Model for Win >= 6.0
288 GetPrivateProfileString(TEXT("General"),
290 TEXT("To Be Filled By O.E.M."),
292 sizeof(Buf
)/sizeof(Buf
[0]),
294 if (GetOemStrings(IDS_SYS_MODEL
, Msg
))
297 //getting System type
298 switch (SysInfo
.wProcessorArchitecture
)
300 case PROCESSOR_ARCHITECTURE_INTEL
:
301 lpcszSysType
= TEXT("X86-based PC");
303 case PROCESSOR_ARCHITECTURE_IA64
:
304 lpcszSysType
= TEXT("IA64-based PC");
306 case PROCESSOR_ARCHITECTURE_AMD64
:
307 lpcszSysType
= TEXT("AMD64-based PC");
310 lpcszSysType
= TEXT("Unknown");
313 if (GetOemStrings(IDS_SYS_TYPE
, Msg
))
314 _tprintf(Msg
, lpcszSysType
);
316 //getting Processor(s)
317 if (GetOemStrings(IDS_PROCESSORS
, Msg
))
320 _tprintf(Msg
, (unsigned int)SysInfo
.dwNumberOfProcessors
);
321 for(i
= 0; i
< (unsigned int)SysInfo
.dwNumberOfProcessors
; i
++)
323 sprintf(Tmp
, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%u",i
);
325 RegGetSZ(HKEY_LOCAL_MACHINE
, Tmp
, TEXT("Identifier"), Buf
);
326 _tprintf(" [%02u]: %s", i
+1, Buf
);
328 RegGetSZ(HKEY_LOCAL_MACHINE
, Tmp
, TEXT("VendorIdentifier"), Buf
);
329 _tprintf(" %s\n", Buf
);
333 //getting BIOS Version
334 RegGetSZ(HKEY_LOCAL_MACHINE
,
335 TEXT("HARDWARE\\DESCRIPTION\\System"),
336 TEXT("SystemBiosVersion"),
338 if (GetOemStrings(IDS_BIOS_VERSION
, Msg
))
342 RegGetSZ(HKEY_LOCAL_MACHINE
,
343 TEXT("HARDWARE\\DESCRIPTION\\System"),
344 TEXT("SystemBiosDate"),
346 if (GetOemStrings(IDS_BIOS_DATE
, Msg
))
349 //getting ReactOS Directory
350 if (!GetWindowsDirectory(Buf
, BUFFER_SIZE
))
351 _tprintf("Error! GetWindowsDirectory failed.");
352 else if (GetOemStrings(IDS_ROS_DIR
, Msg
))
355 //getting System Directory
356 if (GetOemStrings(IDS_SYS_DIR
, Msg
))
357 _tprintf(Msg
, szSystemDir
);
359 //getting Boot Device
360 RegGetSZ(HKEY_LOCAL_MACHINE
,
361 TEXT("SYSTEM\\Setup"),
362 TEXT("SystemPartition"),
364 if (GetOemStrings(IDS_BOOT_DEV
, Msg
))
367 //getting System Locale
368 if (RegGetSZ(HKEY_CURRENT_USER
,
369 TEXT("Control Panel\\International"),
372 if (RegGetSZ(HKEY_CLASSES_ROOT
,
373 TEXT("MIME\\Database\\Rfc1766"),
376 if (GetOemStrings(IDS_SYS_LOCALE
, Msg
))
379 //getting Input Locale
380 if (RegGetSZ(HKEY_CURRENT_USER
,
381 TEXT("Keyboard Layout\\Preload"),
387 for(j
= 0, i
= 4; i
<= 8; j
++, i
++)
390 if (RegGetSZ(HKEY_CLASSES_ROOT
,
391 TEXT("MIME\\Database\\Rfc1766"),
394 if (GetOemStrings(IDS_INPUT_LOCALE
, Msg
))
399 GetTimeZoneInformation(&TimeZoneInfo
);
401 /* Open Time Zones key */
402 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
403 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"),
405 KEY_ENUMERATE_SUB_KEYS
|KEY_READ
,
406 &hKey
) == ERROR_SUCCESS
)
410 /* Find current timezone */
411 dwCharCount
= 256; // Windows seems to have a bug - it doesnt accept BUFFER_SIZE here
412 for(i
= 0; RegEnumKeyEx(hKey
, i
, Tmp
, &dwCharCount
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
; ++i
, dwCharCount
= 255)
415 RegGetSZ(hKey
, Tmp
, TEXT("Std"), Buf
);
417 if(!wcscmp(wBuf
, TimeZoneInfo
.StandardName
))
419 wchar_t wBuf
[BUFFER_SIZE
];
421 RegGetSZ(hKey
, Tmp
, TEXT("Std"), Buf
);
422 mbstowcs(wBuf
, Buf
, BUFFER_SIZE
);
424 if(!wcscmp(wBuf
, TimeZoneInfo
.StandardName
))
427 RegGetSZ(hKey
, Tmp
, TEXT("Display"), Buf
);
429 if (GetOemStrings(IDS_TIME_ZONE
, Msg
))
439 //getting Total Physical Memory
440 GlobalMemoryStatus(&MemoryStatus
);
441 FormatBytes(Buf
, MemoryStatus
.dwTotalPhys
);
442 if (GetOemStrings(IDS_TOTAL_PHYS_MEM
, Msg
))
445 //getting Available Physical Memory
446 FormatBytes(Buf
, MemoryStatus
.dwAvailPhys
);
447 if (GetOemStrings(IDS_AVAIL_PHISICAL_MEM
,Msg
))
450 //getting Virtual Memory: Max Size
451 FormatBytes(Buf
, MemoryStatus
.dwTotalVirtual
);
452 if (GetOemStrings(IDS_VIRT_MEM_MAX
, Msg
))
455 //getting Virtual Memory: Available
456 FormatBytes(Buf
, MemoryStatus
.dwAvailVirtual
);
457 if (GetOemStrings(IDS_VIRT_MEM_AVAIL
, Msg
))
460 //getting Virtual Memory: In Use
461 FormatBytes(Buf
, MemoryStatus
.dwTotalVirtual
-MemoryStatus
.dwAvailVirtual
);
462 if (GetOemStrings(IDS_VIRT_MEM_INUSE
, Msg
))
465 //getting Page File Location(s)
466 if (RegGetSZ(HKEY_LOCAL_MACHINE
,
467 TEXT("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
473 for(i
= 0; i
< strlen((char*)Buf
); i
++)
475 if (Buf
[i
] == TEXT(' '))
482 if(GetOemStrings(IDS_PAGEFILE_LOC
, Msg
))
487 if (RegGetSZ(HKEY_LOCAL_MACHINE
,
488 TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"),
489 TEXT("CachePrimaryDomain"),
491 if(GetOemStrings(IDS_DOMINE
, Msg
))
494 //getting Logon Server
496 //getting NetWork Card(s)
497 if(GetOemStrings(IDS_NETWORK_CARDS
, Msg
))
505 main(int argc
, char *argv
[])
507 if (argc
> 1 && (!strcmp(argv
[1], "/?") || !strcmp(argv
[1], "-?")))