static string[] GetProcessorNames(WMIService wmiService) { ManagementObject[] collection = wmiService.GetObjects("Select Name From Win32_Processor", true); string[] result = new string[collection.Length]; for (int i = 0; i < collection.Length; i++) { result[i] = (string)collection[i].Properties["Name"].Value; } return(result); }
static int GetFreeHDDSizeGB(WMIService wmiService) { ManagementObject[] collection = wmiService.GetObjects("Select FreeSpace From Win32_LogicalDisk ", false); UInt64 size = 0; for (int i = 0; i < collection.Length; i++) { PropertyData pData = collection[i].Properties["FreeSpace"]; size += ((pData != null && pData.Value != null) ? (UInt64)pData.Value : 0u); } return((int)(size >> 30)); }
static PerfomanceInfo_OS[] GetPerfomanceInfo_OS(WMIService wmiService) { ManagementObject[] collection = wmiService.GetObjects( "SELECT Name,Processes,Threads " + "FROM Win32_PerfFormattedData_PerfOS_System", false ); PerfomanceInfo_OS[] result = new PerfomanceInfo_OS[collection.Length]; for (int i = 0; i < collection.Length; i++) { result[i] = new PerfomanceInfo_OS( (string)collection[i].Properties["Name"].Value, (int)(UInt32)collection[i].Properties["Processes"].Value, (int)(UInt32)collection[i].Properties["Threads"].Value ); } return(result); }
static PerfomanceInfo_CPU[] GetPerfomanceInfo_CPU(WMIService wmiService) { ManagementObject[] collection = wmiService.GetObjects( "SELECT Name,PercentProcessorTime,PercentPrivilegedTime,PercentUserTime " + "FROM Win32_PerfFormattedData_PerfOS_Processor " + "WHERE Name=\'_Total\'", false ); PerfomanceInfo_CPU[] result = new PerfomanceInfo_CPU[collection.Length]; for (int i = 0; i < collection.Length; i++) { result[i] = new PerfomanceInfo_CPU( (string)collection[i].Properties["Name"].Value, (float)(UInt64)collection[i].Properties["PercentProcessorTime"].Value, (float)(UInt64)collection[i].Properties["PercentPrivilegedTime"].Value, (float)(UInt64)collection[i].Properties["PercentUserTime"].Value ); } return(result); }
static string GetOSName(WMIService wmiService) { ManagementObject[] collection = wmiService.GetObjects("Select Caption From Win32_OperatingSystem", true); return((collection.Length == 1) ? (string)collection[0].Properties["Caption"].Value : string.Empty); }
static int GetFreeMemorySizeMB(WMIService wmiService) { ManagementObject[] collection = wmiService.GetObjects("Select FreePhysicalMemory From Win32_OperatingSystem", false); return((collection.Length == 1) ? (int)((UInt64)collection[0].Properties["FreePhysicalMemory"].Value / 1024) : 4096); }
static int GetTotalMemorySizeMB(WMIService wmiService) { ManagementObject[] collection = wmiService.GetObjects("Select TotalVisibleMemorySize From Win32_OperatingSystem", true); return((collection.Length == 1) ? (int)((UInt64)collection[0].Properties["TotalVisibleMemorySize"].Value / 1024) : 4096); }
static void worker_DoWork(object sender, DoWorkEventArgs e) { wmiService = WMIService.GetInstance(null); }