public static void SystemProcessInfo(string IPOrComputerName) { List <string> list = new List <string>(); list.Add("\n\n\n\n System Process info*************************************************"); ObjectQuery queryProcess = new ObjectQuery("select * from Win32_Process"); var mngObgProcess = WMIConnection.GetWMIManagementObjectCollection(IPOrComputerName, queryProcess); IList <ManagementObject> managementObjectList2 = mngObgProcess.Cast <ManagementObject>().ToList(); //IList<ManagementObject> managementObjectList = mgtObjProcess.Get() // .Cast<ManagementObject>() // .OrderBy(p => Convert.ToUInt32(p.Properties["Index"].Value)) // .ToList(); // Let's just show all the properties for all physical adapters. foreach (ManagementObject mo in managementObjectList2) { foreach (PropertyData pd in mo.Properties) { Console.WriteLine(pd.Name + ": " + (pd.Value ?? "N/A")); list.Add(pd.Name + ": " + (pd.Value ?? "N/A")); } } //Write to file var fileToCreate = Global.OutputDirCustom + "\\" + Global.fileNames[2]; File.WriteAllLines(fileToCreate, list, Encoding.UTF8); Process.Start("notepad.exe", fileToCreate); }
public static PropertyDataCollection GetPropertyValues(WMIConnection WMIConnection, string SelectQuery, string className) { ManagementScope connectionScope = WMIConnection.GetConnectionScope; SelectQuery msQuery = new SelectQuery(SelectQuery); ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(connectionScope, msQuery); try { foreach (ManagementObject item in searchProcedure.Get()) { return(item.Properties); } } catch { /* Do Nothing */ } return(null); }
public static List <ManagementObject> GetAllInstances(WMIConnection WMIConnection, string SelectQuery, string className) { ManagementScope connectionScope = WMIConnection.GetConnectionScope; SelectQuery msQuery = new SelectQuery(SelectQuery); ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(connectionScope, msQuery); List <ManagementObject> instances = new List <ManagementObject>(); try { foreach (ManagementObject instance in searchProcedure.Get()) { instances.Add(instance); } } catch (ManagementException) { /* Do Nothing */ } return(instances); }
public static List <string> GetWMIRunningProcessName(string IPOrComputerName) { List <string> list = new List <string>(); ObjectQuery queryProcessor = new ObjectQuery("SELECT * FROM Win32_Process"); var mngObgColl = WMIConnection.GetWMIManagementObjectCollection(IPOrComputerName, queryProcessor); int i = 1; foreach (ManagementObject obj in mngObgColl) { list.Add("Processes " + i + ": " + (string)obj["Name"]); Console.WriteLine("Processes " + i + ": " + (string)obj["Name"]); i++; } //Write to file list.Sort(); var fileToCreate = Global.OutputDirCustom + "\\" + Global.fileNames[3]; File.WriteAllLines(fileToCreate, list, Encoding.UTF8); Process.Start("notepad.exe", fileToCreate); return(list); }
public static void GetWMIRunningProcessList(string IPOrComputerName) { ManagementScope wmiScope = WMIConnection.GetWMIManagementScope(IPOrComputerName); ObjectQuery queryProcessor = new ObjectQuery("SELECT * FROM Win32_Process"); ManagementObjectSearcher mgtObjProcessor = new ManagementObjectSearcher(wmiScope, queryProcessor); ManagementObjectCollection collection = mgtObjProcessor.Get(); var items = new List <Win32_ProcessModel>(); foreach (ManagementObject obj in collection) { var item = new Win32_ProcessModel(); item.Caption = (string)obj["Caption"]; item.CommandLine = (string)obj["CommandLine"]; item.CreationClassName = (string)obj["CreationClassName"]; item.CreationDate = (DateTime?)obj["CreationDate"]; item.CSCreationClassName = (string)obj["CSCreationClassName"]; item.CSName = (string)obj["CSName"]; item.Description = (string)obj["Description"]; item.ExecutablePath = (string)obj["ExecutablePath"]; item.ExecutionState = (ushort?)obj["ExecutionState"]; item.Handle = (string)obj["Handle"]; item.HandleCount = (uint?)obj["HandleCount"]; item.InstallDate = (DateTime?)obj["InstallDate"]; item.KernelModeTime = (ulong?)obj["KernelModeTime"]; item.MaximumWorkingSetSize = (uint?)obj["MaximumWorkingSetSize"]; item.MinimumWorkingSetSize = (uint?)obj["MinimumWorkingSetSize"]; item.Name = (string)obj["Name"]; item.OSCreationClassName = (string)obj["OSCreationClassName"]; item.OSName = (string)obj["OSName"]; item.OtherOperationCount = (ulong?)obj["OtherOperationCount"]; item.OtherTransferCount = (ulong?)obj["OtherTransferCount"]; item.PageFaults = (uint?)obj["PageFaults"]; item.PageFileUsage = (uint?)obj["PageFileUsage"]; item.ParentProcessId = (uint?)obj["ParentProcessId"]; item.PeakPageFileUsage = (uint?)obj["PeakPageFileUsage"]; item.PeakVirtualSize = (ulong?)obj["PeakVirtualSize"]; item.PeakWorkingSetSize = (uint?)obj["PeakWorkingSetSize"]; item.Priority = (uint?)obj["Priority"]; item.PrivatePageCount = (ulong?)obj["PrivatePageCount"]; item.ProcessId = (uint?)obj["ProcessId"]; item.QuotaNonPagedPoolUsage = (uint?)obj["QuotaNonPagedPoolUsage"]; item.QuotaPagedPoolUsage = (uint?)obj["QuotaPagedPoolUsage"]; item.QuotaPeakNonPagedPoolUsage = (uint?)obj["QuotaPeakNonPagedPoolUsage"]; item.QuotaPeakPagedPoolUsage = (uint?)obj["QuotaPeakPagedPoolUsage"]; item.ReadOperationCount = (ulong?)obj["ReadOperationCount"]; item.ReadTransferCount = (ulong?)obj["ReadTransferCount"]; item.SessionId = (uint?)obj["SessionId"]; item.Status = (string)obj["Status"]; item.TerminationDate = (DateTime?)obj["TerminationDate"]; item.ThreadCount = (uint?)obj["ThreadCount"]; item.UserModeTime = (ulong?)obj["UserModeTime"]; item.VirtualSize = (ulong?)obj["VirtualSize"]; item.WindowsVersion = (string)obj["WindowsVersion"]; item.WorkingSetSize = (ulong?)obj["WorkingSetSize"]; item.WriteOperationCount = (ulong?)obj["WriteOperationCount"]; item.WriteTransferCount = (ulong?)obj["WriteTransferCount"]; items.Add(item); } }
public static void GetServerDetails(string IPOrComputerName) { List <string> list = new List <string>(); try { var PingReply = GetServerPingStatus(IPOrComputerName); if (PingReply.Status == 0) { list.Add(" Server Status*************************************************"); list.Add(" IP Address: " + PingReply.Address); list.Add(" Server Ping Satus: " + PingReply.Status); list.Add("\n\n\n\n Processor info*************************************************"); ObjectQuery queryProcessor = new ObjectQuery("select * from win32_processor"); var mngObgCollProcessor = WMIConnection.GetWMIManagementObjectCollection(IPOrComputerName, queryProcessor); foreach (ManagementObject mObj in mngObgCollProcessor) { list.Add(" Processor Name: " + ProcessorName(mObj)); } list.Add("\n\n\n\n Hard disk info\n*************************************************"); ObjectQuery queryHD = new ObjectQuery("select * from Win32_LogicalDisk where DriveType=3"); var mngObgCollHD = WMIConnection.GetWMIManagementObjectCollection(IPOrComputerName, queryHD); foreach (ManagementObject mObj in mngObgCollHD) { list.Add(" Volume Name: " + GetStorageVolumeName(mObj)); list.Add(" Description: " + GetStorageDescription(mObj)); list.Add(" File system: " + GetStorageFileSystem(mObj)); list.Add(" Available space to current user: "******" Total size of drive: " + GetStorageSize(mObj) + "\n\n"); } list.Add("\n\n\n\n Memory info*************************************************"); ObjectQuery queryOPeratingSystem = new ObjectQuery("select * from Win32_OPeratingSystem"); var mngObgOPeratingSystem = WMIConnection.GetWMIManagementObjectCollection(IPOrComputerName, queryOPeratingSystem); foreach (ManagementObject obj in mngObgOPeratingSystem) { list.Add(" Total Visible Memory Size: " + TotalVisibleMemorySize(obj)); list.Add(" Total Virtual Memory Size: " + TotalVisibleMemorySize(obj)); list.Add(" Free Physical Memory: " + FreePhysicalMemory(obj)); list.Add(" Free Virtual Memory: " + FreeVirtualMemory(obj)); } list.Add("\n\n\n\n System info*************************************************"); foreach (ManagementObject obj in mngObgOPeratingSystem) { list.Add(" Computer Name: " + ComputerName(obj)); list.Add(" Operating System Name: " + OperatingSystemName(obj)); list.Add(" Current Time Zone: " + CurrentTimeZone(obj)); list.Add(" Manufacturer: " + Manufacturer(obj)); list.Add(" OS Architecture: " + OSArchitecture(obj)); list.Add(" OS Language: " + OSLanguage(obj)); list.Add(" Registered User: "******" Serial Number: " + SerialNumber(obj)); list.Add(" System Device: " + SystemDevice(obj)); list.Add(" System Directory: " + SystemDirectory(obj)); list.Add(" System Drive: " + SystemDrive(obj)); list.Add(" Version: " + Version(obj)); list.Add(" Windows Directory: " + WindowsDirectory(obj)); list.Add(" Operating System Install Date: " + OperatingSystemInstallDate(obj)); list.Add(" Operating System Last Boot Up Time: " + OperatingSystemLastBootUpTime(obj)); list.Add(" Operating System Local Date Time: " + OperatingSystemLocalDateTime(obj)); } list.Add("\n\n\n\n Network info*************************************************"); ObjectQuery queryNetworkAdapter = new ObjectQuery(@"SELECT * FROM Win32_NetworkAdapter WHERE Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\%'"); var mngObgNetworkAdapter = WMIConnection.GetWMIManagementObjectCollection(IPOrComputerName, queryNetworkAdapter); IList <ManagementObject> managementObjectList = mngObgNetworkAdapter .Cast <ManagementObject>() .OrderBy(p => Convert.ToUInt32(p.Properties["Index"].Value)) .ToList(); // Let's just show all the properties for all physical adapters. foreach (ManagementObject mo in managementObjectList) { foreach (PropertyData pd in mo.Properties) { Console.WriteLine(pd.Name + ": " + (pd.Value ?? "N/A")); list.Add(pd.Name + ": " + (pd.Value ?? "N/A")); } } //Write to file var fileToCreate = Global.OutputDirCustom + "\\" + Global.fileNames[1]; File.WriteAllLines(fileToCreate, list, Encoding.UTF8); Process.Start("notepad.exe", fileToCreate); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public BaseService(WMIConnection wmiConnection) { _wmiConnection = wmiConnection; }