#include #include #include #include #include #include TCHAR cName[MAX_COMPUTERNAME_LENGTH+1]; // computer name DWORD cLen = sizeof(cName); // length TCHAR uName[UNLEN+1]; // username DWORD uLen = sizeof(uName); // length TCHAR pAmount[4], sVer[5]; // processors count, OS version LPCWSTR pType, osName; // processor type, OS name SYSTEM_INFO sInfo; // system info struct OSVERSIONINFOEX osInfo; // OS version struct // processor name depends on wProcessorArchitecture void GetProcessorType() { pType = L"Unknown"; switch(sInfo.wProcessorArchitecture) { case PROCESSOR_ARCHITECTURE_AMD64: pType = L"AMD64"; break; case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64: pType = L"WOW64"; break; case PROCESSOR_ARCHITECTURE_IA64: pType = L"Itanium"; break; case PROCESSOR_ARCHITECTURE_INTEL: pType = L"x86"; break; default: break; } } // OS name depends on dwMajorVersion and dwMinorVersion void GetOSName() { osName = L"Unknown"; switch(osInfo.dwMajorVersion) { case 5: if (osInfo.dwMinorVersion == 0) osName = L"Windows 2000"; if (osInfo.dwMinorVersion == 1) osName = L"Windows XP"; if (osInfo.dwMinorVersion == 2) osName = L"Windows Server"; if (osInfo.dwMinorVersion == 2 && osInfo.wProductType == VER_NT_WORKSTATION && sInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) osName = L"Windows XP Professional x64 Edition"; break; case 6: if (osInfo.dwMinorVersion == 0) if (osInfo.wProductType == VER_NT_WORKSTATION) osName = L"Windows Vista"; else osName = L"Windows Server 2008"; if (osInfo.dwMinorVersion == 1) if (osInfo.wProductType == VER_NT_WORKSTATION) osName = L"Windows 7"; else osName = L"Windows Server 2008 R2"; if (osInfo.dwMinorVersion == 2) if (osInfo.wProductType == VER_NT_WORKSTATION) osName = L"Windows 8"; else osName = L"Windows Server 2012"; if (osInfo.dwMinorVersion == 3) if (osInfo.wProductType == VER_NT_WORKSTATION) osName = L"Windows 8.1 Preview"; else osName = L"Windows Server 2012 R2 Preview"; break; } } LONG WINAPI WndProc(HWND, UINT, WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; MSG msg; WNDCLASS w; memset(&w, 0, sizeof(WNDCLASS)); w.style = WS_TILED | CS_HREDRAW | CS_VREDRAW; w.lpfnWndProc = WndProc; w.hInstance = hInstance; w.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); w.lpszClassName = L"Lab1"; w.hIcon = LoadIcon(NULL, IDI_EXCLAMATION); RegisterClass(&w); hwnd = CreateWindow(L"Lab1", L"Petryakov 3120", WS_OVERLAPPEDWINDOW, 400, 400, 240, 160, NULL, NULL, hInstance, NULL); // get system info ZeroMemory(&sInfo, sizeof(SYSTEM_INFO)); GetSystemInfo(&sInfo); // format string StringCbPrintf(pAmount, sizeof(pAmount), L"%u", sInfo.dwNumberOfProcessors); // get processor type readable format GetProcessorType(); //get OS version ZeroMemory(&osInfo, sizeof(OSVERSIONINFOEX)); osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); GetVersionEx((OSVERSIONINFO*)&osInfo); // format full version string StringCbPrintf((LPWSTR)sVer, sizeof(sVer), L"%u.%u", osInfo.dwMajorVersion, osInfo.dwMinorVersion); // get readable version name string GetOSName(); GetComputerName(cName, &cLen); // get computer name in cName, cLen is length of max name / result length GetUserName(uName, &uLen); // get username like computer name ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LONG WINAPI WndProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam) { HDC hdc; PAINTSTRUCT ps; int start = 5; switch (Message){ case WM_DESTROY: PostQuitMessage(0); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 5, start, L"Processors:", 11); TextOut(hdc, 100, start, pAmount, wcslen(pAmount)); TextOut(hdc, 5, start+20, L"Type:", 5); TextOut(hdc, 100, start+20, pType, wcslen(pType)); TextOut(hdc, 5, start+40, L"OS Version:", 11); TextOut(hdc, 100, start+40, sVer, wcslen(sVer)); TextOut(hdc, 5, start+60, L"OS Name:", 8); TextOut(hdc, 100, start+60, osName, wcslen(osName)); TextOut(hdc, 5, start+80, L"Hostname:", 9); TextOut(hdc, 100, start+80, cName, cLen); TextOut(hdc, 5, start+100, L"Username:", 9); TextOut(hdc, 100, start+100, uName, uLen-1); EndPaint(hwnd, &ps); break; default: return DefWindowProc(hwnd, Message, wparam, lparam); } return 0; }