public Memory GetMemory() { try { Log.WriteStart("GetMemory"); Memory memory = new Memory(); WmiHelper wmi = new WmiHelper("root\\cimv2"); ManagementObjectCollection objOses = wmi.ExecuteQuery("SELECT * FROM Win32_OperatingSystem"); foreach (ManagementObject objOs in objOses) { memory.FreePhysicalMemoryKB = UInt64.Parse(objOs["FreePhysicalMemory"].ToString()); memory.TotalVisibleMemorySizeKB = UInt64.Parse(objOs["TotalVisibleMemorySize"].ToString()); memory.TotalVirtualMemorySizeKB = UInt64.Parse(objOs["TotalVirtualMemorySize"].ToString()); memory.FreeVirtualMemoryKB = UInt64.Parse(objOs["FreeVirtualMemory"].ToString()); } Log.WriteEnd("GetMemory"); return(memory); } catch (Exception ex) { Log.WriteError("GetMemory", ex); throw; } }
/// <summary> /// Supports managed resources disposal /// </summary> /// <param name="zoneName"></param> private void DeleteSoaRecord(string zoneName) { string query = String.Format("SELECT * FROM MicrosoftDNS_SOAType " + "WHERE OwnerName = '{0}'", zoneName); using (ManagementObjectCollection objRRs = wmi.ExecuteQuery(query)) { foreach (ManagementObject objRR in objRRs) { using (objRR) objRR.Delete(); } } }
public void RebootSystem() { try { Log.WriteStart("RebootSystem"); WmiHelper wmi = new WmiHelper("root\\cimv2"); ManagementObjectCollection objOses = wmi.ExecuteQuery("SELECT * FROM Win32_OperatingSystem"); foreach (ManagementObject objOs in objOses) { objOs.Scope.Options.EnablePrivileges = true; objOs.InvokeMethod("Reboot", null); } Log.WriteEnd("RebootSystem"); } catch (Exception ex) { Log.WriteError("RebootSystem", ex); throw; } }
public WindowsProcess[] GetWindowsProcesses() { try { Log.WriteStart("GetWindowsProcesses"); List <WindowsProcess> winProcesses = new List <WindowsProcess>(); WmiHelper wmi = new WmiHelper("root\\cimv2"); ManagementObjectCollection objProcesses = wmi.ExecuteQuery( "SELECT * FROM Win32_Process"); foreach (ManagementObject objProcess in objProcesses) { int pid = Int32.Parse(objProcess["ProcessID"].ToString()); string name = objProcess["Name"].ToString(); // get user info string[] methodParams = new String[2]; objProcess.InvokeMethod("GetOwner", (object[])methodParams); string username = methodParams[0]; WindowsProcess winProcess = new WindowsProcess(); winProcess.Pid = pid; winProcess.Name = name; winProcess.Username = username; winProcess.MemUsage = Int64.Parse(objProcess["WorkingSetSize"].ToString()); winProcesses.Add(winProcess); } Log.WriteEnd("GetWindowsProcesses"); return(winProcesses.ToArray()); } catch (Exception ex) { Log.WriteError("GetWindowsProcesses", ex); throw; } }
public virtual bool SiteExists(string siteId) { return(wmi.ExecuteQuery( String.Format("SELECT * FROM IIsFtpServerSetting WHERE Name='{0}'", siteId)).Count > 0); }