├── SystemInfo ├── resource.h ├── Icons │ ├── GPU.ico │ ├── RAM.ico │ ├── bios.ico │ ├── cpu.ico │ ├── mb.ico │ ├── os.ico │ ├── sound.ico │ ├── uptime.ico │ ├── mainIcon.ico │ ├── monitor.ico │ ├── network.ico │ ├── optical.ico │ ├── storage.ico │ └── utilization │ │ ├── utilization_0.ico │ │ ├── utilization_1.ico │ │ ├── utilization_2.ico │ │ ├── utilization_3.ico │ │ ├── utilization_4.ico │ │ └── utilization_5.ico ├── SystemInfo.aps ├── SystemInfo.rc ├── network │ ├── rest │ │ ├── rest.h │ │ └── rest.cpp │ └── common │ │ ├── network.h │ │ └── network.cpp ├── SystemInfo.vcxproj.user ├── dialog │ ├── aboutDialog.h │ ├── scrUploadDialog.h │ ├── aboutDialog.cpp │ └── scrUploadDialog.cpp ├── import │ ├── binImport.h │ └── binImport.cpp ├── core │ ├── WMIWBEMINFO.cpp │ ├── SystemInfo.h │ ├── SystemInfo.cpp │ ├── sysinfo.h │ ├── WMIWBEMINFO.h │ └── sysinfo.cpp ├── logger │ ├── logger.cpp │ └── logger.h ├── const │ ├── appconst.h │ ├── iconLabelIDs.h │ └── itemIDs.h ├── export │ ├── screenCapture.h │ ├── saveSpecs.h │ ├── screenCapture.cpp │ └── saveSpecs.cpp ├── WMIWBEMINFO.cpp ├── meta │ ├── SoftwareInfo.h │ └── SoftwareInfo.cpp ├── SystemInfo.manifest ├── mainWindowProcedure.h ├── SMBIOS.h ├── SMBIOS.cpp ├── glb │ ├── globalVars.cpp │ └── globalVars.h ├── util │ ├── controlManager.h │ ├── controlManager.cpp │ ├── utility.h │ └── utility.cpp ├── main.cpp ├── pugi │ └── pugiconfig.hpp ├── WMIWBEMINFO.h ├── SystemInfo.vcxproj.filters ├── SystemInfo.vcxproj ├── LICENSE └── mainWindowProcedure.cpp ├── .gitignore ├── SystemInfo.sln └── README.md /SystemInfo/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/resource.h -------------------------------------------------------------------------------- /SystemInfo/Icons/GPU.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/GPU.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/RAM.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/RAM.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/bios.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/bios.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/cpu.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/cpu.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/mb.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/mb.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/os.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/os.ico -------------------------------------------------------------------------------- /SystemInfo/SystemInfo.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/SystemInfo.aps -------------------------------------------------------------------------------- /SystemInfo/SystemInfo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/SystemInfo.rc -------------------------------------------------------------------------------- /SystemInfo/Icons/sound.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/sound.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/uptime.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/uptime.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/mainIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/mainIcon.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/monitor.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/monitor.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/network.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/network.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/optical.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/optical.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/storage.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/storage.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/utilization/utilization_0.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/utilization/utilization_0.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/utilization/utilization_1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/utilization/utilization_1.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/utilization/utilization_2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/utilization/utilization_2.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/utilization/utilization_3.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/utilization/utilization_3.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/utilization/utilization_4.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/utilization/utilization_4.ico -------------------------------------------------------------------------------- /SystemInfo/Icons/utilization/utilization_5.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryPill/system_info/HEAD/SystemInfo/Icons/utilization/utilization_5.ico -------------------------------------------------------------------------------- /SystemInfo/network/rest/rest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "../../util/utility.h" 5 | bool uploadImage(RESULT_STRUCT*, TCHAR*); 6 | -------------------------------------------------------------------------------- /SystemInfo/SystemInfo.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SystemInfo/dialog/aboutDialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "../glb/globalVars.h" 6 | #include "../resource.h" 7 | BOOL CALLBACK aboutDlgProc(HWND, UINT, WPARAM, LPARAM); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Dd]ebug/ 2 | [Dd]ebugPublic/ 3 | [Rr]elease/ 4 | [Rr]eleases/ 5 | x64/ 6 | x86/ 7 | bld/ 8 | [Bb]in/ 9 | [Oo]bj/ 10 | [Ll]og/ 11 | *.VC.db 12 | *.VC.VC.opendb 13 | **/*.sdf 14 | packages/ 15 | *.vcxproj 16 | *.vcxproj.filters 17 | *.suo 18 | .vs/ -------------------------------------------------------------------------------- /SystemInfo/import/binImport.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../pugi/pugixml.hpp" 7 | #include "../core/SystemInfo.h" 8 | #include "../glb/globalVars.h" 9 | void importData(SystemInfo*); -------------------------------------------------------------------------------- /SystemInfo/core/WMIWBEMINFO.cpp: -------------------------------------------------------------------------------- 1 | #include "WMIWBEMINFO.h" 2 | 3 | 4 | 5 | WMIWBEMINFO* WMIWBEMINFO::getWMIWBEMInfoInstance() { 6 | if (!currentInstance) { 7 | currentInstance = new WMIWBEMINFO(); 8 | } 9 | return currentInstance; 10 | } 11 | 12 | WMIWBEMINFO::~WMIWBEMINFO() 13 | { 14 | } 15 | -------------------------------------------------------------------------------- /SystemInfo/logger/logger.cpp: -------------------------------------------------------------------------------- 1 | #include "logger.h" 2 | 3 | SimpleLogger* SimpleLogger::loggerInstance; 4 | SimpleLogger* SimpleLogger::getLoggerInstance() { 5 | if (loggerInstance == nullptr) { 6 | loggerInstance = new SimpleLogger(); 7 | } 8 | return loggerInstance; 9 | } 10 | 11 | void SimpleLogger::info() { 12 | 13 | } 14 | 15 | void SimpleLogger::error() { 16 | 17 | } 18 | 19 | void SimpleLogger::debug() { 20 | 21 | } -------------------------------------------------------------------------------- /SystemInfo/const/appconst.h: -------------------------------------------------------------------------------- 1 | #ifndef APPCONST_H 2 | #define APPCONST_H 3 | #define STR_MAX 256 4 | #define ITEM_WIDTH 150 5 | #define ITEM_HEIGHT 40 6 | #define ITEM_INFO_WIDTH 1000 7 | #define ITEM_INFO_HEIGHT 60 8 | #define ITEM_INFO_INITIAL_HEIGTH 15 9 | #define ITEM_ICON_SIZE 16 10 | #define ITEM_UTIL_ICON_RENDER_SIZE_WIDTH 12 11 | #define ITEM_UTIL_ICON_RENDER_SIZE_HEIGHT 14 12 | #define MOUSE_WHEEL_SCROLL 120 13 | #endif -------------------------------------------------------------------------------- /SystemInfo/const/iconLabelIDs.h: -------------------------------------------------------------------------------- 1 | #ifndef ICONLABELIDS_H 2 | #define ICONLABELIDS_H 3 | #define BIOS_ICON_LABEL 60 4 | #define OS_ICON_LABEL 61 5 | #define CPU_ICON_LABEL 62 6 | #define RAM_ICON_LABEL 63 7 | #define MB_ICON_LABEL 64 8 | #define VIDEO_ICON_LABEL 65 9 | #define DISPLAY_ICON_LABEL 66 10 | #define STORAGE_ICON_LABEL 67 11 | #define OPTICAL_ICON_LABEL 68 12 | #define NETWORK_ICON_LABEL 69 13 | #define AUDIO_ICON_LABEL 70 14 | #define UPTIME_ICON_LABEL 71 15 | #endif -------------------------------------------------------------------------------- /SystemInfo/dialog/scrUploadDialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "../glb/globalVars.h" 6 | #include "../resource.h" 7 | typedef struct UPLOAD_SRC_LINK_DATA { 8 | TCHAR link[256]; 9 | }; 10 | extern UPLOAD_SRC_LINK_DATA uploadSrcLinkData; 11 | BOOL CALLBACK scrDlgProc(HWND, UINT, WPARAM, LPARAM); 12 | LRESULT CALLBACK editCtrlProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); 13 | bool copyLinkToClipboard(); 14 | -------------------------------------------------------------------------------- /SystemInfo/export/screenCapture.h: -------------------------------------------------------------------------------- 1 | #ifndef SCREENCAPTURE_H 2 | #define SCREENCAPTURE_H 3 | #include 4 | #include 5 | #include "../util/utility.h" 6 | typedef struct VisibleAreaCoordsStruct { 7 | INT32 visibleAreaWidth; 8 | INT32 visibleAreaHeight; 9 | }; 10 | ACTION takeScreenshot(HWND, SCR_SAVETYPE, RESULT_STRUCT*); 11 | Gdiplus::Bitmap* getBitmapFromAreaCoords(HWND hwnd, VisibleAreaCoordsStruct&); 12 | VisibleAreaCoordsStruct getVisibleClientArea(HWND hwnd); 13 | Gdiplus::Bitmap* mergeBitmaps( std::vector, INT32); 14 | 15 | #endif // !SCREENCAPTURE_H 16 | -------------------------------------------------------------------------------- /SystemInfo/WMIWBEMINFO.cpp: -------------------------------------------------------------------------------- 1 | #include "WMIWBEMINFO.h" 2 | 3 | 4 | WMIWBEMINFO* WMIWBEMINFO::currentInstance; 5 | 6 | WMIWBEMINFO* WMIWBEMINFO::getWMIWBEMINFOInstance() { 7 | if (currentInstance == nullptr) { 8 | currentInstance = new WMIWBEMINFO(); 9 | } 10 | return currentInstance; 11 | } 12 | 13 | IWbemLocator* WMIWBEMINFO::getWbemLocator() { 14 | return this->pLoc; 15 | } 16 | 17 | IWbemServices* WMIWBEMINFO::getWbemServices() { 18 | return this->pSvc; 19 | } 20 | 21 | HRESULT WMIWBEMINFO::getHres() { 22 | return this->hres; 23 | } 24 | 25 | WMIWBEMINFO::~WMIWBEMINFO() { 26 | this->pSvc->Release(); 27 | this->pLoc->Release(); 28 | CoUninitialize(); 29 | } 30 | -------------------------------------------------------------------------------- /SystemInfo/logger/logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | class SimpleLogger { 6 | private: 7 | static SimpleLogger*loggerInstance; 8 | std::wofstream outLoggerStream; 9 | TCHAR *hardCodedLoggerOutFilePath = L""; 10 | SimpleLogger() { 11 | std::locale loc(std::locale::classic(), new std::codecvt_utf8); 12 | outLoggerStream.open(hardCodedLoggerOutFilePath, std::wofstream::out); 13 | outLoggerStream.imbue(loc); //todo create configAppData directory on application startup 14 | } 15 | public: 16 | static SimpleLogger *getLoggerInstance(); 17 | static void info(); 18 | static void error(); 19 | static void debug(); 20 | 21 | }; -------------------------------------------------------------------------------- /SystemInfo/meta/SoftwareInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../const/appconst.h" 7 | using namespace std; 8 | class SoftwareInfo { 9 | private: 10 | TCHAR softwareName[STR_MAX]; 11 | TCHAR softwareDescription[STR_MAX]; 12 | TCHAR softwareVersion[STR_MAX]; 13 | TCHAR softwareRepo[STR_MAX]; 14 | 15 | public: 16 | SoftwareInfo(); 17 | ~SoftwareInfo(); 18 | TCHAR* getSoftwareName(); 19 | TCHAR* getSoftwareDesc(); 20 | TCHAR* getSoftwareVer(); 21 | TCHAR* getSoftwareRepo(); 22 | void setSoftwareDesc(TCHAR*); 23 | void setSoftwareVer(TCHAR*); 24 | void setSoftwareRepo(TCHAR*); 25 | void setSoftwareName(TCHAR*); 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /SystemInfo/SystemInfo.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | Hardware information tool for Windows 10 | 11 | 12 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /SystemInfo/network/common/network.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "../../core/SystemInfo.h" 5 | using namespace std; 6 | class SystemInfo; 7 | //also used as a place holder for the external internet address (ipv4) 8 | class NetAdapter { 9 | private: 10 | wstring adapterDesc; 11 | wstring adapterAddr; 12 | wstring adapterGW; 13 | wstring adapterType; 14 | 15 | public: 16 | NetAdapter() {} 17 | void setAdapterType(wstring); 18 | void setAdapterDesc(wstring); 19 | void setAdapterAdr(wstring); 20 | void setAdapterGW(wstring); 21 | wstring getAdapterType(void); 22 | wstring getAdapterDesc(void); 23 | wstring getAdapterAdr(void); 24 | wstring getAdapterGW(void); 25 | }; 26 | void fillNetworkAdapters(SystemInfo*); 27 | int getIpAddress(char *ipBuff); 28 | -------------------------------------------------------------------------------- /SystemInfo/export/saveSpecs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../core/SystemInfo.h" 3 | #include 4 | #include "../util/utility.h" 5 | class saveSpecs { 6 | private: 7 | static const TCHAR *xmlDTD; 8 | static const TCHAR *htmlStartPoint; 9 | static const TCHAR *uniformComment; 10 | static const TCHAR *htmlCommentStart; 11 | static const TCHAR *htmlCommentEnd; 12 | static const TCHAR *CSSCommentStart; 13 | static const TCHAR *CSSCommentEnd; 14 | public: 15 | static ACTION saveAsXML(HWND, SystemInfo*, RESULT_STRUCT*); 16 | static ACTION saveAsHTML(HWND, SystemInfo*, RESULT_STRUCT*); 17 | static ACTION saveAsText(HWND, SystemInfo*, RESULT_STRUCT*); 18 | static ACTION save(WORD command, 19 | RESULT_STRUCT *res, 20 | HWND hwnd, 21 | SystemInfo *localMachine); 22 | saveSpecs(); 23 | ~saveSpecs(); 24 | }; 25 | void importAsXML(HWND); 26 | -------------------------------------------------------------------------------- /SystemInfo/mainWindowProcedure.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "core/SystemInfo.h" 3 | #ifndef MAINWINDOWPROCEDURE_H 4 | #define MAINWINDOWPROCEDURE_H 5 | LRESULT CALLBACK mainWindowProc(HWND, UINT, WPARAM, LPARAM); 6 | BOOL CALLBACK SetFont(HWND child, LPARAM font); 7 | void createHardwareInfoHolders(HWND, SystemInfo*, int); 8 | void populateInfoHolders(SystemInfo *machine, HWND); 9 | void createIPToggleControl(HWND, int, int); 10 | void createCpuUtilizationInfoHolder(HWND, int, int); 11 | void loadImages(void); 12 | void toggleIpAddress(HWND, SystemInfo*); 13 | void updateNetworkAdaptersView(SystemInfo*); 14 | unsigned int __stdcall updateUptime(void*); 15 | unsigned int __stdcall updateCpuUtilizationPercentage(void*); 16 | unsigned int __stdcall playLoadTextAnimation(void*); 17 | void scrollClientWindow(HWND hwnd, int bar, int pos); 18 | void fillGUI(HWND hwnd, SystemInfo *localMachine, int); 19 | #endif -------------------------------------------------------------------------------- /SystemInfo/SMBIOS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | typedef struct _RawSMBIOSData { 5 | BYTE Used20CallingMethod; 6 | BYTE SMBIOSMajorVersion; 7 | BYTE SMBIOSMinorVersion; 8 | BYTE DmiRevision; 9 | DWORD Length; 10 | PBYTE SMBIOSTableData; 11 | } RawSMBIOSData, *PRawSMBIOSData; 12 | typedef struct _SMBIOSHEADER_ { 13 | BYTE Type; 14 | BYTE Length; 15 | WORD Handle; 16 | } SMBIOSHEADER, *PSMBIOSHEADER; 17 | typedef struct _TYPE_0_ { 18 | SMBIOSHEADER Header; 19 | UCHAR Vendor; 20 | UCHAR Version; 21 | UINT16 StartingAddrSeg; 22 | UCHAR ReleaseDate; 23 | UCHAR ROMSize; 24 | ULONG64 Characteristics; 25 | UCHAR Extension[2]; // spec. 2.3 26 | UCHAR MajorRelease; 27 | UCHAR MinorRelease; 28 | UCHAR ECFirmwareMajor; 29 | UCHAR ECFirmwareMinor; 30 | } BIOSInfo, *PBIOSInfo; 31 | void DumpSMBIOSStruct(void *, UINT, TCHAR*); 32 | const char* LocateStringA(const char* str, UINT i); 33 | const char* toPointString(void* p); 34 | const wchar_t* LocateStringW(const char* str, UINT i); -------------------------------------------------------------------------------- /SystemInfo/const/itemIDs.h: -------------------------------------------------------------------------------- 1 | #ifndef ITEMIDS_H 2 | #define ITEMIDS_H 3 | #define SNAPSHOT_LABEL -1 4 | #define BIOS_LABEL 0 5 | #define OS_LABEL 1 6 | #define CPU_LABEL 2 7 | #define MB_LABEL 3 8 | #define RAM_LABEL 4 9 | #define GPU_LABEL 5 10 | #define MONITOR_LABEL 6 11 | #define STORAGE_LABEL 7 12 | #define OPTICAL_LABEL 8 13 | #define NETWORK_LABEL 9 14 | #define AUDIO_LABEL 10 15 | #define UPTIME_LABEL 11 16 | #define BIOS_INFO 12 17 | #define OS_INFO 13 18 | #define CPU_INFO 14 19 | #define MB_INFO 15 20 | #define RAM_INFO 16 21 | #define GPU_INFO 17 22 | #define MONITOR_INFO 18 23 | #define STORAGE_INFO 19 24 | #define OPTICAL_INFO 20 25 | #define NETWORK_INFO 21 26 | #define AUDIO_INFO 22 27 | #define UPTIME_INFO 23 28 | #define END_INFO 24 29 | 30 | #define AUX_IP_TOGGLE 720 31 | #define AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_ICON 820 32 | #define AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_STRING 920 33 | 34 | 35 | #define INFO_ID_OFFSET 12 36 | #define ICON_ID_OFFSET 60 37 | #endif -------------------------------------------------------------------------------- /SystemInfo/SMBIOS.cpp: -------------------------------------------------------------------------------- 1 | #include "atlstr.h" 2 | #include "SMBIOS.h" 3 | void DumpSMBIOSStruct(void *Addr, UINT Len, TCHAR *outData) { 4 | LPBYTE p = (LPBYTE)(Addr); 5 | const DWORD lastAddress = ((DWORD)p) + Len; 6 | PSMBIOSHEADER pHeader; 7 | pHeader = (PSMBIOSHEADER)p; 8 | PBIOSInfo pBIOS = (PBIOSInfo)p; 9 | const char *str = toPointString(p); 10 | TCHAR *biosVendor = (TCHAR*)LocateStringW(str, pBIOS->Vendor); 11 | _tcscpy(outData, biosVendor); 12 | TCHAR *biosVersion = (TCHAR*)LocateStringW(str, pBIOS->Version); 13 | _tcscat(outData, _T(" v.")); 14 | _tcscat(outData, biosVersion); 15 | } 16 | const char* toPointString(void* p) { 17 | return (char*)p + ((PSMBIOSHEADER)p)->Length; 18 | } 19 | const wchar_t* LocateStringW(const char* str, UINT i) { 20 | static wchar_t buff[2048]; 21 | const char *pStr = LocateStringA(str, i); 22 | SecureZeroMemory(buff, sizeof(buff)); 23 | MultiByteToWideChar(CP_UTF8, 0, pStr, strlen(pStr), buff, sizeof(buff)); 24 | return buff; 25 | } 26 | const char* LocateStringA(const char* str, UINT i) { 27 | static const char strNull[] = "Null String"; 28 | if (0 == i || 0 == *str) return strNull; 29 | while (--i) { 30 | str += strlen((char*)str) + 1; 31 | } 32 | return str; 33 | } -------------------------------------------------------------------------------- /SystemInfo/meta/SoftwareInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "../meta/SoftwareInfo.h" 2 | 3 | SoftwareInfo *shippedSoftWare; 4 | SoftwareInfo::SoftwareInfo() { 5 | this->setSoftwareName(_T("SystemInfo")); 6 | this->setSoftwareDesc(_T("Hardware information tool for Windows")); 7 | this->setSoftwareRepo(_T("https://github.com/CherryPill/system_info")); 8 | this->setSoftwareVer(_T("1.4.3 [32-bit]")); 9 | } 10 | 11 | SoftwareInfo::~SoftwareInfo() {} 12 | 13 | TCHAR* SoftwareInfo::getSoftwareName() { 14 | return this->softwareName; 15 | } 16 | 17 | TCHAR* SoftwareInfo::getSoftwareDesc() { 18 | return this->softwareDescription; 19 | } 20 | 21 | TCHAR* SoftwareInfo::getSoftwareVer() { 22 | return this->softwareVersion; 23 | } 24 | 25 | TCHAR* SoftwareInfo::getSoftwareRepo() { 26 | return this->softwareRepo; 27 | } 28 | 29 | void SoftwareInfo::setSoftwareDesc(TCHAR* desc) { 30 | _tcscpy(this->softwareDescription, desc); 31 | } 32 | 33 | void SoftwareInfo::setSoftwareVer(TCHAR* ver) { 34 | _tcscpy(this->softwareVersion, ver); 35 | } 36 | 37 | void SoftwareInfo::setSoftwareRepo(TCHAR* repo) { 38 | _tcscpy(this->softwareRepo, repo); 39 | } 40 | 41 | void SoftwareInfo::setSoftwareName(TCHAR* name) { 42 | _tcscpy(this->softwareName, name); 43 | } 44 | -------------------------------------------------------------------------------- /SystemInfo/glb/globalVars.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "globalVars.h" 6 | 7 | HINSTANCE ghInstance = NULL; 8 | HWND mainWindowHwnd = NULL; 9 | int PROGRAM_INSTANCE = 0; 10 | TCHAR PROGRAM_DATA_IMPORT_LOCATION[256] = { 0 }; 11 | TCHAR execName[256] = { 0 }; 12 | int mainWindowWidth = 600; 13 | int mainWindowHeight = 660; //default 660 14 | int scrollY = 0; 15 | int scrollFullPageHeight = 0; 16 | WNDPROC lpfnScrEditProc; 17 | HBRUSH grayBrush = CreateSolidBrush(RGB(81, 81, 81)); 18 | TCHAR *fontFamilies[] = { 19 | _T("Arial"), 20 | _T("Courier New") 21 | }; 22 | HFONT appNameFontLarge = CreateFont(-28, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, fontFamilies[0]); 23 | HFONT ipToggleBtnFont = CreateFont(-10, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, fontFamilies[0]); 24 | 25 | TCHAR *timeVerboseMonths[] = { 26 | _T("Dummy"), 27 | _T("January"), 28 | _T("February"), 29 | _T("March"), 30 | _T("April"), 31 | _T("May"), 32 | _T("June"), 33 | _T("July"), 34 | _T("August"), 35 | _T("September"), 36 | _T("October"), 37 | _T("November"), 38 | _T("December") 39 | }; 40 | TCHAR *timeVerboseDaysOfWeek[] = { 41 | _T("Sunday"), 42 | _T("Monday"), 43 | _T("Tuesday"), 44 | _T("Wednesday"), 45 | _T("Thursday"), 46 | _T("Friday"), 47 | _T("Saturday") 48 | }; 49 | 50 | TCHAR sysInfoConfigDirectoryPath[256] = {}; 51 | 52 | int currentCpuUsageGlobal = -1; 53 | 54 | 55 | int glbCpuInfoHolderXoffset = 0; 56 | int glbCpuInfoHolderYoffset = 0; 57 | 58 | 59 | -------------------------------------------------------------------------------- /SystemInfo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28729.10 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SystemInfo", "SystemInfo\SystemInfo.vcxproj", "{48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{00560159-1600-41C9-BB56-BE1CE22C58BD}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Debug|x64.ActiveCfg = Debug|x64 19 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Debug|x64.Build.0 = Debug|x64 20 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Debug|x86.ActiveCfg = Debug|Win32 21 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Debug|x86.Build.0 = Debug|Win32 22 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Release|x64.ActiveCfg = Release|x64 23 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Release|x64.Build.0 = Release|x64 24 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Release|x86.ActiveCfg = Release|Win32 25 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8}.Release|x86.Build.0 = Release|Win32 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ExtensibilityGlobals) = postSolution 31 | SolutionGuid = {FFE214F5-3A0B-49A3-94D5-978ECFDCA264} 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SystemInfo - a hardware information tool for Windows 2 | 3 | SystemInfo enables you to view information about the hardware components of your computer. 4 |

5 | 6 |

7 |
8 | 9 | The program allows you to take screenshots of the client area and export hardware information in the following formats: 10 | - HTML (with CSS) 11 | - XML 12 | - Simple text 13 | 14 | Supports the following operating systems: 15 | - Windows Vista (x86/x64) 16 | - Windows 7 (x86/x64) 17 | - Windows 8/8.1 (x86/x64) 18 | - Windows 10 (x86/x64) 19 | 20 | 21 | Might also work on modern Windows Server systems, but I didn't test it. 22 | 23 | The program is written in C/C++ and uses barebones WindowsAPI for its GUI. 24 | 25 | This program is free software. 26 | 27 | Download 28 | 29 | ### Like the software? Consider donating and I may actually have some time to get back to the project. 30 | 31 | ## BTC: bc1qsmv62jym9rqppklmvgv5xkkq2luyjr9jl4ckq0 32 | *** 33 | 34 | DISCLAIMER: THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | -------------------------------------------------------------------------------- /SystemInfo/dialog/aboutDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "aboutDialog.h" 2 | #include "../util/utility.h" 3 | 4 | BOOL CALLBACK aboutDlgProc(HWND dlgHandle, UINT message, WPARAM wParam, LPARAM lParam) { 5 | switch (message) { 6 | case WM_NOTIFY: { 7 | switch (((LPNMHDR)lParam)->code) { 8 | case NM_CLICK: 9 | case NM_RETURN: { 10 | PNMLINK pNMLink = (PNMLINK)lParam; 11 | LITEM item = pNMLink->item; 12 | if ((((LPNMHDR)lParam)->hwndFrom == GetDlgItem(dlgHandle, IDC_GITHUB)) && (item.iLink == 0)) { 13 | ShellExecute(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); 14 | } 15 | break; 16 | } 17 | } 18 | break; 19 | } 20 | case WM_INITDIALOG: { 21 | SendDlgItemMessage(dlgHandle, IDC_STATIC_ICON, STM_SETICON, (WPARAM)(HICON)LoadImage(ghInstance, MAKEINTRESOURCE(MAIN_APP_ICON), IMAGE_ICON, 64, 64, NULL), NULL); 22 | DWORD buffSize = 256; 23 | TCHAR inputBuff[256]; 24 | ZeroMemory(inputBuff, sizeof(inputBuff)); 25 | SetWindowText(GetDlgItem(dlgHandle, IDC_PROGRAM_NAME), (LPCWSTR)shippedSoftWare->getSoftwareName()); 26 | SetWindowText(GetDlgItem(dlgHandle, IDC_PROGRAM_VER), (LPCWSTR)shippedSoftWare->getSoftwareVer()); 27 | SetWindowText(GetDlgItem(dlgHandle, IDC_PROGRAM_DESC), (LPCWSTR)shippedSoftWare->getSoftwareDesc()); 28 | SetWindowText(GetDlgItem(dlgHandle, IDC_GITHUB), (LPCWSTR)shippedSoftWare->getSoftwareRepo()); 29 | SendMessage(GetDlgItem(dlgHandle, IDC_PROGRAM_NAME), WM_SETFONT, (WPARAM)appNameFontLarge, MAKELPARAM(true, 0)); 30 | ZeroMemory(inputBuff, sizeof(inputBuff)); 31 | return true; 32 | } 33 | case WM_COMMAND: { 34 | switch (LOWORD(wParam)) { 35 | case ID_ABOUT_OK: { 36 | EndDialog(dlgHandle, 0); 37 | return true; 38 | } 39 | } 40 | break; 41 | } 42 | case WM_CLOSE: { 43 | EndDialog(dlgHandle, 0); 44 | return true; 45 | } 46 | } 47 | return false; 48 | } -------------------------------------------------------------------------------- /SystemInfo/dialog/scrUploadDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "scrUploadDialog.h" 2 | #include "../util/utility.h" 3 | #include "../glb/globalVars.h" 4 | #include "../util/controlManager.h" 5 | 6 | UPLOAD_SRC_LINK_DATA uploadSrcLinkData = {}; 7 | BOOL CALLBACK scrDlgProc(HWND dlgHandle, UINT message, WPARAM wParam, LPARAM lParam) { 8 | switch (message) { 9 | case WM_INITDIALOG: { 10 | SendMessage(GetDlgItem(dlgHandle, IDC_PROGRAM_NAME), WM_SETFONT, (WPARAM)appNameFontLarge, MAKELPARAM(true, 0)); 11 | SetWindowText(GetDlgItem(dlgHandle, IDC_EDIT_SCRCOPY), (LPCWSTR)uploadSrcLinkData.link); 12 | lpfnScrEditProc = (WNDPROC)SetWindowLong(GetDlgItem(dlgHandle, IDC_EDIT_SCRCOPY), 13 | GWL_WNDPROC, (DWORD)editCtrlProc); 14 | return true; 15 | } 16 | case WM_COMMAND: { 17 | switch (LOWORD(wParam)) { 18 | case ID_SCRUPLOAD_OK: 19 | case ID_SRCUPLOAD_CANCEL: { 20 | EndDialog(dlgHandle, 0); 21 | return true; 22 | } 23 | } 24 | break; 25 | } 26 | case WM_CLOSE: { 27 | EndDialog(dlgHandle, 0); 28 | return true; 29 | } 30 | } 31 | return false; 32 | } 33 | 34 | LRESULT CALLBACK editCtrlProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { 35 | switch (msg) { 36 | case WM_LBUTTONDOWN: { 37 | SetWindowText(GetDlgItem(GetParent(hwnd), IDC_STATIC_SCRCOPYDONE), 38 | copyLinkToClipboard() ? 39 | ControlManager::UI_messagesTxt[2].c_str() : 40 | ControlManager::UI_messagesTxt[3].c_str()); 41 | break; 42 | } 43 | } 44 | return CallWindowProc(lpfnScrEditProc, hwnd, msg, wParam, lParam); 45 | } 46 | 47 | bool copyLinkToClipboard() { 48 | const size_t linkLen = _tcslen(uploadSrcLinkData.link) * sizeof(TCHAR) + 1; 49 | HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, linkLen); 50 | memcpy(GlobalLock(hMem), uploadSrcLinkData.link, linkLen); 51 | GlobalUnlock(hMem); 52 | if (OpenClipboard(mainWindowHwnd)) { 53 | EmptyClipboard(); 54 | SetClipboardData(CF_UNICODETEXT, hMem); 55 | CloseClipboard(); 56 | return true; 57 | } else { 58 | return false; 59 | } 60 | } -------------------------------------------------------------------------------- /SystemInfo/core/SystemInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../network/common/network.h" 8 | #include "../const/appconst.h" 9 | using namespace std; 10 | class NetAdapter; 11 | class SystemInfo { 12 | private: 13 | SystemInfo() { 14 | this->BIOS = L"BIOS not detected"; 15 | this->OS = L"OS not detected"; 16 | this->RAM = L"RAM not detected"; 17 | this->MB = L"Motherboard not detected"; 18 | this->CPU = L"CPU not detected"; 19 | this->audio = L"Sound card not detected"; 20 | this->uptime = L"Uptime not set"; 21 | } 22 | wstring BIOS; 23 | wstring OS; 24 | wstring CPU; 25 | wstring MB; 26 | wstring RAM; 27 | vector GPUDevices; 28 | vector storageMediums; 29 | vector displayDevices; 30 | vector CDROMDevices; 31 | vector networkAdapters; 32 | vector networkAdaptersText; 33 | wstring audio; 34 | wstring uptime; 35 | wstring snapshotGenDateTime; 36 | 37 | public: 38 | static SystemInfo *getCurrentInstance() { 39 | static SystemInfo *currentInstance = new SystemInfo(); 40 | return currentInstance; 41 | } 42 | 43 | vector getCDROMDevices(void); 44 | wstring getBIOS(void); 45 | wstring getUptime(void); 46 | wstring getCPU(void); 47 | wstring getRAM(void); 48 | wstring getMB(void); 49 | wstring getAudio(void); 50 | vector getGPUDevices(void); 51 | vector getStorageMediums(void); 52 | vector getDisplayDevices(void); 53 | vector getNetworkAdapters(void); 54 | vector getNetworkAdaptersText(void); 55 | vector& getNetworkAdaptersTextRef(void) { 56 | return this->networkAdaptersText; 57 | } 58 | wstring getOS(void); 59 | wstring getSnapshotGenDateTime(); 60 | void setBIOS(wstring bios); 61 | void setUptime(wstring uptime); 62 | void setCPU(wstring CPU); 63 | void setRAM(wstring RAM); 64 | void setMB(wstring MB); 65 | void addDisplayDevice(wstring device); 66 | void addStorageMedium(wstring medium); 67 | void addNetworkAdapter(NetAdapter adapter); 68 | void addNetworkAdapterText(wstring adapter); 69 | void addGPUDevice(wstring device); 70 | void setOS(wstring OS); 71 | void setAudio(wstring audio); 72 | void addCDROMDevice(wstring CDROM); 73 | void setSnapshotGenDateTime(wstring dt); 74 | }; 75 | -------------------------------------------------------------------------------- /SystemInfo/util/controlManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "../glb/globalVars.h" 6 | class ControlManager { 7 | public: 8 | 9 | const static wstring UI_messagesTxt[]; 10 | 11 | enum class UI_MESS_RES_ICON { 12 | SUCCESS = MB_ICONINFORMATION, //info 13 | FAILURE = MB_ICONERROR, //error 14 | WARN = MB_ICONWARNING, 15 | QUESTION = MB_ICONQUESTION 16 | }; 17 | 18 | enum class UI_MESS_EXPORT_ACTION { 19 | WRITE_OUT_TXT = ID_EXPORT_TXT, 20 | WRITE_OUT_XML = ID_EXPORT_XML, 21 | WRITE_OUT_HTML = ID_EXPORT_HTML, 22 | WRITE_OUT_IMG = ID_FILE_TAKESCREENSHOT_SAVE_LOCALLY 23 | }; 24 | 25 | enum class UI_MESS_TYPE { 26 | GENERIC, 27 | EXPORT 28 | }; 29 | 30 | const static unordered_map messageCodeCaptionsMap; 31 | 32 | const static unordered_map > UIMessageExportFileExtByUserExportModeCommandMap; 33 | 34 | static HWND appCreateControl( 35 | TCHAR* className, 36 | int xOffset, 37 | int yOffSet, 38 | int width, 39 | int height, 40 | std::bitset<32> windowStyles, 41 | HWND parent, 42 | int controlMenuID, 43 | TCHAR* windowName = NULL, 44 | DWORD exStyle = 0, 45 | HINSTANCE hInstance = NULL, 46 | LPVOID lParam = NULL); 47 | 48 | static bool searchAndDestroy( 49 | HWND parentWindowHandle, 50 | TCHAR *className, 51 | TCHAR *windowName); 52 | }; 53 | 54 | class AbstractMessage { 55 | protected: 56 | wstring message; 57 | ControlManager::UI_MESS_RES_ICON icon; 58 | public: 59 | virtual UINT display() = 0; 60 | AbstractMessage *withMessage(const wstring message) { 61 | this->message.assign(message); 62 | return this; 63 | } 64 | AbstractMessage* withIcon(ControlManager::UI_MESS_RES_ICON icon) { 65 | this->icon = icon; 66 | return this; 67 | } 68 | }; 69 | 70 | class GenericMessageOK : public AbstractMessage { 71 | public: 72 | UINT display() { 73 | return MessageBox( 74 | mainWindowHwnd, 75 | this->message.c_str(), 76 | ControlManager::messageCodeCaptionsMap.at(this->icon).c_str(), 77 | MB_OK | static_cast(this->icon)); 78 | } 79 | }; 80 | 81 | class PromptMessageYesNo : public AbstractMessage { 82 | public: 83 | UINT display() { 84 | return MessageBox( 85 | NULL, 86 | this->message.c_str(), 87 | ControlManager::messageCodeCaptionsMap.at(this->icon).c_str(), 88 | MB_YESNO | static_cast(this->icon)); 89 | } 90 | }; -------------------------------------------------------------------------------- /SystemInfo/util/controlManager.cpp: -------------------------------------------------------------------------------- 1 | #include "controlManager.h" 2 | #include "utility.h" 3 | 4 | const wstring ControlManager::UI_messagesTxt[] = { 5 | L"Successfully written to ", 6 | L"Error writing to ", 7 | L"Link successfully copied to clipboard", 8 | L"There's been a problem copying link to clipboard" 9 | }; 10 | 11 | const unordered_map ControlManager::messageCodeCaptionsMap = 12 | { 13 | {ControlManager::UI_MESS_RES_ICON::SUCCESS, L"Success"}, 14 | {ControlManager::UI_MESS_RES_ICON::QUESTION, L"User action required"}, 15 | {ControlManager::UI_MESS_RES_ICON::WARN, L"Warning"}, 16 | {ControlManager::UI_MESS_RES_ICON::FAILURE, L"Error" } 17 | }; 18 | 19 | const unordered_map > ControlManager::UIMessageExportFileExtByUserExportModeCommandMap = 20 | { 21 | {ControlManager::UI_MESS_EXPORT_ACTION::WRITE_OUT_HTML, 22 | {L".html", L".html files (*.html)\0*.html\0"}}, 23 | {ControlManager::UI_MESS_EXPORT_ACTION::WRITE_OUT_IMG, 24 | {L".png", L".png images (*.png)\0*.png\0"}}, 25 | {ControlManager::UI_MESS_EXPORT_ACTION::WRITE_OUT_TXT, 26 | {L".txt", L".txt files (*.txt)\0*.txt\0"}}, 27 | {ControlManager::UI_MESS_EXPORT_ACTION::WRITE_OUT_XML, 28 | {L".xml", L".xml files (*.xml)\0*.xml\0"}} 29 | }; 30 | 31 | HWND ControlManager::appCreateControl( 32 | TCHAR *className, 33 | int xOffset, 34 | int yOffSet, 35 | int width, 36 | int height, 37 | std::bitset<32> windowStyles, 38 | HWND parent, 39 | int controlMenuID, 40 | TCHAR* windowName, 41 | DWORD exStyle, 42 | HINSTANCE hInstance, 43 | LPVOID lParam 44 | ) { 45 | HWND createdWindow = CreateWindowEx( 46 | 0, 47 | className, 48 | windowName, 49 | windowStyles.to_ulong(), 50 | xOffset, 51 | yOffSet, 52 | width, 53 | height, 54 | parent, 55 | (HMENU)controlMenuID, 56 | hInstance, 57 | lParam 58 | ); 59 | if (!createdWindow) { 60 | DWORD errCode = GetLastError(); 61 | GenericMessageOK() 62 | .withMessage(getSystemErrorCodeMessageForErrorCode(errCode)) 63 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 64 | ->display(); 65 | } 66 | return createdWindow; 67 | } 68 | 69 | bool ControlManager::searchAndDestroy( 70 | HWND parentWindowHandle, 71 | TCHAR *className, 72 | TCHAR *windowName) { 73 | HWND foundWindowHandle = NULL; 74 | if ((foundWindowHandle = FindWindowEx(NULL, NULL, className, windowName)) != NULL) { 75 | return DestroyWindow(foundWindowHandle); 76 | } 77 | return false; 78 | } -------------------------------------------------------------------------------- /SystemInfo/import/binImport.cpp: -------------------------------------------------------------------------------- 1 | #include "../util/utility.h" 2 | #include "../import/binImport.h" 3 | #include "../util/controlManager.h" 4 | void importData(SystemInfo* snapshotInstance) { 5 | pugi::xml_document doc; 6 | pugi::xml_parse_result res = doc.load_file(PROGRAM_DATA_IMPORT_LOCATION); 7 | if (res) { 8 | pugi::xml_node items = doc.child(L"hardwareinfo"); 9 | pugi::xml_node itemInner; 10 | for (pugi::xml_node item = items.first_child(); item; item = item.next_sibling()) { 11 | wstring attrValue = item.first_attribute().value(); 12 | wstring itemValue = item.first_child().value(); 13 | trimWhiteSpace(itemValue); 14 | if (attrValue == L"BIOS/UEFI") { 15 | snapshotInstance->setBIOS(itemValue); 16 | } else if (attrValue == L"Operating System") { 17 | snapshotInstance->setOS(itemValue); 18 | } else if (attrValue == L"CPU") { 19 | snapshotInstance->setCPU(itemValue); 20 | } else if (attrValue == L"Motherboard") { 21 | snapshotInstance->setMB(itemValue); 22 | } else if (attrValue == L"RAM") { 23 | snapshotInstance->setRAM(itemValue); 24 | } else if (attrValue == L"Sound") { 25 | snapshotInstance->setAudio(itemValue); 26 | } else if (attrValue == L"Uptime") { 27 | snapshotInstance->setUptime(itemValue); 28 | } else if (attrValue == L"GPU") { 29 | for (pugi::xml_node subitem : item.children()) { 30 | snapshotInstance->addGPUDevice(subitem.first_child().value()); 31 | } 32 | } else if (attrValue == L"Display") { 33 | for (pugi::xml_node subitem : item.children()) { 34 | snapshotInstance->addDisplayDevice(subitem.first_child().value()); 35 | } 36 | } else if (attrValue == L"Storage") { 37 | for (pugi::xml_node subitem : item.children()) { 38 | snapshotInstance->addStorageMedium(subitem.first_child().value()); 39 | } 40 | } else if (attrValue == L"Optical drives") { 41 | for (pugi::xml_node subitem : item.children()) { 42 | snapshotInstance->addCDROMDevice(subitem.first_child().value()); 43 | } 44 | } else if (attrValue == L"Network and Connections") { 45 | for (pugi::xml_node subitem : item.children()) { 46 | snapshotInstance->addNetworkAdapterText(subitem.first_child().value()); 47 | } 48 | } else if (attrValue == L"Snapshot") { 49 | snapshotInstance->setSnapshotGenDateTime(itemValue); 50 | } 51 | } 52 | } else { 53 | GenericMessageOK() 54 | .withMessage(L"Unable to parse XML file") 55 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 56 | ->display(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /SystemInfo/main.cpp: -------------------------------------------------------------------------------- 1 | #define ISOLATION_AWARE_ENABLED 1 2 | #include 3 | #include "resource.h" 4 | #include "glb/globalVars.h" 5 | #include "util/utility.h" 6 | #include "mainWindowProcedure.h" 7 | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 8 | LPSTR lpCmdLine, int nCmdShow) { 9 | int argc; 10 | //if argcount > 1 then a snapshot is being loaded 11 | LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); 12 | TCHAR fullExecPath[256] = { 0 }; 13 | GetModuleFileName(NULL, fullExecPath, 256); 14 | getFileNameFromPath(fullExecPath, execName); 15 | _tcscat(execName, L" "); 16 | configAppData(); 17 | if (argc > 1) { 18 | PROGRAM_INSTANCE = 1; 19 | _tcscpy(PROGRAM_DATA_IMPORT_LOCATION, argv[1]); 20 | } 21 | #ifdef _DEBUG 22 | for (int x = 0; x < argc; x++) 23 | MessageBox(NULL, argv[x], _T("arg"), MB_OK); 24 | #endif 25 | LocalFree(argv); 26 | shippedSoftWare = new SoftwareInfo(); 27 | MSG message; 28 | WNDCLASSEX wc = { 0 }; //nullifying the struct 29 | wc.cbSize = sizeof(wc); 30 | wc.style = CS_HREDRAW | CS_VREDRAW; 31 | wc.cbClsExtra = 0; 32 | wc.cbWndExtra = 0; 33 | wc.lpszClassName = L"sysinfo"; 34 | wc.hInstance = hInstance; 35 | wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); 36 | wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); 37 | wc.lpfnWndProc = mainWindowProc; 38 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 39 | wc.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(MAIN_APP_ICON), IMAGE_ICON, 0, 0, NULL); 40 | wc.hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(MAIN_APP_ICON), IMAGE_ICON, 32, 32, NULL); 41 | if (!RegisterClassEx(&wc)) { 42 | GenericMessageOK() 43 | .withMessage(L"Window class registration failed") 44 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 45 | ->display(); 46 | return FALSE; 47 | } 48 | ghInstance = hInstance; 49 | POINT upperLeftCorner; 50 | positionWindow(&upperLeftCorner); 51 | //centerWindow(&upperLeftCorner); 52 | mainWindowHwnd = CreateWindowEx 53 | ( 54 | 0, 55 | wc.lpszClassName, 56 | PROGRAM_INSTANCE ? L"SystemInfo (snapshot)" : L"SystemInfo", 57 | WS_SYSMENU | WS_OVERLAPPEDWINDOW, 58 | upperLeftCorner.x, 59 | upperLeftCorner.y, 60 | mainWindowWidth, 61 | mainWindowHeight, 62 | NULL, 63 | NULL, 64 | hInstance, 65 | NULL 66 | ); 67 | SetClassLongPtr(mainWindowHwnd, GCLP_HBRBACKGROUND, (LONG)grayBrush); 68 | ShowWindow(mainWindowHwnd, nCmdShow); 69 | UpdateWindow(mainWindowHwnd); 70 | while (GetMessage(&message, NULL, 0, 0)) { 71 | TranslateMessage(&message); 72 | DispatchMessage(&message); 73 | } 74 | return (int)(message.wParam); 75 | } -------------------------------------------------------------------------------- /SystemInfo/core/SystemInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "SystemInfo.h" 2 | #pragma comment (lib,"Gdiplus.lib") 3 | wstring SystemInfo::getCPU() { 4 | return (*this).CPU; 5 | } 6 | 7 | wstring SystemInfo::getRAM() { 8 | return (*this).RAM; 9 | } 10 | 11 | void SystemInfo::setMB(wstring MB) { 12 | (*this).MB = MB; 13 | } 14 | 15 | wstring SystemInfo::getMB() { 16 | return (*this).MB; 17 | } 18 | 19 | vector SystemInfo::getGPUDevices() { 20 | return (*this).GPUDevices; 21 | } 22 | 23 | vector SystemInfo::getStorageMediums() { 24 | return (*this).storageMediums; 25 | } 26 | 27 | vector SystemInfo::getDisplayDevices() { 28 | return (*this).displayDevices; 29 | } 30 | 31 | void SystemInfo::addDisplayDevice(wstring device) { 32 | (*this).displayDevices.push_back(device); 33 | } 34 | 35 | void SystemInfo::addStorageMedium(wstring medium) { 36 | (*this).storageMediums.push_back(medium); 37 | } 38 | 39 | void SystemInfo::addNetworkAdapter(NetAdapter adapter) { 40 | (*this).networkAdapters.push_back(adapter); 41 | } 42 | 43 | void SystemInfo::addNetworkAdapterText(wstring adapter) { 44 | (*this).networkAdaptersText.push_back(adapter); 45 | } 46 | 47 | vector SystemInfo::getNetworkAdaptersText() { 48 | return (*this).networkAdaptersText; 49 | } 50 | 51 | void SystemInfo::addGPUDevice(wstring device) { 52 | (*this).GPUDevices.push_back(device); 53 | } 54 | 55 | wstring SystemInfo::getOS() { 56 | return (*this).OS; 57 | } 58 | 59 | void SystemInfo::setCPU(wstring CPU) { 60 | (*this).CPU = CPU; 61 | } 62 | 63 | void SystemInfo::setRAM(wstring RAM) { 64 | (*this).RAM = RAM; 65 | } 66 | 67 | void SystemInfo::setOS(wstring OS) { 68 | (*this).OS = OS; 69 | } 70 | 71 | vector SystemInfo::getCDROMDevices(void) { 72 | return (*this).CDROMDevices; 73 | } 74 | 75 | void SystemInfo::addCDROMDevice(wstring CDROM) { 76 | (*this).CDROMDevices.push_back(CDROM); 77 | } 78 | 79 | void SystemInfo::setAudio(wstring audio) { 80 | (*this).audio = audio; 81 | } 82 | 83 | wstring SystemInfo::getAudio(void) { 84 | return (*this).audio; 85 | } 86 | 87 | wstring SystemInfo::getUptime(void) { 88 | return (*this).uptime; 89 | } 90 | 91 | void SystemInfo::setUptime(wstring uptime) { 92 | (*this).uptime = uptime; 93 | } 94 | 95 | wstring SystemInfo::getBIOS(void) { 96 | return (*this).BIOS; 97 | } 98 | 99 | void SystemInfo::setBIOS(wstring bios) { 100 | (*this).BIOS = bios; 101 | } 102 | 103 | vector SystemInfo::getNetworkAdapters(void) { 104 | return (*this).networkAdapters; 105 | } 106 | 107 | void SystemInfo::setSnapshotGenDateTime(wstring snapshotGenDateTime) { 108 | (*this).snapshotGenDateTime = snapshotGenDateTime; 109 | } 110 | 111 | wstring SystemInfo::getSnapshotGenDateTime(void) { 112 | return (*this).snapshotGenDateTime; 113 | } 114 | -------------------------------------------------------------------------------- /SystemInfo/pugi/pugiconfig.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * pugixml parser - version 1.8 3 | * -------------------------------------------------------- 4 | * Copyright (C) 2006-2016, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) 5 | * Report bugs and download new versions at http://pugixml.org/ 6 | * 7 | * This library is distributed under the MIT License. See notice at the end 8 | * of this file. 9 | * 10 | * This work is based on the pugxml parser, which is: 11 | * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) 12 | */ 13 | 14 | #ifndef HEADER_PUGICONFIG_HPP 15 | #define HEADER_PUGICONFIG_HPP 16 | 17 | // Uncomment this to enable wchar_t mode 18 | #define PUGIXML_WCHAR_MODE 19 | 20 | // Uncomment this to enable compact mode 21 | // #define PUGIXML_COMPACT 22 | 23 | // Uncomment this to disable XPath 24 | // #define PUGIXML_NO_XPATH 25 | 26 | // Uncomment this to disable STL 27 | // #define PUGIXML_NO_STL 28 | 29 | // Uncomment this to disable exceptions 30 | // #define PUGIXML_NO_EXCEPTIONS 31 | 32 | // Set this to control attributes for public classes/functions, i.e.: 33 | // #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL 34 | // #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL 35 | // #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall 36 | // In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead 37 | 38 | // Tune these constants to adjust memory-related behavior 39 | // #define PUGIXML_MEMORY_PAGE_SIZE 32768 40 | // #define PUGIXML_MEMORY_OUTPUT_STACK 10240 41 | // #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096 42 | 43 | // Uncomment this to switch to header-only version 44 | // #define PUGIXML_HEADER_ONLY 45 | 46 | // Uncomment this to enable long long support 47 | // #define PUGIXML_HAS_LONG_LONG 48 | 49 | #endif 50 | 51 | /** 52 | * Copyright (c) 2006-2016 Arseny Kapoulkine 53 | * 54 | * Permission is hereby granted, free of charge, to any person 55 | * obtaining a copy of this software and associated documentation 56 | * files (the "Software"), to deal in the Software without 57 | * restriction, including without limitation the rights to use, 58 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 59 | * copies of the Software, and to permit persons to whom the 60 | * Software is furnished to do so, subject to the following 61 | * conditions: 62 | * 63 | * The above copyright notice and this permission notice shall be 64 | * included in all copies or substantial portions of the Software. 65 | * 66 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 67 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 68 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 69 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 70 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 71 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 72 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 73 | * OTHER DEALINGS IN THE SOFTWARE. 74 | */ 75 | -------------------------------------------------------------------------------- /SystemInfo/core/sysinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSINFOSTRUCT_H 2 | #define SYSINFOSTRUCT_H 3 | #include 4 | #include 5 | #include 6 | #include "../const/appconst.h" 7 | #include "../core/SystemInfo.h" 8 | using namespace std; 9 | 10 | enum class WMI_OS { 11 | NAME, 12 | ARCHITECTURE 13 | }; 14 | 15 | enum class WMI_CPU { 16 | NAME, 17 | MAXCLOCK, 18 | SOCKET_DESIGNATION 19 | }; 20 | 21 | enum class WMI_RAM { 22 | CAPACITY, 23 | FORMFACTOR, 24 | MEMTYPE, 25 | SPEED 26 | }; 27 | 28 | enum class WMI_MB { 29 | MANUFACTURER, 30 | PRODUCT 31 | }; 32 | enum class WMI_GPU { 33 | ADAPTER_RAM, 34 | NAME 35 | }; 36 | enum class WMI_MONITOR { 37 | NAME 38 | }; 39 | enum class WMI_DISPLAYCONFIG { 40 | NAME 41 | }; 42 | enum class WMI_DISKDRIVE { 43 | CAPTION, 44 | SIZE 45 | }; 46 | enum class WMI_OPTICALDISK { 47 | CAPTION 48 | }; 49 | enum class WMI_SOUND { 50 | CAPTION 51 | }; 52 | 53 | enum class WMI_CPU_PERF { 54 | PROC_TIME_PERCENTAGE 55 | }; 56 | static unordered_map > wmiClassStringsMap = { 57 | { L"Win32_OperatingSystem", {L"Name", L"OSArchitecture"}}, 58 | { L"Win32_Processor", { L"Name", L"MaxClockSpeed", L"SocketDesignation"} }, 59 | { L"Win32_BaseBoard",{ L"Manufacturer", L"Product" } }, 60 | { L"Win32_PhysicalMemory", { L"Capacity", L"FormFactor", L"MemoryType", L"Speed" } }, 61 | { L"Win32_VideoController", { L"AdapterRAM", L"Name" } }, 62 | { L"Win32_DesktopMonitor", { L"Name"} }, 63 | { L"Win32_DisplayConfiguration", { L"DisplayFrequency"} }, 64 | { L"Win32_DiskDrive", { L"Caption", L"Size" } }, 65 | { L"Win32_CDROMDrive", { L"Caption" } }, 66 | { L"Win32_SoundDevice", { L"Caption"} }, 67 | { L"Win32_PerfFormattedData_PerfOS_Processor", { L"PercentProcessorTime"} } 68 | 69 | }; 70 | int fillSystemInformation(SystemInfo *localMachine); 71 | int test(); 72 | void fillCPUTemp(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 73 | //hardware 74 | wstring getComputerType(void); 75 | void fillBIOS(SystemInfo *localMachine); 76 | void fillOS(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 77 | void fillCPU(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 78 | void fillMB(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 79 | void fillRAM(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 80 | void fillGPU(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 81 | void fillMonitor(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 82 | void fillStorage(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 83 | void fillCDROM(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 84 | void fillAudio(SystemInfo *localMachine, HRESULT hres, IWbemServices *pSvc, IWbemLocator *pLoc); 85 | void fillNetworkAdapters(SystemInfo *localMachine); 86 | void fillUptime(SystemInfo *localMachine); 87 | void fillDimensionsAndFrequency(HRESULT, IWbemServices*, IWbemLocator*, UINT*); 88 | wstring getSocket(HRESULT, IWbemServices*, IWbemLocator*); 89 | unsigned int getCpuUsagePercentage(void); 90 | IEnumWbemClassObject* executeWQLQuery(HRESULT hres, IWbemLocator *pLoc, IWbemServices *pSvc, BSTR stringQuery); 91 | bstr_t buildQueryString(const wchar_t *wmiClass, vector attrs); 92 | bstr_t buildQueryString(const wchar_t* wmiClass, vector attrs, const wchar_t *whereClause); 93 | 94 | wstring getRamBySlot(HRESULT hres, IWbemServices*, IWbemLocator*, const vector&); 95 | #endif -------------------------------------------------------------------------------- /SystemInfo/WMIWBEMINFO.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | class WMIWBEMINFO 8 | { 9 | private: 10 | static WMIWBEMINFO* currentInstance; 11 | HRESULT hres; 12 | IWbemServices* pSvc; 13 | IWbemLocator* pLoc; 14 | WMIWBEMINFO() { 15 | 16 | // Step 1: -------------------------------------------------- 17 | // Initialize COM. ------------------------------------------ 18 | 19 | hres = CoInitializeEx(0, COINIT_MULTITHREADED); 20 | if (FAILED(hres)) { 21 | throw std::exception("Failed to initialize COM library"); 22 | } 23 | 24 | // Step 2: -------------------------------------------------- 25 | // Set general COM security levels -------------------------- 26 | 27 | hres = CoInitializeSecurity( 28 | NULL, 29 | -1, // COM authentication 30 | NULL, // Authentication services 31 | NULL, // Reserved 32 | RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication 33 | RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation 34 | NULL, // Authentication info 35 | EOAC_NONE, // Additional capabilities 36 | NULL // Reserved 37 | ); 38 | 39 | 40 | if (FAILED(hres)) { 41 | CoUninitialize(); 42 | throw std::exception("Failed to initialize COM security levels"); 43 | } 44 | 45 | //obtain the initial locator to WMI 46 | 47 | this->pLoc = NULL; 48 | 49 | hres = CoCreateInstance( 50 | CLSID_WbemLocator, 51 | 0, 52 | CLSCTX_INPROC_SERVER, 53 | IID_IWbemLocator, (LPVOID*)& pLoc); 54 | 55 | if (FAILED(hres)) { 56 | CoUninitialize(); 57 | throw std::exception("Failed to create IWbemLocator object"); 58 | } 59 | 60 | // Step 4: ----------------------------------------------------- 61 | // Connect to WMI through the IWbemLocator::ConnectServer method 62 | 63 | this->pSvc = NULL; 64 | 65 | // Connect to the root\cimv2 namespace with 66 | // the current user and obtain pointer pSvc 67 | // to make IWbemServices calls. 68 | hres = pLoc->ConnectServer( 69 | _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace 70 | NULL, // User name. NULL = current user 71 | NULL, // User password. NULL = current 72 | 0, // Locale. NULL indicates current 73 | NULL, // Security flags. 74 | 0, // Authority (for example, Kerberos) 75 | 0, // Context object 76 | &pSvc // pointer to IWbemServices proxy 77 | ); 78 | 79 | if (FAILED(hres)) { 80 | pLoc->Release(); 81 | CoUninitialize(); 82 | throw std::exception("Could not connect to root/cimv2 namespace"); 83 | } 84 | 85 | 86 | // Step 5: -------------------------------------------------- 87 | // Set security levels on the proxy ------------------------- 88 | 89 | hres = CoSetProxyBlanket( 90 | pSvc, // Indicates the proxy to set 91 | RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx 92 | RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx 93 | NULL, // Server principal name 94 | RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx 95 | RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx 96 | NULL, // client identity 97 | EOAC_NONE // proxy capabilities 98 | ); 99 | 100 | if (FAILED(hres)) { 101 | pSvc->Release(); 102 | pLoc->Release(); 103 | CoUninitialize(); 104 | throw std::exception("Could not set proxy blanket"); 105 | } 106 | } 107 | 108 | public: 109 | static WMIWBEMINFO* getWMIWBEMINFOInstance(); 110 | IWbemLocator *getWbemLocator(); 111 | IWbemServices* getWbemServices(); 112 | HRESULT getHres(); 113 | ~WMIWBEMINFO(); 114 | }; 115 | 116 | -------------------------------------------------------------------------------- /SystemInfo/core/WMIWBEMINFO.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | class WMIWBEMINFO 8 | { 9 | private: 10 | static WMIWBEMINFO* currentInstance; 11 | HRESULT hres; 12 | IWbemServices* pSvc; 13 | IWbemLocator* pLoc; 14 | WMIWBEMINFO() { 15 | HRESULT hres; 16 | 17 | // Step 1: -------------------------------------------------- 18 | // Initialize COM. ------------------------------------------ 19 | 20 | this->hres = CoInitializeEx(0, COINIT_MULTITHREADED); 21 | if (FAILED(hres)) { 22 | throw std::exception("Failed to initialize COM library"); 23 | } 24 | 25 | // Step 2: -------------------------------------------------- 26 | // Set general COM security levels -------------------------- 27 | 28 | hres = CoInitializeSecurity( 29 | NULL, 30 | -1, // COM authentication 31 | NULL, // Authentication services 32 | NULL, // Reserved 33 | RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication 34 | RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation 35 | NULL, // Authentication info 36 | EOAC_NONE, // Additional capabilities 37 | NULL // Reserved 38 | ); 39 | 40 | 41 | if (FAILED(hres)) { 42 | CoUninitialize(); 43 | throw std::exception("Failed to initialize COM security levels"); 44 | } 45 | 46 | //obtain the initial locator to WMI 47 | 48 | this->pLoc = NULL; 49 | 50 | hres = CoCreateInstance( 51 | CLSID_WbemLocator, 52 | 0, 53 | CLSCTX_INPROC_SERVER, 54 | IID_IWbemLocator, (LPVOID*)& pLoc); 55 | 56 | if (FAILED(hres)) { 57 | CoUninitialize(); 58 | throw std::exception("Failed to create IWbemLocator object"); 59 | } 60 | 61 | // Step 4: ----------------------------------------------------- 62 | // Connect to WMI through the IWbemLocator::ConnectServer method 63 | 64 | this->pSvc = NULL; 65 | 66 | // Connect to the root\cimv2 namespace with 67 | // the current user and obtain pointer pSvc 68 | // to make IWbemServices calls. 69 | hres = pLoc->ConnectServer( 70 | _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace 71 | NULL, // User name. NULL = current user 72 | NULL, // User password. NULL = current 73 | 0, // Locale. NULL indicates current 74 | NULL, // Security flags. 75 | 0, // Authority (for example, Kerberos) 76 | 0, // Context object 77 | &pSvc // pointer to IWbemServices proxy 78 | ); 79 | 80 | if (FAILED(hres)) { 81 | pLoc->Release(); 82 | CoUninitialize(); 83 | throw std::exception("Could not connect to root/cimv2 namespace"); 84 | } 85 | 86 | 87 | // Step 5: -------------------------------------------------- 88 | // Set security levels on the proxy ------------------------- 89 | 90 | hres = CoSetProxyBlanket( 91 | pSvc, // Indicates the proxy to set 92 | RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx 93 | RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx 94 | NULL, // Server principal name 95 | RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx 96 | RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx 97 | NULL, // client identity 98 | EOAC_NONE // proxy capabilities 99 | ); 100 | 101 | if (FAILED(hres)) { 102 | pSvc->Release(); 103 | pLoc->Release(); 104 | CoUninitialize(); 105 | throw std::exception("Could not set proxy blanket"); 106 | } 107 | } 108 | 109 | public: 110 | static WMIWBEMINFO* getWMIWBEMINFOInstance(); 111 | IWbemLocator* getWbemLocator(); 112 | IWbemServices* getWbemServices(); 113 | HRESULT getHres(); 114 | ~WMIWBEMINFO(); 115 | }; 116 | 117 | -------------------------------------------------------------------------------- /SystemInfo/util/utility.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_H 2 | #define UTILITY_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "../core/SystemInfo.h" 8 | #include "../glb/globalVars.h" 9 | #include "../util/controlManager.h" 10 | 11 | enum class FILE_IO_OPERATION { 12 | SAVE_AS, 13 | OPEN 14 | }; 15 | 16 | static wstring ipToggleText[]{ 17 | L"Hide IP", 18 | L"Show IP" 19 | }; 20 | 21 | static wstring writeOutPrefix[]{ 22 | L"", 23 | L"", 24 | L"", 25 | L"" 26 | }; 27 | 28 | static wstring writeOutPostfix[]{ 29 | L"\n", 30 | L"\n\t", 31 | L"
", 32 | L"
" 33 | }; 34 | 35 | enum class WRITE_OUT_TYPE { 36 | APP_WINDOW, 37 | FILE_TXT, 38 | FILE_HTML, 39 | FILE_XML 40 | }; 41 | 42 | enum class OS_INFO_TYPES { 43 | MIDDLEWARE_BIOS = 1, 44 | SOFTWARE_OS, 45 | HARDWARE_MB, 46 | HARDWARE_RAM, 47 | HARDWARE_VIDEO_ADAPTER, 48 | HARDWARE_DISPLAY, 49 | HARDWARE_STORAGE, 50 | HARDWARE_CDROM, 51 | HARDWARE_NETWORK 52 | }; 53 | 54 | enum class WINDOW_CENTER_TYPE { 55 | CENTER_MAIN, 56 | CENTER_CHILD 57 | }; 58 | 59 | enum class FILE_EXTENSION { 60 | TXT, 61 | XML, 62 | HTML, 63 | PNG 64 | }; 65 | 66 | enum class SCR_SAVETYPE { 67 | LOCAL, 68 | INTERNET 69 | }; 70 | static std::wstring storageMediumManufacturers[20]{ 71 | L"Western Digital", 72 | L"Seagate", 73 | L"Fujitsu", 74 | L"Hitachi", 75 | L"Samsung", 76 | L"IMB" 77 | }; 78 | 79 | enum class ENCODER_IMG_TYPES { 80 | IMG_PNG = 0, 81 | IMG_BMP, 82 | IMG_JPG, 83 | IMG_GIF, 84 | IMG_TIFF 85 | }; 86 | 87 | const 88 | static 89 | unordered_map 90 | encoderImgTypesToStringMap = { 91 | {ENCODER_IMG_TYPES::IMG_PNG, L"image/png"}, 92 | {ENCODER_IMG_TYPES::IMG_BMP, L"image/bmp"}, 93 | {ENCODER_IMG_TYPES::IMG_JPG, L"image/jpeg"}, 94 | {ENCODER_IMG_TYPES::IMG_GIF, L"image/gif"}, 95 | {ENCODER_IMG_TYPES::IMG_TIFF, L"image/tiff"} 96 | }; 97 | 98 | static std::wstring imageEncodersForGdiPlus[]{ 99 | L"image / bmp", 100 | L"image / jpeg", 101 | L"image / gif", 102 | L"image / tiff", 103 | L"image / png" 104 | }; 105 | 106 | typedef struct RESULT_STRUCT { 107 | ACTION result; 108 | std::wstring src; 109 | TCHAR __src[256]; 110 | }; 111 | 112 | static std::wstring actionPromptText[]{ 113 | L"Open exported file?" 114 | }; 115 | 116 | void centerWindow(POINT*); 117 | void positionWindow(POINT*); 118 | std::string& BstrToStdString(const BSTR, std::string&, int cp = CP_UTF8); 119 | void trimNullTerminator(std::wstring&); 120 | std::wstring parseDiskStorageName(std::wstring); 121 | std::wstring convertUIntToString(UINT64); 122 | void trimWhiteSpace(std::wstring&); 123 | void generateFileName(TCHAR*, FILE_EXTENSION); 124 | UINT32 getInfoBoxItemCount(UINT32, SystemInfo*); 125 | UINT32 adjustItemHeight(HWND, UINT32, UINT32); 126 | void getCurrentDateTime(TCHAR *); 127 | void getCurrentDateTimeVerbose(TCHAR *); 128 | std::wstring formListString(SystemInfo*, OS_INFO_TYPES, WRITE_OUT_TYPE); 129 | enum class ACTION openFileDiag(HWND, FILE_EXTENSION, TCHAR*, int); 130 | void writeToFile(wofstream&, SystemInfo*, int, WRITE_OUT_TYPE); 131 | wstring fromChToWideStr(char *value); 132 | wstring fromIntToWideStr(int); 133 | std::wstring convertStringToWide(const std::string& as); 134 | void prependZeroToStr(WORD min, TCHAR *minBuff); 135 | vector stringSplit(const wchar_t *s, wchar_t delimiter); 136 | std::wstring netAdapterStringWrapper(NetAdapter); 137 | void getFileNameFromPath(TCHAR *fullPath, TCHAR *fileName); 138 | ACTION fileIOCheck(wofstream&); 139 | void calculateTimeAndFormat(TCHAR*); 140 | BOOL openDefAppForExpData(WORD command, RESULT_STRUCT *res); 141 | void configAppData(); 142 | bool dirExists(LPCTSTR); 143 | std::wstring convertWmiCapacityToGB(std::wstring); 144 | void removeTabulation(std::wstring&); 145 | void condenseSpaces(std::wstring&); 146 | std::wstring getSystemErrorCodeMessageForErrorCode(DWORD); 147 | std::wstring formMessageForUIExportByExportAction(ControlManager::UI_MESS_RES_ICON res, DWORD act); 148 | int GetEncoderClsid(const TCHAR *format, CLSID *pClsid); 149 | #endif -------------------------------------------------------------------------------- /SystemInfo/network/common/network.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "network.h" 9 | #include "../../util/utility.h" 10 | 11 | 12 | char *getUniCastIP(PIP_ADAPTER_UNICAST_ADDRESS pUnicast) { 13 | SOCKET_ADDRESS actualAddress = pUnicast->Address; 14 | LPSOCKADDR sock = actualAddress.lpSockaddr; 15 | sockaddr_in *act = (sockaddr_in*)sock; 16 | char *uniCastAddress = inet_ntoa(act->sin_addr); 17 | return uniCastAddress; 18 | } 19 | 20 | void NetAdapter::setAdapterDesc(wstring v) { 21 | (*this).adapterDesc = v; 22 | } 23 | 24 | void NetAdapter::setAdapterAdr(wstring v) { 25 | (*this).adapterAddr = v; 26 | } 27 | 28 | void NetAdapter::setAdapterGW(wstring v) { 29 | //stub 30 | } 31 | 32 | wstring NetAdapter::getAdapterDesc(void) { 33 | return (*this).adapterDesc; 34 | } 35 | 36 | wstring NetAdapter::getAdapterAdr(void) { 37 | return (*this).adapterAddr; 38 | } 39 | 40 | wstring NetAdapter::getAdapterGW(void) { 41 | return L"null"; 42 | } 43 | 44 | void NetAdapter::setAdapterType(wstring v) { 45 | (*this).adapterType = v; 46 | } 47 | 48 | wstring NetAdapter::getAdapterType(void) { 49 | return (*this).adapterType; 50 | } 51 | 52 | void fillNetworkAdapters(SystemInfo* localMachine) { 53 | 54 | PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL; 55 | PIP_ADAPTER_ADDRESSES pAddresses = NULL; 56 | DWORD dwRetValAddr = 0; 57 | UINT i; 58 | ULONG outBufLen = 0x3A98; 59 | 60 | pAddresses = (IP_ADAPTER_ADDRESSES *)malloc(outBufLen); 61 | if (pAddresses == NULL) { 62 | printf("Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n"); 63 | exit(1); 64 | } 65 | dwRetValAddr = GetAdaptersAddresses(AF_INET, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &outBufLen); 66 | USES_CONVERSION; 67 | if (dwRetValAddr == NO_ERROR) { 68 | pCurrAddresses = pAddresses; 69 | while (pCurrAddresses) { 70 | if (pCurrAddresses->IfType != 0x18 && pCurrAddresses->IfIndex != 0x83) { 71 | PIP_ADAPTER_UNICAST_ADDRESS pUnicast = pCurrAddresses->FirstUnicastAddress; 72 | NetAdapter adapter = NetAdapter(); 73 | wstring desc = wstring(pCurrAddresses->Description); 74 | wstring ipAddr = CA2W(getUniCastIP(pUnicast)); 75 | wstring type = pCurrAddresses->FriendlyName; 76 | adapter.setAdapterDesc(desc); 77 | adapter.setAdapterAdr(ipAddr); 78 | adapter.setAdapterType(type); 79 | localMachine->addNetworkAdapterText(netAdapterStringWrapper(adapter)); 80 | } 81 | pCurrAddresses = pCurrAddresses->Next; 82 | } 83 | } 84 | NetAdapter extIpPlaceHolder = NetAdapter(); 85 | wstring externalIpAddressDesc; 86 | wstring externalIp = L"Unable to fetch IP"; 87 | wstring type = L"null"; 88 | char buff[128] = { 0 }; 89 | if (getIpAddress(buff)) { 90 | externalIpAddressDesc = L"Connected to the Internet"; 91 | externalIp = fromChToWideStr(buff); 92 | } else { 93 | externalIpAddressDesc = L"Not connected to the Internet"; 94 | } 95 | extIpPlaceHolder.setAdapterDesc(externalIpAddressDesc); 96 | extIpPlaceHolder.setAdapterAdr(externalIp); 97 | extIpPlaceHolder.setAdapterType(type); 98 | //localMachine->addNetworkAdapter(extIpPlaceHolder); 99 | localMachine->addNetworkAdapterText(netAdapterStringWrapper(extIpPlaceHolder)); 100 | } 101 | int getIpAddress(char *ipBuff) { 102 | 103 | int connectionRes = 1; 104 | 105 | 106 | #ifndef _DEBUG 107 | HINTERNET hInternet, hFile; 108 | DWORD rSize; 109 | char *buffer = new char[128]; 110 | 111 | hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 112 | 113 | if ((hFile = 114 | InternetOpenUrl( 115 | hInternet, 116 | L"https://api.ipify.org", 117 | NULL, 118 | 0, 119 | INTERNET_FLAG_RELOAD, 120 | 0)) != NULL) { 121 | InternetReadFile(hFile, buffer, 128, &rSize); 122 | buffer[rSize] = '\0'; 123 | strcpy(ipBuff, buffer); 124 | InternetCloseHandle(hFile); 125 | connectionRes = 1; 126 | } else { 127 | connectionRes = 0; 128 | } 129 | InternetCloseHandle(hInternet); 130 | //test fallback 131 | #else 132 | strcpy(ipBuff, "1.1.1.1."); 133 | #endif 134 | 135 | return connectionRes; 136 | } 137 | -------------------------------------------------------------------------------- /SystemInfo/glb/globalVars.h: -------------------------------------------------------------------------------- 1 | #ifndef GLOBALVARS_H 2 | #define GLOBALVARS_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "../meta/SoftwareInfo.h" 9 | #include "../resource.h" 10 | 11 | using namespace std; 12 | extern int PROGRAM_INSTANCE; //0 - parent, 1 - child 13 | extern TCHAR PROGRAM_DATA_IMPORT_LOCATION[256]; //path to the xml file to import data from if the process is spawned by parent 14 | extern TCHAR execName[256]; 15 | extern SoftwareInfo *shippedSoftWare; 16 | extern HINSTANCE ghInstance; 17 | extern HWND mainWindowHwnd; 18 | extern int mainWindowWidth; 19 | extern int mainWindowHeight; 20 | extern int scrollY; 21 | extern int scrollFullPageHeight; 22 | extern HBRUSH grayBrush; 23 | extern HFONT appNameFontLarge; 24 | static vector iconArr; 25 | static vector iconArrCpuUtilizationIcons; 26 | const static int iconArrCpuUtilizationIconsSize = 6; 27 | const static int totalItemsCount = 13; 28 | 29 | 30 | static int glbCpuProgressStringXOffset; 31 | static int glbCpuProgressStringYOffset; 32 | const static int cpuProgressStringWindowWidthSmall = 26; 33 | 34 | const static int cpuProgressStringWindowHeightSmall = 15; 35 | const static int cpuProgressStringWindowWidthLarge = 40; 36 | const static int cpuProgressStringWindowHeightLarge = 15; 37 | 38 | //use this hardcoded value for png cls id if os failed to provide its own values for the png clsid 39 | const static CLSID glbPngFallbackHardCodedEncoderClsID = { 40 | 0x557cf406, 41 | 0x1a04, 42 | 0x11d3, 43 | {0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} }; 44 | 45 | static WORD ICON_IDS[totalItemsCount]{ 46 | BIOS_ICON, 47 | OS_ICON, 48 | CPU_ICON, 49 | MB_ICON, 50 | RAM_ICON, 51 | VIDEO_ICON, 52 | DISPLAY_ICON, 53 | STORAGE_ICON, 54 | OPTICAL_ICON, 55 | NETWORK_ICON, 56 | AUDIO_ICON, 57 | UPTIME_ICON 58 | }; 59 | 60 | static WORD UTIL_iCON_IDS[iconArrCpuUtilizationIconsSize]{ 61 | UTILIZATION_ICON_0, 62 | UTILIZATION_ICON_1, 63 | UTILIZATION_ICON_2, 64 | UTILIZATION_ICON_3, 65 | UTILIZATION_ICON_4, 66 | UTILIZATION_ICON_5 67 | }; 68 | 69 | 70 | 71 | static wstring UI_messagesCapt[] = { 72 | L"Success", 73 | L"Error" 74 | }; 75 | 76 | static wstring itemStrings[totalItemsCount] = { 77 | L"BIOS/UEFI", 78 | L"Operating System", 79 | L"CPU", 80 | L"Motherboard", 81 | L"RAM", 82 | L"GPU", 83 | L"Display", 84 | L"Storage", 85 | L"Optical drives", 86 | L"Network and Connections", 87 | L"Sound", 88 | L"Uptime", 89 | L"Snapshot" 90 | }; 91 | //DO NOT change, a map depends on it 92 | static TCHAR* savefileExtensions[] = { 93 | _T(".txt"), 94 | _T(".xml"), 95 | _T(".html"), 96 | _T(".png") 97 | }; 98 | 99 | static TCHAR *savefileExtensionsLong[] = { 100 | _T(".txt files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"), 101 | _T(".xml files (*.xml)\0*.xml\0All Files (*.*)\0*.*\0"), 102 | _T(".html files (*.html)\0*.html\0All Files (*.*)\0*.*\0"), 103 | _T(".png images (*.png)\0*.png\0All Files (*.*)\0*.*\0") 104 | }; 105 | 106 | static wstring RAMFormFactors[24]{ 107 | L"Unknown form factor", 108 | L"", 109 | L"SIP", 110 | L"DIP", 111 | L"ZIP", 112 | L"SOJ", 113 | L"Proprietary", 114 | L"SIMM", 115 | L"DIMM", 116 | L"TSOP", 117 | L"PGA", 118 | L"RIMM", 119 | L"SODIMM", 120 | L"SRIMM", 121 | L"SMD", 122 | L"SSMP", 123 | L"QFP", 124 | L"TQFP", 125 | L"SOIC", 126 | L"LCC", 127 | L"PLCC", 128 | L"BGA", 129 | L"FPBGA", 130 | L"LGA" 131 | }; 132 | 133 | static wstring RAMMemoryTypes[] = { 134 | L"Unknown", 135 | L"Other", 136 | L"DRAM", 137 | L"Synchronous DRAM", 138 | L"Cache DRAM", 139 | L"EDO", 140 | L"EDRAM", 141 | L"VRAM", 142 | L"SRAM", 143 | L"RAM", 144 | L"ROM", 145 | L"Flash", 146 | L"EEPROM", 147 | L"FEPROM", 148 | L"EPROM", 149 | L"CDRAM", 150 | L"3DRAM", 151 | L"SDRAM", 152 | L"SGRAM", 153 | L"RDRAM", 154 | L"DDR", 155 | L"DDR2", 156 | L"DDR2 FB-DIMM", 157 | L"", 158 | L"DDR3", 159 | L"FBD2", 160 | L"DDR4", 161 | L"LPDDR", 162 | L"LPDDR2", 163 | L"LPDDR3", 164 | L"LPDDR4", 165 | L"Logical non-volatile device", 166 | L"HBM", 167 | L"HBM2" 168 | }; 169 | 170 | static wstring PCType[2]{ 171 | L" (Laptop) ", 172 | L" (Desktop) " 173 | }; 174 | 175 | //time functions 176 | extern TCHAR *timeVerboseMonths[]; 177 | extern TCHAR *timeVerboseDaysOfWeek[]; 178 | //font 179 | extern HFONT ipToggleBtnFont; 180 | 181 | enum class ACTION { 182 | ACCEPTED, 183 | CANCELED_OUT, 184 | __ERROR 185 | }; 186 | 187 | extern WNDPROC lpfnScrEditProc; 188 | extern TCHAR sysInfoConfigDirectoryPath[256]; 189 | extern int currentCpuUsageGlobal; 190 | 191 | extern int glbCpuInfoHolderXoffset; 192 | extern int glbCpuInfoHolderYoffset; 193 | 194 | #endif -------------------------------------------------------------------------------- /SystemInfo/network/rest/rest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "atlstr.h" 7 | #include "atlimage.h" 8 | #include "rest.h" 9 | #include "../../dialog/scrUploadDialog.h" 10 | #include "../../export/screenCapture.h" 11 | 12 | bool uploadImage(RESULT_STRUCT *res, TCHAR *fileName) { 13 | 14 | const TCHAR* UPLOAD_SERVER = _T("upload.gyazo.com"); 15 | const TCHAR* UPLOAD_PATH = _T("/upload.cgi"); 16 | const TCHAR* szTitle = L"Gyazo"; 17 | 18 | const char* sBoundary = "----BOUNDARYBOUNDARY----"; // boundary 19 | const char sCrLf[] = { 0xd, 0xa, 0x0 }; 20 | const TCHAR* szHeader = 21 | _T("Content-type: multipart/form-data; boundary=----BOUNDARYBOUNDARY----"); 22 | 23 | std::ostringstream buf; 24 | std::string idStr; // ID 25 | 26 | 27 | buf << "--"; 28 | buf << sBoundary; 29 | buf << sCrLf; 30 | buf << "content-disposition: form-data; name=\"id\""; 31 | buf << sCrLf; 32 | buf << sCrLf; 33 | buf << idStr; 34 | buf << sCrLf; 35 | 36 | // -- imagedata part 37 | buf << "--"; 38 | buf << sBoundary; 39 | buf << sCrLf; 40 | buf << "content-disposition: form-data; name=\"imagedata\"; filename=\"gyazo.com\""; 41 | buf << sCrLf; 42 | //buf << "Content-type: image/png"; 43 | //buf << sCrLf; 44 | buf << sCrLf; 45 | 46 | std::ifstream png; 47 | png.open(fileName, std::ios::binary); 48 | if (png.fail()) { 49 | GenericMessageOK() 50 | .withMessage(L"Could not open PNG file") 51 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 52 | ->display(); 53 | png.close(); 54 | return FALSE; 55 | } 56 | buf << png.rdbuf(); //read all & append to buffer 57 | png.close(); 58 | 59 | buf << sCrLf; 60 | buf << "--"; 61 | buf << sBoundary; 62 | buf << "--"; 63 | buf << sCrLf; 64 | 65 | std::string oMsg(buf.str()); 66 | 67 | HINTERNET hSession = InternetOpen(szTitle, 68 | INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 69 | if (NULL == hSession) { 70 | GenericMessageOK() 71 | .withMessage(L"Cannot configure wininet") 72 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 73 | ->display(); 74 | return FALSE; 75 | } 76 | 77 | HINTERNET hConnection = InternetConnect(hSession, 78 | UPLOAD_SERVER, INTERNET_DEFAULT_HTTP_PORT, 79 | NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL); 80 | if (NULL == hSession) { 81 | GenericMessageOK() 82 | .withMessage(L"Cannot initiate connection") 83 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 84 | ->display(); 85 | return FALSE; 86 | } 87 | 88 | HINTERNET hRequest = HttpOpenRequest(hConnection, 89 | _T("POST"), UPLOAD_PATH, NULL, 90 | NULL, NULL, INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, NULL); 91 | if (NULL == hSession) { 92 | GenericMessageOK() 93 | .withMessage(L"Cannot compose post request") 94 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 95 | ->display(); 96 | return FALSE; 97 | } 98 | 99 | // Setting user-Agent 100 | const TCHAR* ua = _T("User-Agent: Gyazowin/1.0\r\n"); 101 | BOOL bResult = HttpAddRequestHeaders( 102 | hRequest, ua, _tcslen(ua), 103 | HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE); 104 | if (FALSE == bResult) { 105 | GenericMessageOK() 106 | .withMessage(L"Cannot set user agent") 107 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 108 | ->display(); 109 | 110 | return FALSE; 111 | } 112 | 113 | if (HttpSendRequest(hRequest, 114 | szHeader, 115 | lstrlen(szHeader), 116 | (LPVOID)oMsg.c_str(), 117 | (DWORD)oMsg.length())) { 118 | DWORD resLen = 8; 119 | TCHAR resCode[4]; 120 | 121 | // status code 122 | HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE, resCode, &resLen, 0); 123 | int ress = _tcscmp(resCode, L"200\0"); 124 | if (ress) { 125 | 126 | // upload (status error) 127 | GenericMessageOK() 128 | .withMessage(L"Failed to upload (unexpected result code, under maintainance?)") 129 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 130 | ->display(); 131 | } else { 132 | DWORD idLen = 100; 133 | TCHAR newid[100]; 134 | 135 | memset(newid, 0, idLen * sizeof(TCHAR)); 136 | _tcscpy_s(newid, _T("X-Gyazo-Id")); 137 | 138 | HttpQueryInfo(hRequest, HTTP_QUERY_CUSTOM, newid, &idLen, 0); 139 | if (GetLastError() != ERROR_HTTP_HEADER_NOT_FOUND && idLen != 0) { 140 | 141 | } 142 | 143 | 144 | DWORD len; 145 | char resbuf[1024]; 146 | ZeroMemory(&resbuf, sizeof(resbuf)); 147 | InternetReadFile(hRequest, (LPVOID)resbuf, 1024, &len); 148 | USES_CONVERSION; 149 | _tcscpy(res->__src, A2T(resbuf)); 150 | 151 | return TRUE; 152 | } 153 | } else { 154 | return false; 155 | } 156 | return FALSE; 157 | } 158 | 159 | -------------------------------------------------------------------------------- /SystemInfo/export/screenCapture.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "atlstr.h" 4 | #include "atlimage.h" 5 | #include "../export/screenCapture.h" 6 | #include "../util/utility.h" 7 | #include "../dialog/scrUploadDialog.h" 8 | #include "../network/rest/rest.h" 9 | 10 | 11 | ACTION takeScreenshot(HWND hwnd, SCR_SAVETYPE scrSaveType, RESULT_STRUCT *res) { 12 | 13 | //init GDI+ 14 | ULONG_PTR gdiPlusToken; 15 | Gdiplus::GdiplusStartupInput input; 16 | Gdiplus::GdiplusStartup(&gdiPlusToken, &input, nullptr); 17 | 18 | CLSID pngEncoderCLSID; 19 | 20 | if (GetEncoderClsid( 21 | encoderImgTypesToStringMap.at(ENCODER_IMG_TYPES::IMG_PNG).c_str(), 22 | &pngEncoderCLSID) == -1) { 23 | pngEncoderCLSID = glbPngFallbackHardCodedEncoderClsID; 24 | } 25 | 26 | std::vector bitmapList; 27 | 28 | INT32 pixelsToOffset = 10; 29 | VisibleAreaCoordsStruct initialDims = getVisibleClientArea(hwnd); 30 | 31 | INT32 currentVisibleYOffset = initialDims.visibleAreaHeight; 32 | INT32 initialVisibleYOffset = currentVisibleYOffset; 33 | //scroll a few pixels up and get hbitmap, 34 | //put into vector 35 | //merge by calling mergeBitmaps 36 | //scroll back 37 | if (scrollFullPageHeight > currentVisibleYOffset) { 38 | while (scrollFullPageHeight > currentVisibleYOffset) { 39 | ScrollWindow(hwnd, 0, -pixelsToOffset, NULL, NULL); 40 | UpdateWindow(hwnd); 41 | VisibleAreaCoordsStruct a = getVisibleClientArea(hwnd); 42 | Gdiplus::Bitmap* currBitmap = getBitmapFromAreaCoords(hwnd, a); 43 | bitmapList.push_back(currBitmap); 44 | currentVisibleYOffset += pixelsToOffset; 45 | Sleep(200); 46 | } 47 | ScrollWindow(hwnd, 0, currentVisibleYOffset - initialVisibleYOffset, NULL, NULL); 48 | UpdateWindow(hwnd); 49 | } 50 | else { 51 | VisibleAreaCoordsStruct a = getVisibleClientArea(hwnd); 52 | Gdiplus::Bitmap* currBitmap = getBitmapFromAreaCoords(hwnd, a); 53 | bitmapList.push_back(currBitmap); 54 | } 55 | //currentVisibleYOffset = adjusted image size; 56 | Gdiplus::Bitmap* gdiPlusMainImgBitmap = NULL; 57 | if (bitmapList.size() > 1) { 58 | gdiPlusMainImgBitmap = mergeBitmaps(bitmapList, currentVisibleYOffset); 59 | } 60 | else { 61 | gdiPlusMainImgBitmap = bitmapList.at(0); 62 | } 63 | 64 | TCHAR fullSavePath[256]; 65 | 66 | ZeroMemory(&fullSavePath, sizeof(fullSavePath)); 67 | if (scrSaveType == SCR_SAVETYPE::INTERNET) { 68 | _tcscpy(fullSavePath, sysInfoConfigDirectoryPath); 69 | TCHAR uuidString[256]; 70 | _tcscat(fullSavePath, L"\\"); 71 | _tcscat(fullSavePath, L"_temp.png"); 72 | } else if (scrSaveType == SCR_SAVETYPE::LOCAL) { 73 | if (openFileDiag(hwnd, FILE_EXTENSION::PNG, fullSavePath, 1) == ACTION::CANCELED_OUT) { 74 | return ACTION::CANCELED_OUT; 75 | } 76 | } 77 | if (!gdiPlusMainImgBitmap->Save(fullSavePath, &pngEncoderCLSID, NULL) == Gdiplus::Status::Ok) { 78 | return ACTION::__ERROR; 79 | } 80 | 81 | //shutdown GDI+ 82 | Gdiplus::GdiplusShutdown(gdiPlusToken); 83 | if (scrSaveType == SCR_SAVETYPE::LOCAL) { 84 | res->src.assign(fullSavePath); 85 | } 86 | if (scrSaveType == SCR_SAVETYPE::INTERNET) { 87 | RESULT_STRUCT resStruct = {}; 88 | if (!uploadImage(&resStruct, fullSavePath)) { 89 | GenericMessageOK() 90 | .withMessage(L"Failed to upload") 91 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 92 | ->display(); 93 | return ACTION::__ERROR; 94 | } 95 | else { 96 | _tcscpy(uploadSrcLinkData.link, resStruct.__src); 97 | } 98 | DeleteFile(fullSavePath); 99 | } 100 | return ACTION::ACCEPTED; 101 | } 102 | 103 | VisibleAreaCoordsStruct getVisibleClientArea(HWND hwnd) { 104 | RECT winSize; 105 | GetClientRect(hwnd, &winSize); 106 | 107 | //visible client area 108 | INT32 areaWidth = winSize.right - winSize.left; 109 | INT32 areaHeight = winSize.bottom - winSize.top; 110 | return { areaWidth, areaHeight }; 111 | } 112 | 113 | Gdiplus::Bitmap* getBitmapFromAreaCoords(HWND hwnd, VisibleAreaCoordsStruct &coords) { 114 | HDC mainWindowDC = GetDC(hwnd); 115 | HDC screenCapture = CreateCompatibleDC(mainWindowDC); 116 | HBITMAP hCaptureBitmap = CreateCompatibleBitmap(mainWindowDC, 117 | coords.visibleAreaWidth, coords.visibleAreaHeight); 118 | SelectObject(screenCapture, hCaptureBitmap); 119 | BitBlt(screenCapture, 120 | 0, 121 | 0, 122 | coords.visibleAreaWidth, 123 | coords.visibleAreaHeight, 124 | mainWindowDC, 125 | 0, 126 | 0, 127 | SRCCOPY | CAPTUREBLT); 128 | 129 | Gdiplus::Bitmap *gdiPlusMainImgBitmap = Gdiplus::Bitmap::FromHBITMAP(hCaptureBitmap, NULL); 130 | DeleteObject(hCaptureBitmap); 131 | ReleaseDC(hwnd, mainWindowDC); 132 | DeleteDC(screenCapture); 133 | return gdiPlusMainImgBitmap; 134 | } 135 | 136 | Gdiplus::Bitmap *mergeBitmaps( 137 | std::vector bitmapsToMerge, 138 | INT32 adjustedImageSizeByYOffset) { 139 | bitmapsToMerge.at(0)->GetWidth(); 140 | Gdiplus::Bitmap *completeBitmap = 141 | new Gdiplus::Bitmap( 142 | bitmapsToMerge.at(0)->GetWidth(), 143 | adjustedImageSizeByYOffset); 144 | Gdiplus::Graphics *g = Gdiplus::Graphics::FromImage(completeBitmap); 145 | //iterate over the vector and draw images one by one 146 | INT32 offsetForLength = 10; 147 | for (auto bitmapIterator = bitmapsToMerge.begin(); 148 | bitmapIterator != bitmapsToMerge.end(); 149 | bitmapIterator++) { 150 | if (bitmapIterator == bitmapsToMerge.begin()) { 151 | g->DrawImage((*bitmapIterator), 0, 0); 152 | } 153 | else { 154 | g->DrawImage((*bitmapIterator), 0, offsetForLength); 155 | offsetForLength += 10; 156 | } 157 | } 158 | return completeBitmap; 159 | } 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /SystemInfo/export/saveSpecs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../glb/globalVars.h" 6 | #include "../export/saveSpecs.h" 7 | #include "../core/SystemInfo.h" 8 | #include "../util/utility.h" 9 | #include "screenCapture.h" 10 | 11 | using namespace std; 12 | const TCHAR *saveSpecs::xmlDTD = _T("\n"); 13 | const TCHAR *saveSpecs::uniformComment = _T("Generated by -SystemInfo- on "); 14 | const TCHAR *saveSpecs::htmlCommentStart = _T("\n"); 16 | const TCHAR *saveSpecs::CSSCommentStart = _T("/*"); 17 | const TCHAR *saveSpecs::CSSCommentEnd = _T("*/\n"); 18 | saveSpecs::saveSpecs() {} 19 | 20 | //to do add file write exceptions 21 | ACTION saveSpecs::save(WORD command, 22 | RESULT_STRUCT *res, 23 | HWND hwnd, 24 | SystemInfo *localMachine) { 25 | 26 | switch (command) { 27 | case ID_EXPORT_XML: { 28 | res->result = saveAsXML(hwnd, localMachine, res); 29 | break; 30 | } 31 | case ID_EXPORT_TXT: { 32 | res->result = saveAsText(hwnd, localMachine, res); 33 | break; 34 | } 35 | case ID_EXPORT_HTML: { 36 | res->result = saveAsHTML(hwnd, localMachine, res); 37 | break; 38 | } 39 | case ID_FILE_TAKESCREENSHOT_SAVE_LOCALLY: { 40 | res->result = takeScreenshot(hwnd, SCR_SAVETYPE::LOCAL, res); 41 | break; 42 | } 43 | } 44 | return res->result; 45 | } 46 | 47 | ACTION saveSpecs::saveAsHTML(HWND hwnd, SystemInfo *info, RESULT_STRUCT *resultStruct) { 48 | TCHAR fullSavePath[256]; 49 | 50 | ZeroMemory(&fullSavePath, sizeof(fullSavePath)); 51 | 52 | if (openFileDiag(hwnd, FILE_EXTENSION::HTML, fullSavePath, 1) 53 | != ACTION::CANCELED_OUT) { 54 | std::locale loc(std::locale::classic(), new std::codecvt_utf8); //this line is necessary to output non-ascii text 55 | wofstream htmlOutFile; 56 | htmlOutFile.open(fullSavePath, wofstream::out); 57 | htmlOutFile.imbue(loc); 58 | TCHAR commentBuff[256] = { 0 }; 59 | getCurrentDateTimeVerbose(commentBuff); 60 | htmlOutFile << saveSpecs::htmlCommentStart; 61 | htmlOutFile << saveSpecs::uniformComment; 62 | htmlOutFile << commentBuff; 63 | htmlOutFile << saveSpecs::htmlCommentEnd; 64 | htmlOutFile << saveSpecs::htmlStartPoint; 65 | htmlOutFile << L"
\n"; 66 | for (int x = 0; x < totalItemsCount - 1; x++) { //excluding snapshot 67 | htmlOutFile << _T("\t
\n"); 68 | htmlOutFile << _T("\t\t
"); 69 | htmlOutFile << itemStrings[x].c_str(); 70 | htmlOutFile << _T("\t\t
\n"); 71 | htmlOutFile << _T("\t\t
"); 72 | writeToFile(htmlOutFile, info, x, WRITE_OUT_TYPE::FILE_HTML); 73 | htmlOutFile << L"\t
\n
\n"; 74 | } 75 | htmlOutFile << L"
\n\n\n"; 76 | 77 | htmlOutFile.close(); 78 | resultStruct->src.assign(fullSavePath); 79 | 80 | return fileIOCheck(htmlOutFile); 81 | } else { 82 | return ACTION::CANCELED_OUT; 83 | } 84 | } 85 | 86 | ACTION saveSpecs::saveAsXML(HWND hwnd, SystemInfo *info, RESULT_STRUCT *resultStruct) { 87 | TCHAR fullSavePath[256]; 88 | 89 | ZeroMemory(&fullSavePath, sizeof(fullSavePath)); 90 | 91 | if (openFileDiag(hwnd, FILE_EXTENSION::XML, fullSavePath, 1) != ACTION::CANCELED_OUT) { 92 | 93 | std::locale loc(std::locale::classic(), new std::codecvt_utf8); //this line is necessary to output non-ascii text 94 | wofstream xmlOutFile; 95 | xmlOutFile.open(fullSavePath, wofstream::out); 96 | xmlOutFile.imbue(loc); 97 | TCHAR commentBuff[256] = { 0 }; 98 | getCurrentDateTimeVerbose(commentBuff); 99 | xmlOutFile << saveSpecs::xmlDTD; 100 | xmlOutFile << saveSpecs::htmlCommentStart; 101 | xmlOutFile << saveSpecs::uniformComment; 102 | xmlOutFile << commentBuff; 103 | xmlOutFile << saveSpecs::htmlCommentEnd; 104 | 105 | xmlOutFile << L"\n"; 106 | for (int x = 0; x < totalItemsCount; x++) { 107 | xmlOutFile << _T("\t\n\t\t"); 110 | 111 | writeToFile(xmlOutFile, info, x, WRITE_OUT_TYPE::FILE_XML); 112 | 113 | xmlOutFile << L"\t\n"; 114 | } 115 | xmlOutFile << L"\n"; 116 | xmlOutFile.close(); 117 | resultStruct->src.assign(fullSavePath); 118 | return fileIOCheck(xmlOutFile); 119 | } else { 120 | return ACTION::CANCELED_OUT; 121 | } 122 | } 123 | 124 | void importAsXML(HWND hwnd) { 125 | 126 | TCHAR fullOpenPath[256]; 127 | ZeroMemory(&fullOpenPath, sizeof(fullOpenPath)); 128 | 129 | if (openFileDiag(hwnd, FILE_EXTENSION::XML, fullOpenPath, 0) != ACTION::CANCELED_OUT) { 130 | STARTUPINFO si; 131 | PROCESS_INFORMATION pi; 132 | 133 | ZeroMemory(&si, sizeof(si)); 134 | si.cb = sizeof(si); 135 | ZeroMemory(&pi, sizeof(pi)); 136 | 137 | 138 | // Start the child process. 139 | TCHAR fullExecLine[256] = { 0 }; 140 | _tcscpy(fullExecLine, execName); 141 | _tcscat(fullExecLine, fullOpenPath); 142 | 143 | 144 | DWORD err; 145 | DWORD res = 1; 146 | LPTSTR szcmdLine = _tcsdup(fullExecLine); 147 | if (!CreateProcess(NULL, // No module name (use command line) 148 | szcmdLine, // Command line 149 | NULL, // Process handle not inheritable 150 | NULL, // Thread handle not inheritable 151 | FALSE, // Set handle inheritance to FALSE 152 | 0, // No creation flags 153 | NULL, // Use parent's environment block 154 | NULL, // Use parent's starting directory 155 | &si, // Pointer to STARTUPINFO structure 156 | &pi)) { 157 | GenericMessageOK() 158 | .withMessage(L"Unable to create process") 159 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 160 | ->display(); 161 | } 162 | } 163 | } 164 | 165 | ACTION saveSpecs::saveAsText(HWND hwnd, SystemInfo *info, RESULT_STRUCT *resultStruct) { 166 | TCHAR fullSavePath[256]; 167 | 168 | ZeroMemory(&fullSavePath, sizeof(fullSavePath)); 169 | 170 | if (openFileDiag(hwnd, FILE_EXTENSION::TXT, fullSavePath, 1) != ACTION::CANCELED_OUT) { 171 | std::locale loc(std::locale::classic(), new std::codecvt_utf8); //this line is necessary to output non-ascii text 172 | wofstream txtOutFile; 173 | txtOutFile.open(fullSavePath, wofstream::out); 174 | txtOutFile.imbue(loc); 175 | TCHAR commentBuff[256] = { 0 }; 176 | getCurrentDateTimeVerbose(commentBuff); 177 | txtOutFile << saveSpecs::uniformComment; 178 | txtOutFile << commentBuff; 179 | txtOutFile << endl << endl; 180 | for (int x = 0; x < totalItemsCount - 1; x++) { //excluding snapshot 181 | txtOutFile << itemStrings[x].c_str(); 182 | txtOutFile << _T(":\n"); 183 | txtOutFile << _T("\t"); 184 | writeToFile(txtOutFile, info, x, WRITE_OUT_TYPE::FILE_TXT); 185 | txtOutFile << endl; 186 | } 187 | txtOutFile.close(); 188 | resultStruct->src.assign(fullSavePath); 189 | return fileIOCheck(txtOutFile); 190 | } else { 191 | return ACTION::CANCELED_OUT; 192 | } 193 | 194 | } 195 | 196 | saveSpecs::~saveSpecs() {} 197 | const TCHAR *saveSpecs::htmlStartPoint = _T("\ 198 | \n\ 199 | \n\ 200 | \ 201 | \n\ 202 | \n\ 232 | Hardware Information\n\ 233 | \n\ 234 | \n"); -------------------------------------------------------------------------------- /SystemInfo/SystemInfo.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {e0a14077-3b19-44c8-aef5-4bba2985e1d3} 18 | 19 | 20 | {6ab82245-1eeb-44b8-a735-fdc5bbe7d78c} 21 | 22 | 23 | {a400d830-f3e3-4670-8498-e27d75f3159f} 24 | 25 | 26 | {13e4bee5-132d-4557-963f-7426e1670b77} 27 | 28 | 29 | {26c4324f-baea-453d-b54f-5bdc6d53cea1} 30 | 31 | 32 | {fbdb2ee1-5039-4a1a-8178-b77f5a8b9ad8} 33 | 34 | 35 | {52c41785-2de7-4492-82fa-342804b4107b} 36 | 37 | 38 | {2a8c2d79-13a7-44ff-9944-37755bc037db} 39 | 40 | 41 | {fadfb506-963d-4d63-9545-8fdfa6b1a3e5} 42 | 43 | 44 | {4904ea02-d1f1-4343-99b5-acf54f7be4e1} 45 | 46 | 47 | {1d66ddd0-610b-4d4e-8f4d-c0646241279b} 48 | 49 | 50 | {6978f6a2-6a74-4303-8e45-40d49674e069} 51 | 52 | 53 | {d1cbdcf0-8a30-40f3-8555-149fa60d0ab0} 54 | 55 | 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | glb 68 | 69 | 70 | core 71 | 72 | 73 | core 74 | 75 | 76 | dialog 77 | 78 | 79 | export 80 | 81 | 82 | export 83 | 84 | 85 | import 86 | 87 | 88 | meta 89 | 90 | 91 | network\common 92 | 93 | 94 | pugi 95 | 96 | 97 | util 98 | 99 | 100 | network\rest 101 | 102 | 103 | dialog 104 | 105 | 106 | core 107 | 108 | 109 | logger 110 | 111 | 112 | util 113 | 114 | 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | glb 127 | 128 | 129 | const 130 | 131 | 132 | const 133 | 134 | 135 | const 136 | 137 | 138 | core 139 | 140 | 141 | core 142 | 143 | 144 | dialog 145 | 146 | 147 | export 148 | 149 | 150 | export 151 | 152 | 153 | import 154 | 155 | 156 | meta 157 | 158 | 159 | network\common 160 | 161 | 162 | pugi 163 | 164 | 165 | pugi 166 | 167 | 168 | util 169 | 170 | 171 | network\rest 172 | 173 | 174 | dialog 175 | 176 | 177 | core 178 | 179 | 180 | logger 181 | 182 | 183 | util 184 | 185 | 186 | 187 | 188 | Resource Files 189 | 190 | 191 | 192 | 193 | Resource Files 194 | 195 | 196 | Resource Files 197 | 198 | 199 | Resource Files 200 | 201 | 202 | Resource Files 203 | 204 | 205 | Resource Files 206 | 207 | 208 | Resource Files 209 | 210 | 211 | Resource Files 212 | 213 | 214 | Resource Files 215 | 216 | 217 | Resource Files 218 | 219 | 220 | Resource Files 221 | 222 | 223 | Resource Files 224 | 225 | 226 | Resource Files 227 | 228 | 229 | Resource Files 230 | 231 | 232 | Resource Files 233 | 234 | 235 | Resource Files 236 | 237 | 238 | Resource Files 239 | 240 | 241 | Resource Files 242 | 243 | 244 | Resource Files 245 | 246 | 247 | Resource Files 248 | 249 | 250 | 251 | 252 | 253 | -------------------------------------------------------------------------------- /SystemInfo/SystemInfo.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {48DC8C62-89CF-4F86-BFE0-42AA4080A9B8} 23 | Win32Proj 24 | SystemInfo 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | false 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | $(VC_IncludePath);$(WindowsSDK_IncludePath);W:\boost\boost_1_64_0 75 | 76 | 77 | true 78 | $(VC_IncludePath);$(WindowsSDK_IncludePath); 79 | 80 | 81 | false 82 | 83 | 84 | false 85 | 86 | 87 | 88 | 89 | 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 93 | MultiThreadedDebug 94 | 95 | 96 | Windows 97 | true 98 | W:\Projects\SI\v1.4\packages\curl-vc141-dynamic-x86_64.7.59.0\build\native\lib\Win32\dynamic;W:\Projects\SI\v1.4\packages\curl-vc141-dynamic-x86_64.7.59.0\build\native\lib\Win32\static;%(AdditionalLibraryDirectories) 99 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;gdiplus.lib;wbemuuid.lib;powrprof.lib;IPHLPAPI.lib;wininet.lib;ws2_32.lib;%(AdditionalDependencies) 100 | 101 | 102 | 103 | 104 | 105 | 106 | Level3 107 | Disabled 108 | _DEBUG;_WINDOWS;%(PreprocessorDefinitions) 109 | 110 | 111 | Windows 112 | true 113 | %(AdditionalLibraryDirectories) 114 | 115 | 116 | 117 | 118 | Level3 119 | 120 | 121 | Disabled 122 | true 123 | true 124 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 125 | MultiThreaded 126 | EditAndContinue 127 | %(AdditionalIncludeDirectories) 128 | 129 | 130 | Windows 131 | true 132 | true 133 | true 134 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;gdiplus.lib;wbemuuid.lib;powrprof.lib;IPHLPAPI.lib;wininet.lib;ws2_32.lib;%(AdditionalDependencies) 135 | 136 | 137 | 138 | 139 | Level3 140 | 141 | 142 | Disabled 143 | true 144 | true 145 | NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 146 | MultiThreaded 147 | 148 | 149 | Windows 150 | true 151 | true 152 | true 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | Designer 228 | 229 | 230 | 231 | 232 | -------------------------------------------------------------------------------- /SystemInfo/LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /SystemInfo/util/utility.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../glb/globalVars.h" 7 | #include "../util/utility.h" 8 | #include "../const/itemIDs.h" 9 | #include "../util/controlManager.h" 10 | 11 | void positionWindow(POINT *upperLeftCorner) { 12 | 13 | int offset = 0; 14 | if (PROGRAM_INSTANCE) { 15 | offset = 16; 16 | } 17 | (*upperLeftCorner).x = (GetSystemMetrics(SM_CXSCREEN) / 2 - mainWindowWidth / 2) + offset; 18 | (*upperLeftCorner).y = (GetSystemMetrics(SM_CYSCREEN) / 2 - mainWindowHeight / 2) + offset; 19 | } 20 | 21 | void centerWindow(POINT *upperLeftCorner) { 22 | (*upperLeftCorner).x = GetSystemMetrics(SM_CXSCREEN) / 2 - mainWindowWidth / 2; 23 | (*upperLeftCorner).y = GetSystemMetrics(SM_CYSCREEN) / 2 - mainWindowHeight / 2; 24 | } 25 | 26 | void trimNullTerminator(wstring &strToTrim) { 27 | strToTrim = strToTrim.erase(strToTrim.length()); 28 | } 29 | 30 | std::wstring convertStringToWide(const std::string& as) { 31 | 32 | wchar_t* buf = new wchar_t[as.size() * 2 + 2]; 33 | swprintf(buf, L"%S", as.c_str()); 34 | std::wstring rval = buf; 35 | trimWhiteSpace(rval); 36 | delete[] buf; 37 | return rval; 38 | } 39 | 40 | std::string& BstrToStdString(const BSTR bstr, std::string& dst, int cp) { 41 | 42 | if (!bstr) { 43 | // define NULL functionality. I just clear the target. 44 | dst.clear(); 45 | return dst; 46 | } 47 | // request content length in single-chars through a terminating 48 | // nullchar in the BSTR. note: BSTR's support imbedded nullchars, 49 | // so this will only convert through the first nullchar. 50 | int res = WideCharToMultiByte(cp, 0, bstr, -1, NULL, 0, NULL, NULL); 51 | if (res > 0) { 52 | dst.resize(res); 53 | WideCharToMultiByte(cp, 0, bstr, -1, &dst[0], res, NULL, NULL); 54 | } 55 | // no content. clear target 56 | else { 57 | dst.clear(); 58 | } 59 | return dst; 60 | } 61 | 62 | wstring parseDiskStorageName(wstring modelName) { 63 | 64 | wstring finalString = L""; 65 | if (modelName.find(L"WDC", 0, 3) != wstring::npos) { 66 | return storageMediumManufacturers[0]; 67 | } else if (modelName.find(L"MHS", 0, 3) != wstring::npos) { 68 | return storageMediumManufacturers[2]; 69 | } else if (modelName.find(L"HTS", 0, 3) != wstring::npos) { 70 | return storageMediumManufacturers[3]; 71 | } else if (modelName.find(L"DTL") != wstring::npos) { 72 | return storageMediumManufacturers[5]; 73 | } else if (modelName.find(L"ST", 0, 2) != wstring::npos || modelName.find(L"SC", 0, 2) != wstring::npos) { 74 | return storageMediumManufacturers[1]; 75 | } else { 76 | return finalString; 77 | } 78 | } 79 | 80 | vector stringSplit(const wchar_t *s, wchar_t delimiter) { 81 | 82 | vector res; 83 | do { 84 | const wchar_t *begin = s; 85 | while (*s != delimiter && *s) { 86 | s++; 87 | } 88 | res.push_back(wstring(begin, s)); 89 | s += 5; 90 | } while (*s++ != 0); 91 | return res; 92 | } 93 | 94 | wstring convertUIntToString(UINT64 num) { 95 | wstring str; 96 | TCHAR *buff = new TCHAR[256]; 97 | _stprintf(buff, L"%u", num); 98 | str = wstring(buff); 99 | delete buff; 100 | return str; 101 | } 102 | 103 | void trimWhiteSpace(wstring &str) { 104 | if (!str.empty()) { 105 | int whiteSpaceStart = str.find_last_not_of(L" \t"); 106 | str.erase(whiteSpaceStart + 1); 107 | int whiteSpaceStartBeginning = str.find_first_not_of(L" \n\t"); 108 | str.erase(str.begin(), str.end() - (str.length() - whiteSpaceStartBeginning)); 109 | } 110 | } 111 | 112 | 113 | 114 | //Generates string in the following format: "sysinfo capture @ YYYY-MM-DD-HH:MM.required_extension" 115 | void generateFileName(TCHAR *completeFileName, FILE_EXTENSION requiredExtension) { 116 | ZeroMemory(completeFileName, sizeof(completeFileName)); 117 | TCHAR timeDateFileName[256]; 118 | getCurrentDateTime(timeDateFileName); 119 | _tcscpy(completeFileName, _T("sysinfo-capture-")); 120 | _tcscat(completeFileName, timeDateFileName); 121 | _tcscat(completeFileName, savefileExtensions[(int)requiredExtension]); 122 | } 123 | 124 | void getCurrentDateTime(TCHAR *buffer) { 125 | SYSTEMTIME currentTime; 126 | GetLocalTime(¤tTime); 127 | TCHAR finalTimeString[256]; 128 | TCHAR strMinBuff[16]; 129 | TCHAR strSecBuff[16]; 130 | TCHAR strMonBuff[16]; 131 | 132 | prependZeroToStr(currentTime.wMinute, strMinBuff); 133 | prependZeroToStr(currentTime.wSecond, strSecBuff); 134 | prependZeroToStr(currentTime.wMonth, strMonBuff); 135 | 136 | _stprintf(buffer, _T("%d-%s-%d_@_%d.%s.%s"), 137 | currentTime.wYear, 138 | strMonBuff, 139 | currentTime.wDay, 140 | currentTime.wHour, 141 | strMinBuff, 142 | strSecBuff); 143 | } 144 | 145 | void prependZeroToStr(WORD val, TCHAR *valBuff) { 146 | if (val < 10) { 147 | _itow(val, valBuff, 10); 148 | wstring temp = wstring(valBuff); 149 | temp = L"0" + temp; 150 | _tcscpy(valBuff, temp.c_str()); 151 | } else { 152 | _stprintf(valBuff, L"%d", val); 153 | } 154 | } 155 | 156 | //format: Friday, January 21, 2017 @ 0 00 157 | void getCurrentDateTimeVerbose(TCHAR *buffer) { 158 | SYSTEMTIME currentTime; 159 | WORD min; 160 | TCHAR minBuff[16]; 161 | GetLocalTime(¤tTime); 162 | prependZeroToStr(currentTime.wMinute, minBuff); 163 | _stprintf(buffer, _T("%s, %s %d, %d @ %d:%s"), 164 | timeVerboseDaysOfWeek[currentTime.wDayOfWeek], 165 | timeVerboseMonths[currentTime.wMonth], 166 | currentTime.wDay, 167 | currentTime.wYear, 168 | currentTime.wHour, 169 | minBuff); 170 | } 171 | 172 | //adjusts item height based on the number of elements and returns updated offset 173 | UINT32 adjustItemHeight(HWND windowHandle, UINT32 ITEM_ID, UINT32 innerItemsCount) { 174 | HWND itemHandle = GetDlgItem(windowHandle, ITEM_ID); 175 | RECT itemHandleDimensions; 176 | GetWindowRect(itemHandle, &itemHandleDimensions); 177 | MapWindowPoints(HWND_DESKTOP, windowHandle, (LPPOINT)&itemHandleDimensions, 2); 178 | UINT32 adjustedItemHeight; 179 | UINT32 adjustedYAxisOffset; 180 | adjustedItemHeight = innerItemsCount * 15; 181 | adjustedYAxisOffset = itemHandleDimensions.top + adjustedItemHeight + 5; 182 | return adjustedYAxisOffset; 183 | } 184 | 185 | UINT32 getInfoBoxItemCount(UINT32 ITEM_ID, SystemInfo *info) { 186 | UINT32 hardwareListSize = 0; 187 | switch (ITEM_ID) { 188 | case GPU_INFO: { 189 | hardwareListSize = info->getGPUDevices().size(); 190 | break; 191 | } 192 | case MONITOR_INFO: { 193 | hardwareListSize = info->getDisplayDevices().size(); 194 | break; 195 | } 196 | case STORAGE_INFO: { 197 | hardwareListSize = info->getStorageMediums().size(); 198 | break; 199 | } 200 | case OPTICAL_INFO: { 201 | hardwareListSize = info->getCDROMDevices().size(); 202 | break; 203 | } 204 | case NETWORK_INFO: { 205 | hardwareListSize = info->getNetworkAdaptersText().size(); 206 | break; 207 | } 208 | default: { 209 | return 1; //single field like CPU or BIOS 210 | break; 211 | } 212 | } 213 | if (!hardwareListSize) { 214 | hardwareListSize = 1; 215 | } 216 | return hardwareListSize; 217 | } 218 | 219 | //this function forms a single string to display within the program window 220 | //make HARDWARE_TYPE instead of harware_vector_type to process strings and vectors 221 | wstring formListString(SystemInfo *currentMachine, OS_INFO_TYPES type, WRITE_OUT_TYPE wType) { 222 | wstring finalString = L""; 223 | vector values; 224 | wstring emptyValue; 225 | if (type == OS_INFO_TYPES::HARDWARE_VIDEO_ADAPTER) { 226 | values = currentMachine->getGPUDevices(); 227 | emptyValue = itemStrings[5]; 228 | } else if (type == OS_INFO_TYPES::HARDWARE_DISPLAY) { 229 | values = currentMachine->getDisplayDevices(); 230 | emptyValue = itemStrings[6]; 231 | } else if (type == OS_INFO_TYPES::HARDWARE_STORAGE) { 232 | values = currentMachine->getStorageMediums(); 233 | emptyValue = itemStrings[7]; 234 | } else if (type == OS_INFO_TYPES::HARDWARE_CDROM) { 235 | values = currentMachine->getCDROMDevices(); 236 | emptyValue = itemStrings[8]; 237 | } else if (type == OS_INFO_TYPES::HARDWARE_NETWORK) { 238 | values = currentMachine->getNetworkAdaptersText(); 239 | emptyValue = itemStrings[9]; 240 | } 241 | if (values.empty()) { 242 | return emptyValue + L" not detected"; 243 | } else { 244 | for (auto iterator = values.begin(); 245 | iterator != values.end(); 246 | iterator++) { 247 | finalString.append(writeOutPrefix[static_cast(wType)]); 248 | finalString.append((*iterator)); 249 | finalString.append(writeOutPostfix[static_cast(wType)]); 250 | } 251 | return finalString; 252 | } 253 | } 254 | 255 | ACTION openFileDiag(HWND mainWindow, 256 | FILE_EXTENSION extension, 257 | TCHAR *fullOpenSavePath, int mode) { 258 | OPENFILENAME fileName; 259 | TCHAR szFile[MAX_PATH]; 260 | ZeroMemory(&fileName, sizeof(fileName)); 261 | szFile[0] = L'\0'; 262 | fileName.lStructSize = sizeof(fileName); 263 | fileName.hwndOwner = mainWindow; 264 | fileName.nMaxFile = sizeof(szFile); 265 | 266 | TCHAR *shortExtension = savefileExtensions[(int)extension]; 267 | fileName.lpstrFilter = savefileExtensionsLong[(int)extension]; 268 | if (mode) { 269 | fileName.Flags = 270 | OFN_PATHMUSTEXIST 271 | | OFN_OVERWRITEPROMPT 272 | | OFN_EXPLORER 273 | | OFN_HIDEREADONLY; 274 | } else { 275 | fileName.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST; 276 | } 277 | if (mode) { 278 | TCHAR buffer[256]; 279 | ZeroMemory(&buffer, sizeof(buffer)); 280 | generateFileName(buffer, extension); 281 | fileName.lpstrFileTitle = buffer; 282 | fileName.lpstrFile = buffer; 283 | if (GetSaveFileName(&fileName)) { 284 | _tcscpy(fullOpenSavePath, fileName.lpstrFile); 285 | return ACTION::ACCEPTED; 286 | } else { 287 | return ACTION::CANCELED_OUT; 288 | } 289 | } else { 290 | 291 | fileName.lpstrFile = szFile; 292 | if (GetOpenFileName(&fileName)) { 293 | _tcscpy(fullOpenSavePath, fileName.lpstrFile); 294 | return ACTION::ACCEPTED; 295 | //success 296 | } else { 297 | return ACTION::CANCELED_OUT; 298 | } 299 | } 300 | 301 | } 302 | 303 | void writeToFile(wofstream &fileStream, SystemInfo *info, int counter, WRITE_OUT_TYPE woType) { 304 | if (counter >= 5 && counter <= 9) { 305 | fileStream << formListString(info, static_cast(counter), woType).c_str(); 306 | } else { 307 | switch (counter) { 308 | case 0: { 309 | fileStream << info->getBIOS().c_str(); 310 | break; 311 | } 312 | case 1: { 313 | fileStream << info->getOS().c_str(); 314 | break; 315 | } 316 | case 2: { 317 | fileStream << info->getCPU().c_str(); 318 | break; 319 | } 320 | case 3: { 321 | fileStream << info->getMB().c_str(); 322 | break; 323 | } 324 | case 4: { 325 | fileStream << info->getRAM().c_str(); 326 | break; 327 | } 328 | case 10: { 329 | fileStream << info->getAudio().c_str(); 330 | break; 331 | } 332 | case 11: { 333 | fileStream << info->getUptime().c_str(); 334 | break; 335 | } 336 | case 12: { 337 | fileStream << info->getSnapshotGenDateTime().c_str(); 338 | break; 339 | } 340 | } 341 | } 342 | } 343 | 344 | wstring fromChToWideStr(char *value) { 345 | char txtBuff[256] = { 0 }; 346 | wstring wStr; 347 | wchar_t _wtxtBuff[256] = { 0 }; 348 | strcpy(txtBuff, value); 349 | mbstowcs(_wtxtBuff, txtBuff, sizeof(txtBuff)); 350 | wStr = wstring(_wtxtBuff); 351 | return wStr; 352 | } 353 | 354 | wstring fromIntToWideStr(int type) { 355 | wstring connType; 356 | switch (type) { 357 | case 1: 358 | connType = L"Other"; 359 | break; 360 | case 6: 361 | connType = L"Ethernet"; 362 | break; 363 | case 9: 364 | connType = L"Token Ring"; 365 | break; 366 | case 15: 367 | connType = L"FDDI\n"; 368 | break; 369 | case 23: 370 | connType = L"PPP\n"; 371 | break; 372 | case 24: 373 | connType = L"Loopback"; 374 | break; 375 | case 28: 376 | connType = L"Slip"; 377 | break; 378 | case 71: 379 | connType = L"Wi-Fi"; 380 | break; 381 | default: 382 | connType = L"Unknown type"; 383 | break; 384 | } 385 | return connType; 386 | } 387 | 388 | wstring netAdapterStringWrapper(NetAdapter adapter) { 389 | 390 | wstring completeString = adapter.getAdapterDesc() 391 | + L": " + adapter.getAdapterAdr(); 392 | if (adapter.getAdapterType() != L"null") { 393 | completeString += L" (" + adapter.getAdapterType() + L")"; 394 | } 395 | return completeString; 396 | } 397 | 398 | void getFileNameFromPath(TCHAR *fullPath, TCHAR *fileName) { 399 | TCHAR fullPathTempBuff[256] = { 0 }; 400 | _tcscpy(fullPathTempBuff, fullPath); 401 | #define fullPath fullPathTempBuff 402 | TCHAR *ptr = _tcstok(fullPath, _T("\\")); 403 | TCHAR *prevInstance; 404 | while (ptr != NULL) { 405 | prevInstance = ptr; 406 | ptr = _tcstok(NULL, _T("\\")); 407 | } 408 | _tcscpy(fileName, prevInstance); 409 | #undef fullPath 410 | } 411 | 412 | ACTION fileIOCheck(wofstream &stream) { 413 | if (stream) { 414 | return ACTION::ACCEPTED; 415 | } else { 416 | return ACTION::__ERROR; 417 | } 418 | } 419 | 420 | void calculateTimeAndFormat(TCHAR *formattedTimeString) { 421 | 422 | UINT64 uptimeMilliseconds = GetTickCount64(); 423 | UINT64 uptimeSeconds = 0; 424 | UINT64 uptimeMinutes = 0; 425 | UINT64 uptimeHours = 0; 426 | UINT64 uptimeDays = 0; 427 | 428 | uptimeSeconds = uptimeMilliseconds / 1000; 429 | uptimeMinutes = uptimeSeconds / 60; 430 | uptimeHours = uptimeSeconds / 3600; 431 | if (uptimeMinutes > 1) { 432 | uptimeSeconds -= uptimeMinutes * 60; 433 | } 434 | if (uptimeHours > 0) { 435 | uptimeMinutes -= uptimeHours * 60; 436 | if (uptimeHours > 24) { 437 | uptimeDays = uptimeHours / 24; 438 | uptimeHours -= uptimeDays * 24; 439 | } 440 | } 441 | if (uptimeDays != 0) { 442 | if (uptimeHours != 0) { 443 | if (uptimeHours > 1) { 444 | _stprintf(formattedTimeString, 445 | uptimeDays > 1 ? L"%llu days, %llu hrs, %llu mins, %llu seconds" : 446 | L"%llu day, %llu hrs, %llu mins, %llu seconds", 447 | uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds); 448 | } else { 449 | _stprintf(formattedTimeString, uptimeDays > 1 ? L"%llu days, %llu hr" 450 | : L"%llu day, %llu hr, %llu mins, %ll seconds", uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds); 451 | 452 | } 453 | _stprintf(formattedTimeString, L"%llu days, %llu hrs, %llu mins, %llu seconds", 454 | uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds); 455 | } else { 456 | _stprintf(formattedTimeString, uptimeDays > 1 ? L"%llu days, %llu hrs, %llu mins, %llu seconds" : 457 | L"%llu day, %llu hrs, %llu mins, %llu seconds", uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds); 458 | } 459 | } else { 460 | if (uptimeHours < 1) { 461 | _stprintf(formattedTimeString, L"%llu mins, %llu secs", uptimeMinutes, uptimeSeconds); 462 | //_stprintf(formattedTimeString, L"%s",L"Less than an hour"); 463 | } else if (uptimeHours == 1) { 464 | _stprintf(formattedTimeString, L"%llu hr, %llu mins, %llu seconds", uptimeHours, uptimeMinutes, uptimeSeconds); 465 | } else { 466 | _stprintf(formattedTimeString, L"%llu hrs, %llu mins, %llu seconds", uptimeHours, uptimeMinutes, uptimeSeconds); 467 | } 468 | } 469 | } 470 | 471 | 472 | //opens external application to view exported data, opens 'open with' dialog 473 | BOOL openDefAppForExpData(WORD command, RESULT_STRUCT *res) { 474 | std::wstring openUrl = res->src; 475 | CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); 476 | SHELLEXECUTEINFO sei = { sizeof(sei) }; 477 | sei.nShow = SW_SHOWNORMAL; 478 | sei.lpVerb = L"openas"; 479 | sei.lpFile = openUrl.c_str(); 480 | sei.fMask = SEE_MASK_INVOKEIDLIST; 481 | return ShellExecuteEx(&sei); 482 | } 483 | 484 | 485 | void configAppData() { 486 | PWSTR sysAppDataPath; 487 | TCHAR fullPath[256]; 488 | if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, NULL, NULL, &sysAppDataPath))) { 489 | _tcscpy(fullPath, sysAppDataPath); 490 | _tcscat(fullPath, L"\\SystemInfo"); 491 | CreateDirectoryW(fullPath, NULL); 492 | _tcscpy(sysInfoConfigDirectoryPath, fullPath); 493 | } 494 | } 495 | 496 | bool dirExists(LPCTSTR dirPath) { 497 | DWORD dwAttr = GetFileAttributes(dirPath); 498 | return (dwAttr != 0xffffffff && (dwAttr & FILE_ATTRIBUTE_DIRECTORY)); 499 | } 500 | 501 | bool createSimpleDirectory(TCHAR *path) { 502 | return CreateDirectoryW(path, NULL); 503 | } 504 | 505 | std::wstring convertWmiCapacityToGB(wstring val) { 506 | TCHAR tempChar[100]; 507 | double cap; 508 | double capacity; 509 | double accumulatedRAM = 0; 510 | _tcscpy(tempChar, val.c_str()); 511 | swscanf(tempChar, L"%lf", &cap); 512 | 513 | cap /= (pow(1024, 3)); 514 | accumulatedRAM += cap; 515 | TCHAR capacityStrBuff[100]; 516 | _stprintf(capacityStrBuff, _T("%.2lf"), accumulatedRAM); 517 | return wstring(capacityStrBuff); 518 | } 519 | 520 | void removeTabulation(std::wstring &str) { 521 | str.erase(std::remove(str.begin(), str.end(), L'\t'), str.end()); 522 | } 523 | 524 | bool wcharEqualsPredicate(wchar_t a, wchar_t b) { 525 | return a == b && a == ' '; 526 | } 527 | 528 | void condenseSpaces(std::wstring &str) { 529 | std::wstring::iterator new_end = 530 | std::unique(str.begin(), str.end(), wcharEqualsPredicate); 531 | str.erase(new_end, str.end()); 532 | } 533 | 534 | std::wstring getSystemErrorCodeMessageForErrorCode(DWORD errorCode) { 535 | TCHAR *errorCodeString = new TCHAR[256]; 536 | FormatMessage( 537 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 538 | FORMAT_MESSAGE_FROM_SYSTEM | 539 | FORMAT_MESSAGE_IGNORE_INSERTS, 540 | NULL, 541 | errorCode, 542 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 543 | (LPTSTR)& errorCode, 544 | 0, NULL); 545 | return std::wstring(errorCodeString); 546 | } 547 | 548 | std::wstring formMessageForUIExportByExportAction(ControlManager::UI_MESS_RES_ICON res, DWORD act) { 549 | return (ControlManager::UI_messagesTxt[0] + 550 | ControlManager::UIMessageExportFileExtByUserExportModeCommandMap 551 | .at((ControlManager::UI_MESS_EXPORT_ACTION)static_cast(act)) 552 | [0] + L" file"); 553 | } 554 | 555 | int GetEncoderClsid(const TCHAR *format, CLSID *pClsid) { 556 | UINT num = 0; // number of image encoders 557 | UINT size = 0; // size of the image encoder array in bytes 558 | 559 | Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL; 560 | 561 | Gdiplus::GetImageEncodersSize(&num, &size); 562 | if (size == 0) 563 | return -1; // Failure 564 | 565 | pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size)); 566 | if (pImageCodecInfo == NULL) 567 | return -1; // Failure 568 | 569 | GetImageEncoders(num, size, pImageCodecInfo); 570 | 571 | for (UINT j = 0; j < num; ++j) 572 | { 573 | if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) 574 | { 575 | *pClsid = pImageCodecInfo[j].Clsid; 576 | free(pImageCodecInfo); 577 | return j; // Success 578 | } 579 | } 580 | 581 | free(pImageCodecInfo); 582 | return -1; // Failure 583 | } -------------------------------------------------------------------------------- /SystemInfo/mainWindowProcedure.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "resource.h" 9 | #include "core/SystemInfo.h" 10 | #include "core/sysinfo.h" 11 | #include "glb/globalVars.h" 12 | #include "const/appconst.h" 13 | #include "const/itemIDs.h" 14 | #include "const/iconLabelIDs.h" 15 | #include "mainWindowProcedure.h" 16 | #include "export/screenCapture.h" 17 | #include "util/utility.h" 18 | #include "export/saveSpecs.h" 19 | #include "dialog/aboutDialog.h" 20 | #include "dialog/scrUploadDialog.h" 21 | #include "import/binImport.h" 22 | #include "core/WMIWBEMINFO.h" 23 | #include "core/sysinfo.h" 24 | #include "util/controlManager.h" 25 | 26 | int g_scrollY = 0; 27 | LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { 28 | SystemInfo *localMachine = localMachine->getCurrentInstance(); 29 | PAINTSTRUCT ps; 30 | HDC hdc; 31 | SCROLLINFO si; 32 | LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam; 33 | switch (msg) { 34 | case WM_CREATE: { 35 | loadImages(); 36 | if (PROGRAM_INSTANCE == 1) { 37 | importData(localMachine->getCurrentInstance()); 38 | } else { 39 | fillSystemInformation(localMachine->getCurrentInstance()); 40 | //test(); 41 | } 42 | fillGUI(hwnd, localMachine, 0); 43 | toggleIpAddress(hwnd, NULL); 44 | 45 | return 0; 46 | } 47 | 48 | case WM_COMMAND: { 49 | WORD receivedCommand = LOWORD(wParam); 50 | switch (receivedCommand) { 51 | case ID_FILE_TAKESCREENSHOT_UPLOAD: { 52 | takeScreenshot(hwnd, SCR_SAVETYPE::INTERNET, NULL); 53 | DialogBox(ghInstance, MAKEINTRESOURCE(IDD_DIALOG_SCRUPLOAD), hwnd, (DLGPROC)scrDlgProc); 54 | break; 55 | } 56 | case ID_FILE_TAKESCREENSHOT_SAVE_LOCALLY: 57 | case ID_EXPORT_XML: 58 | case ID_EXPORT_TXT: 59 | case ID_EXPORT_HTML: { 60 | std::unique_ptr pDateTime(new TCHAR[256]); 61 | //export xml 62 | getCurrentDateTimeVerbose(pDateTime.get()); 63 | wstring dateTimeConv(pDateTime.get()); 64 | localMachine-> 65 | getCurrentInstance()-> 66 | setSnapshotGenDateTime(dateTimeConv); 67 | RESULT_STRUCT resStruct = {}; 68 | 69 | saveSpecs::save(receivedCommand, &resStruct, hwnd, localMachine->getCurrentInstance()); 70 | if (resStruct.result == ACTION::ACCEPTED) { 71 | GenericMessageOK() 72 | .withMessage( 73 | formMessageForUIExportByExportAction 74 | (ControlManager::UI_MESS_RES_ICON::QUESTION, 75 | receivedCommand) 76 | ) 77 | ->withIcon(ControlManager::UI_MESS_RES_ICON::SUCCESS) 78 | ->display(); 79 | 80 | if (PromptMessageYesNo() 81 | .withMessage(actionPromptText[0]) 82 | ->withIcon(ControlManager::UI_MESS_RES_ICON::QUESTION) 83 | ->display() == IDYES) { 84 | if (openDefAppForExpData(receivedCommand, &resStruct) != TRUE) { 85 | GenericMessageOK() 86 | .withMessage(L"Unable to open exported data") 87 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 88 | ->display(); 89 | } 90 | } 91 | break; 92 | } 93 | else if(resStruct.result == ACTION::__ERROR) { 94 | GenericMessageOK() 95 | .withMessage(L"Error while writing to file") 96 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 97 | ->display(); 98 | } 99 | else { 100 | //user canceled the save window out 101 | } 102 | break; 103 | } 104 | case ID_IMPORT_FROMXML: { 105 | importAsXML(hwnd); 106 | break; 107 | } 108 | case ID_ABOUT: { 109 | DialogBox(ghInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, (DLGPROC)aboutDlgProc); 110 | break; 111 | } 112 | case ID_FILE_EXIT: { 113 | PostQuitMessage(WM_QUIT); 114 | break; 115 | } 116 | case AUX_IP_TOGGLE: { 117 | toggleIpAddress(hwnd, localMachine); 118 | break; 119 | } 120 | } 121 | } 122 | //to do put hardcoded color values in external constants 123 | case WM_CTLCOLORSTATIC: { 124 | HDC hdcStatic = (HDC)wParam; 125 | if (GetDlgCtrlID((HWND)lParam) < BIOS_INFO) { 126 | if (GetDlgCtrlID((HWND)lParam) == SNAPSHOT_LABEL) { 127 | SetTextColor(hdcStatic, RGB(0, 255, 0)); 128 | } else { 129 | SetTextColor(hdcStatic, RGB(125, 207, 246)); 130 | } 131 | } 132 | else if (GetDlgCtrlID((HWND)lParam) == AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_STRING) { 133 | if (currentCpuUsageGlobal >= 0) { 134 | if (currentCpuUsageGlobal <= 33) { 135 | SetTextColor(hdcStatic, RGB(0, 255, 0)); 136 | } 137 | else if (currentCpuUsageGlobal > 33 && currentCpuUsageGlobal <= 66) { 138 | SetTextColor(hdcStatic, RGB(255, 255, 0)); 139 | } 140 | else { 141 | SetTextColor(hdcStatic, RGB(255, 0, 0)); 142 | } 143 | } 144 | else { 145 | SetTextColor(hdcStatic, RGB(255, 255, 255)); 146 | } 147 | } 148 | else { 149 | if (GetDlgCtrlID((HWND)lParam) == AUX_IP_TOGGLE) { 150 | SetTextColor(hdcStatic, RGB(255, 0, 0)); 151 | } 152 | SetTextColor(hdcStatic, RGB(255, 255, 255)); 153 | } 154 | SetBkColor(hdcStatic, RGB(81, 81, 81)); 155 | return (LONG)grayBrush; 156 | break; 157 | } 158 | case WM_DESTROY: { 159 | PostQuitMessage(WM_QUIT); 160 | return 0; 161 | } 162 | case WM_PAINT: { 163 | hdc = BeginPaint(hwnd, &ps); 164 | EndPaint(hwnd, &ps); 165 | } 166 | case WM_LBUTTONDOWN: { 167 | SCROLLINFO si = { 0 }; 168 | si.cbSize = sizeof(SCROLLINFO); 169 | si.fMask = SIF_POS; 170 | si.nPos = 0; 171 | si.nTrackPos = 0; 172 | GetScrollInfo(hwnd, SB_VERT, &si); 173 | 174 | break; 175 | } 176 | case WM_VSCROLL: { 177 | auto action = LOWORD(wParam); 178 | HWND hScroll = (HWND)lParam; 179 | int pos = -1; 180 | if (action == SB_THUMBPOSITION || action == SB_THUMBTRACK) { 181 | pos = HIWORD(wParam); 182 | } else if (action == SB_LINEDOWN) { 183 | pos = g_scrollY + 30; 184 | } else if (action == SB_LINEUP) { 185 | pos = g_scrollY - 30; 186 | } 187 | if (pos == -1) 188 | break; 189 | WCHAR buf[20]; 190 | SCROLLINFO si = { 0 }; 191 | si.cbSize = sizeof(SCROLLINFO); 192 | si.fMask = SIF_POS; 193 | si.nPos = pos; 194 | si.nTrackPos = 0; 195 | SetScrollInfo(hwnd, SB_VERT, &si, true); 196 | GetScrollInfo(hwnd, SB_VERT, &si); 197 | pos = si.nPos; 198 | POINT pt; 199 | pt.x = 0; 200 | pt.y = pos - g_scrollY; 201 | auto hdc = GetDC(hwnd); 202 | LPtoDP(hdc, &pt, 1); 203 | ReleaseDC(hwnd, hdc); 204 | ScrollWindow(hwnd, 0, -pt.y, NULL, NULL); 205 | g_scrollY = pos; 206 | return 0; 207 | } 208 | case WM_SIZE: { 209 | int yClient = HIWORD(lParam); 210 | int xClient = LOWORD(lParam); 211 | if (wParam != SIZE_RESTORED && wParam != SIZE_MAXIMIZED) 212 | break; 213 | 214 | int x = GetScrollPos(hwnd, SB_VERT); 215 | 216 | SCROLLINFO si = {}; 217 | si.cbSize = sizeof(SCROLLINFO); 218 | 219 | const int bar[] = { SB_HORZ, SB_VERT }; 220 | const int page[] = { LOWORD(lParam), HIWORD(lParam) }; 221 | 222 | for (size_t i = 0; i < ARRAYSIZE(bar); ++i) { 223 | si.fMask = SIF_PAGE; 224 | si.nPage = page[i]; 225 | SetScrollInfo(hwnd, bar[i], &si, TRUE); 226 | 227 | si.fMask = SIF_RANGE | SIF_POS; 228 | GetScrollInfo(hwnd, bar[i], &si); 229 | 230 | const int maxScrollPos = si.nMax - (page[i] - 1); 231 | 232 | const bool scrollRequired = 233 | (si.nPos != si.nMin && si.nPos == maxScrollPos) || 234 | (wParam == SIZE_MAXIMIZED); 235 | 236 | if (scrollRequired) { 237 | scrollClientWindow(hwnd, bar[i], si.nPos); 238 | } 239 | } 240 | break; 241 | } 242 | case WM_MOUSEWHEEL: { 243 | if (((short)HIWORD(wParam)) / 120 > 0) 244 | PostMessage(hwnd, WM_VSCROLL, SB_LINEUP, (LPARAM)0); 245 | if (((short)HIWORD(wParam)) / 120 < 0) 246 | PostMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, (LPARAM)0); 247 | return (0); 248 | break; 249 | } 250 | case WM_GETMINMAXINFO: { 251 | lpMMI->ptMinTrackSize.x = mainWindowWidth; 252 | lpMMI->ptMinTrackSize.y = mainWindowHeight; 253 | } 254 | } 255 | return DefWindowProc(hwnd, msg, wParam, lParam); 256 | } 257 | 258 | void fillGUI(HWND hwnd, SystemInfo *localMachine, int indexOffset) { 259 | createHardwareInfoHolders(hwnd, localMachine->getCurrentInstance(), indexOffset); 260 | populateInfoHolders(localMachine->getCurrentInstance(), hwnd); 261 | 262 | RECT rc = { 0 }; 263 | GetClientRect(hwnd, &rc); 264 | SCROLLINFO si = { 0 }; 265 | si.cbSize = sizeof(SCROLLINFO); 266 | si.fMask = SIF_ALL; 267 | si.nMin = 0; 268 | si.nMax = scrollFullPageHeight; 269 | si.nPage = (rc.bottom - rc.top); 270 | si.nPos = 0; 271 | si.nTrackPos = 0; 272 | SetScrollInfo(hwnd, SB_VERT, &si, true); 273 | 274 | EnumChildWindows(hwnd, 275 | (WNDENUMPROC)SetFont, 276 | (LPARAM)GetStockObject(DEFAULT_GUI_FONT)); //setting the font 277 | } 278 | 279 | BOOL CALLBACK SetFont(HWND child, LPARAM font) { 280 | SendMessage(child, WM_SETFONT, (LPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE); 281 | SendMessage(GetDlgItem(GetParent(child), AUX_IP_TOGGLE), 282 | WM_SETFONT, 283 | (WPARAM)ipToggleBtnFont, MAKELPARAM(true, 0)); 284 | return TRUE; 285 | } 286 | 287 | void loadImages(void) { 288 | for (int x = 0; x < totalItemsCount; x++) { 289 | HICON newIcon = (HICON)LoadImage(ghInstance, 290 | MAKEINTRESOURCE(ICON_IDS[x]), 291 | IMAGE_ICON, 292 | ITEM_ICON_SIZE, 293 | ITEM_ICON_SIZE, 294 | NULL); 295 | iconArr.push_back(newIcon); 296 | } 297 | for (int x = 0; x < iconArrCpuUtilizationIconsSize; x++) { 298 | HICON newIcon = (HICON)LoadImage(ghInstance, 299 | MAKEINTRESOURCE(UTIL_iCON_IDS[x]), 300 | IMAGE_ICON, 301 | ITEM_UTIL_ICON_RENDER_SIZE_WIDTH, 302 | ITEM_UTIL_ICON_RENDER_SIZE_HEIGHT, 303 | NULL); 304 | iconArrCpuUtilizationIcons.push_back(newIcon); 305 | } 306 | int s = 0; 307 | } 308 | 309 | void createHardwareInfoHolders(HWND parent, SystemInfo *info, int offsetIndex) { 310 | if (PROGRAM_INSTANCE == 1) { 311 | CreateWindowEx 312 | ( 313 | 0, 314 | L"Static", 315 | (L"Snapshot as of " + info->getSnapshotGenDateTime()).c_str(), 316 | WS_VISIBLE | 317 | WS_CHILD | 318 | DS_SETFONT | SS_CENTER, 319 | mainWindowWidth / 2 - 200, 320 | 0, 321 | 400, 322 | ITEM_HEIGHT, 323 | parent, 324 | (HMENU)SNAPSHOT_LABEL, 325 | NULL, 326 | NULL 327 | ); 328 | } 329 | UINT32 yStartOffSet = 20; 330 | int xStartOffSetLabel = 80; 331 | int xStartOffSetInformation = xStartOffSetLabel + 25; 332 | //labels + information as a table 333 | for (int x = offsetIndex, y = offsetIndex + INFO_ID_OFFSET, z = offsetIndex + ICON_ID_OFFSET; 334 | x < BIOS_INFO; 335 | x++, y++, z++) { 336 | //icon 337 | CreateWindowEx 338 | ( 339 | 0, 340 | L"Static", 341 | NULL, 342 | WS_VISIBLE | 343 | WS_CHILD | 344 | SS_ICON | SS_CENTER, 345 | xStartOffSetLabel - 28, 346 | yStartOffSet, 347 | ITEM_WIDTH, 348 | ITEM_HEIGHT, 349 | parent, 350 | (HMENU)z, 351 | NULL, 352 | NULL 353 | ); 354 | SendDlgItemMessage(parent, z, 355 | STM_SETICON, 356 | (WPARAM)iconArr.at(x), 357 | NULL); 358 | 359 | //text 360 | CreateWindowEx 361 | ( 362 | 0, 363 | L"Static", 364 | (LPCTSTR)itemStrings[x].c_str(), 365 | WS_VISIBLE | 366 | WS_CHILD | 367 | DS_SETFONT | SS_LEFT, 368 | xStartOffSetLabel, 369 | yStartOffSet, 370 | ITEM_WIDTH, 371 | ITEM_HEIGHT, 372 | parent, 373 | (HMENU)x, 374 | NULL, 375 | NULL 376 | ); 377 | if (x == NETWORK_LABEL) { 378 | createIPToggleControl(parent, xStartOffSetLabel + 140, yStartOffSet); 379 | } 380 | //info 381 | CreateWindowEx( 382 | 0, 383 | L"Static", 384 | (L"Detecting..." + itemStrings[x]).c_str(), 385 | WS_VISIBLE | WS_CHILD | SS_LEFT | DS_SETFONT, 386 | xStartOffSetInformation, 387 | yStartOffSet + 16, 388 | ITEM_INFO_WIDTH, 389 | getInfoBoxItemCount(y, info) * ITEM_INFO_INITIAL_HEIGTH, 390 | parent, 391 | (HMENU)y, 392 | NULL, 393 | NULL 394 | ); 395 | if (y == CPU_INFO) { 396 | glbCpuInfoHolderXoffset = xStartOffSetInformation; 397 | glbCpuInfoHolderYoffset = yStartOffSet + 16; 398 | } 399 | if (y >= GPU_INFO && y < AUDIO_INFO) { 400 | UINT32 listSize = getInfoBoxItemCount(y, info); 401 | //return rec structure 402 | if (listSize >= 2) { 403 | yStartOffSet = adjustItemHeight(parent, y, listSize); 404 | continue; 405 | } 406 | } 407 | 408 | yStartOffSet += (ITEM_HEIGHT + 2); 409 | } 410 | scrollFullPageHeight = yStartOffSet; 411 | 412 | } 413 | 414 | void populateInfoHolders(SystemInfo *currentMachineInfo, HWND mainWindowHwnd) { 415 | TCHAR biosInfo[256] = { 0 }; 416 | _tcscat(biosInfo, currentMachineInfo->getBIOS().c_str()); 417 | 418 | SetWindowText(GetDlgItem(mainWindowHwnd, BIOS_INFO), 419 | biosInfo); 420 | SetWindowText(GetDlgItem(mainWindowHwnd, OS_INFO), 421 | currentMachineInfo->getOS().c_str()); 422 | SetWindowText(GetDlgItem(mainWindowHwnd, CPU_INFO), 423 | currentMachineInfo->getCPU().c_str()); 424 | 425 | HWND cpuInfoHolderHandle = GetDlgItem(mainWindowHwnd, CPU_INFO); 426 | int charLen = GetWindowTextLength(cpuInfoHolderHandle); 427 | if (!PROGRAM_INSTANCE) { 428 | glbCpuInfoHolderXoffset = glbCpuInfoHolderXoffset + charLen * 6; 429 | createCpuUtilizationInfoHolder(mainWindowHwnd, glbCpuInfoHolderXoffset, glbCpuInfoHolderYoffset); 430 | 431 | } 432 | 433 | SetWindowText(GetDlgItem(mainWindowHwnd, MB_INFO), 434 | currentMachineInfo->getMB().c_str()); 435 | SetWindowText(GetDlgItem(mainWindowHwnd, RAM_INFO), 436 | currentMachineInfo->getRAM().c_str()); 437 | 438 | SetWindowText(GetDlgItem(mainWindowHwnd, GPU_INFO), 439 | formListString(currentMachineInfo, 440 | OS_INFO_TYPES::HARDWARE_VIDEO_ADAPTER, 441 | WRITE_OUT_TYPE::APP_WINDOW).c_str()); 442 | SetWindowText(GetDlgItem(mainWindowHwnd, MONITOR_INFO), 443 | formListString(currentMachineInfo, 444 | OS_INFO_TYPES::HARDWARE_DISPLAY, 445 | WRITE_OUT_TYPE::APP_WINDOW).c_str()); 446 | SetWindowText(GetDlgItem(mainWindowHwnd, STORAGE_INFO), 447 | formListString(currentMachineInfo, 448 | OS_INFO_TYPES::HARDWARE_STORAGE, 449 | WRITE_OUT_TYPE::APP_WINDOW).c_str()); 450 | SetWindowText(GetDlgItem(mainWindowHwnd, OPTICAL_INFO), 451 | formListString(currentMachineInfo, 452 | OS_INFO_TYPES::HARDWARE_CDROM, 453 | WRITE_OUT_TYPE::APP_WINDOW).c_str()); 454 | SetWindowText(GetDlgItem(mainWindowHwnd, NETWORK_INFO), 455 | formListString(currentMachineInfo, 456 | OS_INFO_TYPES::HARDWARE_NETWORK, 457 | WRITE_OUT_TYPE::APP_WINDOW).c_str()); 458 | SetWindowText(GetDlgItem(mainWindowHwnd, AUDIO_INFO), 459 | currentMachineInfo->getAudio().c_str()); 460 | if (!PROGRAM_INSTANCE) { 461 | HANDLE threadHandle = (HANDLE)_beginthreadex(0, 0, updateUptime, 0, 0, 0); 462 | HANDLE cpuUtilThreadHandle = (HANDLE)_beginthreadex(0, 0, 463 | updateCpuUtilizationPercentage, 0, 0, 0); 464 | } else { 465 | SetWindowText(GetDlgItem(mainWindowHwnd, UPTIME_INFO), 466 | currentMachineInfo->getUptime().c_str()); 467 | } 468 | } 469 | 470 | unsigned int __stdcall updateUptime(void *t) { 471 | static TCHAR timeBuff[256]; 472 | while (true) { 473 | ZeroMemory(timeBuff, sizeof(timeBuff)); 474 | calculateTimeAndFormat(timeBuff); 475 | BOOL res = SetWindowText(GetDlgItem(mainWindowHwnd, UPTIME_INFO), timeBuff); 476 | Sleep(500); 477 | } 478 | _endthreadex(0); 479 | } 480 | 481 | unsigned int __stdcall updateCpuUtilizationPercentage(void *t) { 482 | 483 | while (true) { 484 | int cpuPercentage = getCpuUsagePercentage(); 485 | if (cpuPercentage != -1) { 486 | currentCpuUsageGlobal = cpuPercentage; 487 | if (cpuPercentage == 0) { 488 | SetWindowText(GetDlgItem(mainWindowHwnd, 489 | AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_STRING), L"IDLE"); 490 | } 491 | else { 492 | SetWindowText(GetDlgItem(mainWindowHwnd, 493 | AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_STRING), 494 | std::to_wstring(cpuPercentage).append(L"%").c_str()); 495 | } 496 | SendDlgItemMessage(mainWindowHwnd, 497 | AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_ICON, 498 | STM_SETICON, 499 | (WPARAM)iconArrCpuUtilizationIcons.at((int)(cpuPercentage / 20)), 500 | NULL); 501 | } 502 | 503 | Sleep(1000); 504 | } 505 | _endthreadex(0); 506 | } 507 | 508 | unsigned int __stdcall playLoadTextAnimation(void *t) { 509 | std::wstring animationCharArr[4] = {L"--", L"\\", L"|", L"/"}; 510 | while (currentCpuUsageGlobal < 0) { 511 | for (const auto &ch : animationCharArr) { 512 | if (currentCpuUsageGlobal >= 0) { 513 | return 0; 514 | } 515 | SetWindowText(GetDlgItem(mainWindowHwnd, 516 | AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_STRING), 517 | ch.c_str()); 518 | Sleep(500); 519 | } 520 | } 521 | return 0; 522 | } 523 | 524 | void createIPToggleControl(HWND parent, int xOff, int yOff) { 525 | CreateWindowEx( 526 | 0, 527 | L"Button", 528 | ipToggleText[0].c_str(), 529 | WS_VISIBLE | WS_CHILD | WS_TABSTOP, 530 | xOff, 531 | yOff, 532 | 64, 533 | 15, 534 | parent, 535 | (HMENU)AUX_IP_TOGGLE, 536 | NULL, 537 | NULL 538 | ); 539 | } 540 | 541 | void createCpuUtilizationInfoHolder(HWND parent, int xOff, int yOff) { 542 | 543 | ControlManager::appCreateControl( 544 | L"Static", 545 | xOff, 546 | yOff, 547 | cpuProgressStringWindowWidthLarge, 548 | cpuProgressStringWindowHeightLarge, 549 | WS_VISIBLE | WS_CHILD | SS_RIGHT | DS_SETFONT, 550 | parent, 551 | AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_STRING, 552 | L"--" 553 | ); 554 | HANDLE cpuLoadTextAnimation = (HANDLE)_beginthreadex(0, 0, 555 | playLoadTextAnimation, 0, 0, 0); 556 | ControlManager::appCreateControl( 557 | L"Static", 558 | xOff + cpuProgressStringWindowWidthLarge + 5, 559 | yOff, 560 | ITEM_UTIL_ICON_RENDER_SIZE_WIDTH, 561 | ITEM_UTIL_ICON_RENDER_SIZE_HEIGHT, 562 | WS_VISIBLE | WS_CHILD | SS_ICON | SS_CENTER, 563 | parent, 564 | AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_ICON 565 | ); 566 | 567 | SendDlgItemMessage(parent, 568 | AUX_CPU_INFO_TOTAL_UTILIZATION_PERCENTAGE_ICON, 569 | STM_SETICON, 570 | (WPARAM)iconArrCpuUtilizationIcons.at(0), 571 | NULL); 572 | 573 | } 574 | 575 | void toggleIpAddress(HWND mainWindow, SystemInfo *info) { 576 | static bool showStatus = 0; 577 | static wstring savedIP; 578 | SetWindowText(GetDlgItem(mainWindow, AUX_IP_TOGGLE), ipToggleText[showStatus].c_str()); 579 | if (info != NULL) { 580 | 581 | if (!showStatus) { 582 | info->getNetworkAdaptersTextRef().back().assign(savedIP); 583 | } else { 584 | savedIP.assign(info->getNetworkAdaptersText().back()); 585 | //hide ip 586 | info->getNetworkAdaptersTextRef().back().clear(); 587 | info->getNetworkAdaptersTextRef().back().assign(L"Connected to the Internet: (IP hidden by user)"); 588 | 589 | } 590 | trimWhiteSpace(info->getNetworkAdaptersTextRef().back()); 591 | updateNetworkAdaptersView(info); 592 | } 593 | showStatus = !showStatus; 594 | } 595 | 596 | void updateNetworkAdaptersView(SystemInfo *currentMachineInfo) { 597 | SetWindowText(GetDlgItem(mainWindowHwnd, NETWORK_INFO), 598 | formListString(currentMachineInfo, 599 | OS_INFO_TYPES::HARDWARE_NETWORK, WRITE_OUT_TYPE::APP_WINDOW).c_str()); 600 | } 601 | 602 | void scrollClientWindow(HWND hwnd, int bar, int pos) { 603 | static int s_prevx = 1; 604 | static int s_prevy = 1; 605 | 606 | int cx = 0; 607 | int cy = 0; 608 | 609 | int& delta = (bar == SB_HORZ ? cx : cy); 610 | int& prev = (bar == SB_HORZ ? s_prevx : s_prevy); 611 | 612 | delta = prev - pos; 613 | prev = pos; 614 | 615 | if (cx || cy) { 616 | ScrollWindow(hwnd, cx, cy, NULL, NULL); 617 | } 618 | } 619 | -------------------------------------------------------------------------------- /SystemInfo/core/sysinfo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "../network/common/network.h" 10 | #include "../glb/globalVars.h" 11 | #include "../core/sysinfo.h" 12 | #include "../core/SystemInfo.h" 13 | #include "../util/utility.h" 14 | #include "../SMBIOS.h" 15 | #include "../mainWindowProcedure.h" 16 | #include "../core/WMIWBEMINFO.h" 17 | #include "../util/controlManager.h" 18 | 19 | //TODO: Conflate fillMB and fillCPU into one procedure since MB uses socket info available on Win32_Processor 20 | 21 | void(*fillInfoFuncs[])(SystemInfo*, HRESULT, IWbemServices*, IWbemLocator*) = 22 | { fillOS, fillCPU, fillMB, fillRAM, fillGPU, fillMonitor, 23 | fillStorage, fillCDROM, fillAudio }; 24 | 25 | 26 | WMIWBEMINFO* wmiWbemInfo = wmiWbemInfo->getWMIWBEMINFOInstance(); 27 | //the actual function that does all the heavy work 28 | int fillSystemInformation(SystemInfo* localMachine) { 29 | fillBIOS(localMachine); 30 | for (int x = 0; x < sizeof(fillInfoFuncs) / sizeof(fillInfoFuncs[0]); x++) { 31 | (*fillInfoFuncs[x])(localMachine, wmiWbemInfo->getHres(), 32 | wmiWbemInfo->getWbemServices(), wmiWbemInfo->getWbemLocator()); 33 | } 34 | 35 | fillNetworkAdapters(localMachine); 36 | fillUptime(localMachine); 37 | 38 | return 0; 39 | } 40 | 41 | void fillCPU(SystemInfo* localMachine, 42 | HRESULT hres, IWbemServices* pSvc, 43 | IWbemLocator* pLoc) { 44 | 45 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_Processor"); 46 | IEnumWbemClassObject* pEnumerator = executeWQLQuery 47 | (hres, pLoc, pSvc, buildQueryString(L"Win32_Processor", queryAttrs)); 48 | IWbemClassObject* pclsObj = NULL; 49 | ULONG uReturn = 0; 50 | 51 | while (pEnumerator) { 52 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 53 | &pclsObj, &uReturn); 54 | 55 | if (0 == uReturn) { 56 | break; 57 | } 58 | 59 | VARIANT vtProp; 60 | 61 | hr = pclsObj->Get(queryAttrs.at((int)WMI_CPU::NAME), 0, &vtProp, 0, 0); 62 | wstring fullCPUString; //name + @clock 63 | wstring maxClock; 64 | double maxClockInGhZ; 65 | uint32_t maxClockInMhZ; 66 | TCHAR maxClockBuff[10]; 67 | wstring processor; 68 | processor = vtProp.bstrVal; 69 | trimNullTerminator(processor); 70 | trimWhiteSpace(processor); 71 | removeTabulation(processor); 72 | condenseSpaces(processor); 73 | if (processor.find(L"@", 0) == string::npos) { 74 | hr = pclsObj->Get(queryAttrs.at((int)WMI_CPU::MAXCLOCK), 0, &vtProp, 0, 0); 75 | maxClockInMhZ = vtProp.uintVal; 76 | maxClockInGhZ = (double)maxClockInMhZ / 1000; 77 | _stprintf(maxClockBuff, _T("%.1lf"), maxClockInGhZ); 78 | maxClock = wstring(maxClockBuff); 79 | fullCPUString = processor + L" @ " + maxClock + L" GHz"; 80 | } 81 | else { 82 | fullCPUString = processor; 83 | } 84 | 85 | localMachine->setCPU(fullCPUString); 86 | 87 | VariantClear(&vtProp); 88 | 89 | pclsObj->Release(); 90 | } 91 | pEnumerator->Release(); 92 | } 93 | 94 | void fillRAM(SystemInfo* localMachine, 95 | HRESULT hres, IWbemServices* pSvc, 96 | IWbemLocator* pLoc) { 97 | 98 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_PhysicalMemory"); 99 | IEnumWbemClassObject* pEnumerator = executeWQLQuery 100 | (hres, pLoc, pSvc, buildQueryString(L"Win32_PhysicalMemory", queryAttrs)); 101 | IWbemClassObject* pclsObj = NULL; 102 | ULONG uReturn = 0; 103 | 104 | while (pEnumerator) { 105 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 106 | &pclsObj, &uReturn); 107 | 108 | if (0 == uReturn) { 109 | break; 110 | } 111 | 112 | VARIANT vtProp; 113 | 114 | // format: gb channel ddr @ mhz (no timings yet) 115 | 116 | wstring clockStr; 117 | UINT32 clock; 118 | UINT16 formFactor; 119 | wstring name; 120 | wstring capacityStr; 121 | wstring formFactorStr; 122 | wstring memoryTypeStr; 123 | UINT16 memoryType; 124 | uint64_t capacity; 125 | double capacityDouble; 126 | TCHAR capacityStrBuff[10]; 127 | TCHAR clockStrBuff[10]; 128 | 129 | capacityStr = getRamBySlot(hres, pSvc, pLoc, queryAttrs); 130 | 131 | hr = pclsObj->Get(queryAttrs.at((int)WMI_RAM::FORMFACTOR), 0, &vtProp, 0, 0); 132 | formFactor = vtProp.uintVal; 133 | formFactorStr = RAMFormFactors[formFactor]; 134 | 135 | hr = pclsObj->Get(queryAttrs.at((int)WMI_RAM::MEMTYPE), 0, &vtProp, 0, 0); 136 | memoryType = vtProp.uintVal; 137 | memoryTypeStr = RAMMemoryTypes[memoryType]; 138 | 139 | hr = pclsObj->Get(queryAttrs.at((int)WMI_RAM::SPEED), 0, &vtProp, 0, 0); 140 | clock = vtProp.uintVal; 141 | _stprintf(clockStrBuff, _T("%d"), clock); 142 | clockStr = wstring(clockStrBuff); 143 | localMachine->setRAM( 144 | capacityStr + 145 | L" GB " + formFactorStr + L" " + 146 | (memoryTypeStr.length() == 0 ? L"" : memoryTypeStr + L" ") + 147 | clockStr + L"MHz"); 148 | 149 | VariantClear(&vtProp); 150 | 151 | pclsObj->Release(); 152 | } 153 | pEnumerator->Release(); 154 | } 155 | 156 | void fillOS(SystemInfo * localMachine, 157 | HRESULT hres, IWbemServices * pSvc, 158 | IWbemLocator * pLoc) { 159 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_OperatingSystem"); 160 | IEnumWbemClassObject* pEnumerator = 161 | executeWQLQuery(hres, pLoc, pSvc, buildQueryString(L"Win32_OperatingSystem", queryAttrs)); 162 | 163 | IWbemClassObject* pclsObj = NULL; 164 | ULONG uReturn = 0; 165 | 166 | while (pEnumerator) { 167 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 168 | &pclsObj, &uReturn); 169 | 170 | if (0 == uReturn) { 171 | break; 172 | } 173 | 174 | VARIANT vtProp; 175 | 176 | hr = pclsObj->Get(queryAttrs.at((int)WMI_OS::NAME), 0, &vtProp, 0, 0); 177 | wstring fullOSstring; 178 | string OSName; 179 | wstring OSArchitecture; 180 | wstring OSNameWide; 181 | 182 | OSNameWide = vtProp.bstrVal; 183 | hr = pclsObj->Get(queryAttrs.at((int)WMI_OS::ARCHITECTURE), 0, &vtProp, 0, 0); 184 | OSArchitecture = vtProp.bstrVal; 185 | int garbageIndex = OSNameWide.find(L"|"); 186 | OSNameWide = OSNameWide.erase(garbageIndex, OSNameWide.length() - garbageIndex); 187 | fullOSstring = OSNameWide + L" " + OSArchitecture; 188 | 189 | localMachine->setOS(fullOSstring); 190 | 191 | VariantClear(&vtProp); 192 | 193 | pclsObj->Release(); 194 | } 195 | pEnumerator->Release(); 196 | } 197 | 198 | void fillMB(SystemInfo * localMachine, 199 | HRESULT hres, IWbemServices * pSvc, 200 | IWbemLocator * pLoc) { 201 | 202 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_BaseBoard"); 203 | IEnumWbemClassObject* pEnumerator = executeWQLQuery 204 | (hres, pLoc, pSvc, buildQueryString(L"Win32_BaseBoard", queryAttrs)); 205 | 206 | IWbemClassObject* pclsObj = NULL; 207 | ULONG uReturn = 0; 208 | 209 | while (pEnumerator) { 210 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 211 | &pclsObj, &uReturn); 212 | 213 | if (0 == uReturn) { 214 | break; 215 | } 216 | 217 | VARIANT vtProp; 218 | 219 | hr = pclsObj->Get(queryAttrs.at((int)WMI_MB::MANUFACTURER), 0, &vtProp, 0, 0); 220 | 221 | wstring manufacturer; 222 | wstring product; 223 | wstring socket; 224 | manufacturer = vtProp.bstrVal; 225 | manufacturer.erase(manufacturer.length()); 226 | trimWhiteSpace(manufacturer); 227 | hr = pclsObj->Get(queryAttrs.at((int)WMI_MB::PRODUCT), 0, &vtProp, 0, 0); 228 | 229 | product = vtProp.bstrVal; 230 | localMachine->setMB(manufacturer + L" " + product + L" (" + getSocket(hres, pSvc, pLoc) + L")"); 231 | 232 | VariantClear(&vtProp); 233 | pclsObj->Release(); 234 | } 235 | pEnumerator->Release(); 236 | } 237 | 238 | void fillGPU(SystemInfo * localMachine, 239 | HRESULT hres, IWbemServices * pSvc, 240 | IWbemLocator * pLoc) { 241 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_VideoController"); 242 | IEnumWbemClassObject* pEnumerator = 243 | executeWQLQuery(hres, pLoc, pSvc, buildQueryString(L"Win32_VideoController", queryAttrs)); 244 | 245 | IWbemClassObject* pclsObj = NULL; 246 | ULONG uReturn = 0; 247 | 248 | while (pEnumerator) { 249 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 250 | &pclsObj, &uReturn); 251 | 252 | if (0 == uReturn) { 253 | break; 254 | } 255 | 256 | VARIANT vtProp; 257 | 258 | hr = pclsObj->Get(queryAttrs.at((int)WMI_GPU::ADAPTER_RAM), 0, &vtProp, 0, 0); 259 | wstring finalAdapterString; 260 | wstring name; 261 | UINT32 vramBytes; 262 | wstring vrammegabytesStr; 263 | TCHAR vRamCharBuff[50]; 264 | double vRAMmegaBytes; 265 | 266 | vramBytes = vtProp.uintVal; 267 | vRAMmegaBytes = (double)vramBytes / pow(1024, 2); 268 | hr = pclsObj->Get(queryAttrs.at((int)WMI_GPU::NAME), 0, &vtProp, 0, 0); 269 | name = vtProp.bstrVal; 270 | name.erase(name.length()); 271 | trimNullTerminator(name); 272 | _stprintf(vRamCharBuff, _T("%.0lf MB"), vRAMmegaBytes); 273 | vrammegabytesStr = wstring(vRamCharBuff); 274 | finalAdapterString = name + L" " + vrammegabytesStr; 275 | 276 | localMachine->addGPUDevice(finalAdapterString); 277 | 278 | VariantClear(&vtProp); 279 | 280 | pclsObj->Release(); 281 | } 282 | pEnumerator->Release(); 283 | } 284 | 285 | void fillMonitor(SystemInfo * localMachine, 286 | HRESULT hres, IWbemServices * pSvc, 287 | IWbemLocator * pLoc) { 288 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_DesktopMonitor"); 289 | IEnumWbemClassObject* pEnumerator = 290 | executeWQLQuery(hres, pLoc, pSvc, buildQueryString(L"Win32_DesktopMonitor", queryAttrs)); 291 | 292 | IWbemClassObject* pclsObj = NULL; 293 | ULONG uReturn = 0; 294 | 295 | while (pEnumerator) { 296 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 297 | &pclsObj, &uReturn); 298 | 299 | if (0 == uReturn) { 300 | break; 301 | } 302 | 303 | VARIANT vtProp; 304 | //Output format: 305 | // (widthxheight@Hz) 306 | wstring finalMonitorString; 307 | wstring monitorName; 308 | wstring resAndFreqStr; 309 | TCHAR resAndFreqBuff[50]; 310 | UINT32 dimensionsAndFrequency[3]; 311 | fillDimensionsAndFrequency(hres, pSvc, pLoc, dimensionsAndFrequency); 312 | hr = pclsObj->Get(queryAttrs.at((int)WMI_MONITOR::NAME), 0, &vtProp, 0, 0); 313 | monitorName = vtProp.bstrVal; 314 | trimNullTerminator(monitorName); 315 | _stprintf(resAndFreqBuff, L"(%dx%d@%dHz)", dimensionsAndFrequency[0], 316 | dimensionsAndFrequency[1], 317 | dimensionsAndFrequency[2]); 318 | resAndFreqStr = wstring(resAndFreqBuff); 319 | finalMonitorString = monitorName + resAndFreqStr; 320 | localMachine->addDisplayDevice(finalMonitorString); 321 | 322 | VariantClear(&vtProp); 323 | 324 | pclsObj->Release(); 325 | } 326 | pEnumerator->Release(); 327 | } 328 | void fillDimensionsAndFrequency(HRESULT hres, 329 | IWbemServices * pSvc, 330 | IWbemLocator * pLoc, UINT * arr) { 331 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_DisplayConfiguration"); 332 | 333 | IEnumWbemClassObject* pEnumerator = 334 | executeWQLQuery(hres, pLoc, pSvc, buildQueryString(L"Win32_DisplayConfiguration", queryAttrs)); 335 | 336 | IWbemClassObject* pclsObj = NULL; 337 | ULONG uReturn = 0; 338 | double accumulatedRAM = 0; 339 | while (pEnumerator) { 340 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 341 | &pclsObj, &uReturn); 342 | 343 | if (0 == uReturn) { 344 | break; 345 | } 346 | 347 | VARIANT vtProp; 348 | 349 | arr[0] = GetSystemMetrics(SM_CXSCREEN); 350 | arr[1] = GetSystemMetrics(SM_CYSCREEN); 351 | hr = pclsObj->Get(queryAttrs.at((int)WMI_DISPLAYCONFIG::NAME), 0, &vtProp, 0, 0); 352 | arr[2] = vtProp.uintVal; 353 | 354 | 355 | VariantClear(&vtProp); 356 | 357 | pclsObj->Release(); 358 | } 359 | pEnumerator->Release(); 360 | } 361 | 362 | 363 | void fillStorage(SystemInfo * localMachine, 364 | HRESULT hres, IWbemServices * pSvc, 365 | IWbemLocator * pLoc) { 366 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_DiskDrive"); 367 | 368 | IEnumWbemClassObject* pEnumerator = 369 | executeWQLQuery(hres, pLoc, pSvc, buildQueryString(L"Win32_DiskDrive", queryAttrs)); 370 | 371 | IWbemClassObject* pclsObj = NULL; 372 | ULONG uReturn = 0; 373 | 374 | while (pEnumerator) { 375 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 376 | &pclsObj, &uReturn); 377 | 378 | if (0 == uReturn) { 379 | break; 380 | } 381 | 382 | VARIANT vtProp; 383 | wstring storageFullString; 384 | wstring manufacturerName; 385 | wstring modelName; 386 | wstring capacityStr; 387 | UINT64 capacityBytes; 388 | wstring capacityGiBStr; 389 | UINT64 capacityGiBDbl; 390 | TCHAR capacity[256]; 391 | hr = pclsObj->Get(queryAttrs.at((int)WMI_DISKDRIVE::CAPTION), 0, &vtProp, 0, 0); 392 | 393 | //product name 394 | modelName = vtProp.bstrVal; 395 | manufacturerName = parseDiskStorageName(modelName); 396 | trimNullTerminator(modelName); 397 | trimWhiteSpace(manufacturerName); 398 | hr = pclsObj->Get(queryAttrs.at((int)WMI_DISKDRIVE::SIZE), 0, &vtProp, 0, 0); 399 | 400 | capacityStr = vtProp.bstrVal; 401 | capacityBytes = stoull(capacityStr); 402 | capacityGiBDbl = capacityBytes / pow(1024, 3); 403 | capacityGiBStr = convertUIntToString(capacityGiBDbl); 404 | 405 | storageFullString = capacityGiBStr + L" GB " + manufacturerName + (manufacturerName == L"" ? L"" : L" ") + modelName; 406 | 407 | localMachine->addStorageMedium(storageFullString); 408 | 409 | VariantClear(&vtProp); 410 | 411 | pclsObj->Release(); 412 | } 413 | pEnumerator->Release(); 414 | } 415 | 416 | void fillCDROM(SystemInfo * localMachine, 417 | HRESULT hres, IWbemServices * pSvc, 418 | IWbemLocator * pLoc) { 419 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_CDROMDrive"); 420 | 421 | IEnumWbemClassObject* pEnumerator = NULL; 422 | pEnumerator = executeWQLQuery(hres, pLoc, pSvc, 423 | buildQueryString(L"Win32_CDROMDrive", queryAttrs)); 424 | 425 | IWbemClassObject* pclsObj = NULL; 426 | ULONG uReturn = 0; 427 | 428 | while (pEnumerator) { 429 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 430 | &pclsObj, &uReturn); 431 | 432 | if (0 == uReturn) { 433 | break; 434 | } 435 | 436 | VARIANT vtProp; 437 | wstring cdRomCaption; 438 | hr = pclsObj->Get(queryAttrs.at((int)WMI_OPTICALDISK::CAPTION), 0, &vtProp, 0, 0); 439 | 440 | cdRomCaption = vtProp.bstrVal; 441 | trimNullTerminator(cdRomCaption); 442 | condenseSpaces(cdRomCaption); 443 | localMachine->addCDROMDevice(cdRomCaption); 444 | 445 | VariantClear(&vtProp); 446 | 447 | pclsObj->Release(); 448 | } 449 | pEnumerator->Release(); 450 | } 451 | 452 | void fillAudio(SystemInfo * localMachine, 453 | HRESULT hres, IWbemServices * pSvc, 454 | IWbemLocator * pLoc) { 455 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_SoundDevice"); 456 | 457 | IEnumWbemClassObject* pEnumerator = NULL; 458 | pEnumerator = 459 | executeWQLQuery(hres, pLoc, pSvc, buildQueryString(L"Win32_SoundDevice", queryAttrs)); 460 | 461 | IWbemClassObject* pclsObj = NULL; 462 | ULONG uReturn = 0; 463 | 464 | while (pEnumerator) { 465 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 466 | &pclsObj, &uReturn); 467 | 468 | if (0 == uReturn) { 469 | break; 470 | } 471 | 472 | VARIANT vtProp; 473 | wstring soundCaption; 474 | hr = pclsObj->Get(queryAttrs.at((int)WMI_SOUND::CAPTION), 0, &vtProp, 0, 0); 475 | 476 | soundCaption = vtProp.bstrVal; 477 | trimNullTerminator(soundCaption); 478 | localMachine->setAudio(soundCaption); 479 | 480 | VariantClear(&vtProp); 481 | 482 | pclsObj->Release(); 483 | } 484 | pEnumerator->Release(); 485 | } 486 | 487 | void fillUptime(SystemInfo * localMachine) { 488 | 489 | wstring uptimeStr; 490 | TCHAR formattedTimeString[256] = { 0 }; 491 | 492 | calculateTimeAndFormat(formattedTimeString); 493 | 494 | uptimeStr = wstring(formattedTimeString); 495 | localMachine->setUptime(uptimeStr); 496 | } 497 | 498 | void fillBIOS(SystemInfo * localMachine) { 499 | DWORD needBufferSize = 0; 500 | TCHAR biosData[256]; 501 | SecureZeroMemory(&biosData, sizeof(biosData)); 502 | const BYTE byteSignature[] = { 'B', 'M', 'S', 'R' }; 503 | const DWORD Signature = *((DWORD*)byteSignature); 504 | LPBYTE pBuff = NULL; 505 | needBufferSize = GetSystemFirmwareTable(Signature, 0, NULL, 0); 506 | pBuff = (LPBYTE)malloc(needBufferSize); 507 | if (pBuff) { 508 | if (GetSystemFirmwareTable(Signature, 0, pBuff, needBufferSize)) { 509 | const PRawSMBIOSData pDMIData = (PRawSMBIOSData)pBuff; 510 | DumpSMBIOSStruct(&(pDMIData->SMBIOSTableData), pDMIData->Length, biosData); 511 | } 512 | else { 513 | GenericMessageOK() 514 | .withMessage(L"Fatal Error. Failed to fetch firmware tables") 515 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 516 | ->display(); 517 | } 518 | } 519 | else { 520 | GenericMessageOK() 521 | .withMessage(L"Fatal Error. Memory allocation failed") 522 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 523 | ->display(); 524 | } 525 | _tcscat(biosData, (wchar_t*)getComputerType().c_str()); 526 | localMachine->setBIOS(biosData); 527 | } 528 | 529 | void fillCPUTemp(SystemInfo * localMachine, 530 | HRESULT hres, IWbemServices * pSvc, 531 | IWbemLocator * pLoc) { 532 | //stub for now 533 | } 534 | 535 | wstring getSocket(HRESULT hres, IWbemServices * pSvc, 536 | IWbemLocator * pLoc) { 537 | wstring socket; 538 | IEnumWbemClassObject* pEnumerator = NULL; 539 | pEnumerator = executeWQLQuery(hres, pLoc, pSvc, bstr_t("SELECT * FROM Win32_Processor")); 540 | 541 | IWbemClassObject* pclsObj = NULL; 542 | ULONG uReturn = 0; 543 | 544 | while (pEnumerator) { 545 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 546 | &pclsObj, &uReturn); 547 | 548 | if (0 == uReturn) { 549 | break; 550 | } 551 | 552 | VARIANT vtProp; 553 | 554 | hr = pclsObj->Get(L"SocketDesignation", 0, &vtProp, 0, 0); 555 | socket = vtProp.bstrVal; 556 | VariantClear(&vtProp); 557 | pclsObj->Release(); 558 | } 559 | pEnumerator->Release(); 560 | return socket; 561 | } 562 | 563 | IEnumWbemClassObject* executeWQLQuery(HRESULT hres, IWbemLocator * pLoc, 564 | IWbemServices * pSvc, BSTR stringQuery) { 565 | IEnumWbemClassObject* pEnumerator = NULL; 566 | hres = pSvc->ExecQuery( 567 | bstr_t("WQL"), 568 | stringQuery, 569 | WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 570 | NULL, 571 | &pEnumerator); 572 | //test this behavior 573 | if (FAILED(hres)) { 574 | GenericMessageOK() 575 | .withMessage(L"Fatal error: Query to operating system failed") 576 | ->withIcon(ControlManager::UI_MESS_RES_ICON::FAILURE) 577 | ->display(); 578 | 579 | pSvc->Release(); 580 | pLoc->Release(); 581 | CoUninitialize(); 582 | } 583 | else { 584 | return pEnumerator; 585 | } 586 | } 587 | 588 | bstr_t buildQueryString(const wchar_t* wmiClass, vector attrs) { 589 | 590 | WCHAR queryString[256] = { 0 }; 591 | wcscpy(queryString, L"SELECT "); 592 | auto it = attrs.begin(); 593 | for (auto it = attrs.begin(); it != attrs.end(); it++) { 594 | wcscat(queryString, *it); 595 | if (!((attrs.end() - it == 1))) { 596 | wcscat(queryString, L", "); 597 | } 598 | } 599 | wcscat(queryString, L" FROM "); 600 | wcscat(queryString, wmiClass); 601 | return bstr_t(queryString); 602 | } 603 | 604 | bstr_t buildQueryString(const wchar_t* wmiClass, 605 | vector attrs, 606 | const wchar_t* whereClause) { 607 | bstr_t mainQuery = buildQueryString(wmiClass, attrs); 608 | bstr_t mainQueryWithWhereClause = mainQuery; 609 | if (whereClause != NULL) { 610 | mainQueryWithWhereClause += SysAllocString(L" WHERE "); 611 | mainQueryWithWhereClause += SysAllocString(whereClause); 612 | } 613 | return mainQueryWithWhereClause; 614 | } 615 | 616 | wstring getComputerType() { 617 | SYSTEM_POWER_CAPABILITIES systemPowerCapabilities; 618 | ZeroMemory(&systemPowerCapabilities, sizeof(systemPowerCapabilities)); 619 | GetPwrCapabilities(&systemPowerCapabilities); 620 | return systemPowerCapabilities.LidPresent 621 | ? 622 | PCType[0] 623 | : 624 | PCType[1]; 625 | } 626 | 627 | wstring getRamBySlot(HRESULT hres, 628 | IWbemServices *pSvc, 629 | IWbemLocator *pLoc, 630 | const vector &queryAttrs) { 631 | 632 | IEnumWbemClassObject* pEnumerator = executeWQLQuery 633 | (hres, pLoc, pSvc, buildQueryString(L"Win32_PhysicalMemory", queryAttrs)); 634 | 635 | IWbemClassObject* pclsObj = NULL; 636 | ULONG uReturn = 0; 637 | 638 | double accumulatedRAM = 0; 639 | while (pEnumerator) { 640 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 641 | &pclsObj, &uReturn); 642 | 643 | if (0 == uReturn) { 644 | break; 645 | } 646 | VARIANT vtProp; 647 | hr = pclsObj->Get(queryAttrs.at((int)WMI_RAM::CAPACITY), 0, &vtProp, 0, 0); 648 | 649 | double cap; 650 | double capacity; 651 | 652 | wstring temp; 653 | TCHAR tempChar[100]; 654 | temp = vtProp.bstrVal; 655 | _tcscpy(tempChar, temp.c_str()); 656 | swscanf(tempChar, L"%lf", &cap); 657 | 658 | cap /= (pow(1024, 3)); 659 | accumulatedRAM += cap; 660 | VariantClear(&vtProp); 661 | } 662 | TCHAR capacityStrBuff[100]; 663 | _stprintf(capacityStrBuff, _T("%.2lf"), accumulatedRAM); 664 | return wstring(capacityStrBuff); 665 | } 666 | 667 | unsigned int getCpuUsagePercentage() { 668 | vector queryAttrs = wmiClassStringsMap.at(L"Win32_PerfFormattedData_PerfOS_Processor"); 669 | IEnumWbemClassObject* pEnumerator = executeWQLQuery 670 | (wmiWbemInfo->getHres(), 671 | wmiWbemInfo->getWbemLocator(), 672 | wmiWbemInfo->getWbemServices(), 673 | buildQueryString(L"Win32_PerfFormattedData_PerfOS_Processor", queryAttrs, L"Name='_Total'")); 674 | 675 | IWbemClassObject* pclsObj = NULL; 676 | ULONG uReturn = 0; 677 | //if -1, then WMI for some reason didn't get the data from the tables 678 | int cpuUsage = -1; 679 | while (pEnumerator) { 680 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 681 | &pclsObj, &uReturn); 682 | 683 | if (0 == uReturn) { 684 | break; 685 | } 686 | 687 | VARIANT vtProp; 688 | 689 | hr = pclsObj->Get(queryAttrs.at((int)WMI_CPU_PERF::PROC_TIME_PERCENTAGE), 0, &vtProp, 0, 0); 690 | 691 | if (WBEM_S_NO_ERROR != hr) { 692 | if (pclsObj) { 693 | VariantClear(&vtProp); 694 | pclsObj->Release(); pclsObj = NULL; 695 | } 696 | throw std::exception("Failed to get info from perf table"); 697 | break; 698 | } 699 | cpuUsage = std::stoi(vtProp.bstrVal); 700 | 701 | VariantClear(&vtProp); 702 | 703 | pclsObj->Release(); pclsObj = NULL; 704 | } 705 | return cpuUsage; 706 | } 707 | 708 | --------------------------------------------------------------------------------