public static ArrayList GetDiskInfo() { try { ManagementClass mc = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc = mc.GetInstances(); ArrayList disk_list = new ArrayList(); foreach (ManagementObject m in moc) { if (m.Properties["Size"].Value != null) { disk_list.Add(new DiskInfo(m.Properties["Caption"].Value.ToString(), m.Properties["InterfaceType"].Value.ToString(), Convert.ToDouble(m.Properties["Size"].Value))); } } mc = null; moc.Dispose(); return(disk_list); } catch (Exception) { return(null); } }
public string getDisk() { string DiskDrive = "硬盘为:"; ManagementClass m = new ManagementClass("win32_DiskDrive");//硬盘 ManagementObjectCollection mn = m.GetInstances(); double capacity = 0.0; foreach (ManagementObject mo1 in mn) { capacity += Int64.Parse(mo1.Properties["Size"].Value.ToString()) / 1024 / 1024 / 1024; } mn.Dispose(); string HDSN = ""; ManagementClass cimobject = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc1 = cimobject.GetInstances(); foreach (ManagementObject mo in moc1) { HDSN = (string)mo.Properties["Model"].Value; } ManagementClass mc1 = new ManagementClass("Win32_PhysicalMedia"); ManagementObjectCollection moc2 = mc1.GetInstances(); string HDID = ""; foreach (ManagementObject mo in moc2) { HDID = mo.Properties["SerialNumber"].Value.ToString().Trim(); break; } return(HDSN + " " + HDID + " " + DiskDrive + capacity.ToString()); }
public static long GetMemoryFree() { switch (Platform.Platformtype) { case Platform.PlatformType.Windows: ManagementClass management = new ManagementClass("Win32_PerfFormattedData_PerfOS_Memory"); ManagementObjectCollection managementObjects = management.GetInstances(); long capacity = 0; foreach (ManagementObject managementObject in managementObjects) { capacity += long.Parse(managementObject.Properties["AvailableBytes"].Value.ToString()); } managementObjects.Dispose(); management.Dispose(); return(capacity); case Platform.PlatformType.Unix: string meminfo = File.ReadAllText("/proc/meminfo"); meminfo = meminfo.Replace(" ", "").Replace("kB", ""); foreach (string item in meminfo.Split('\n')) { string[] pair = item.Split(':'); if (pair[0] == "MemFree") { return(long.Parse(pair[1]) * 1024); } } break; } return(0); }
/// <summary> /// 构造函数 /// </summary> /// <param name="path">path</param> public WMI(string path) { names = new StringDictionary(); mocs = new ArrayList(); try { ManagementClass cimobject = new ManagementClass(path); ManagementObjectCollection moc = cimobject.GetInstances(); bool ok = false; foreach (var mo in moc) { Hashtable o = new Hashtable(); mocs.Add(o); foreach (PropertyData p in mo.Properties) { o.Add(p.Name, p.Value); if (!ok) { names.Add(p.Name, p.Name); } } ok = true; mo.Dispose(); } moc.Dispose(); } catch (Exception e) { throw new Exception(e.Message); } }
protected override void FillFloppyDriveInfo() { ManagementObjectCollection moc = this.GetAllInfo(this.WSql); foreach (ManagementObject mo in moc) { Win32NTLogEvent csp = new Win32NTLogEvent(); if (mo != null) { csp.Category = GetManagementObject <ushort>(mo, "Category"); csp.CategoryString = GetManagementObject <string>(mo, "CategoryString"); csp.ComputerName = GetManagementObject <string>(mo, "ComputerName"); csp.Data = GetManagementObject <byte[]>(mo, "Data"); csp.EventCode = GetManagementObject <ushort>(mo, "EventCode"); csp.EventIdentifier = GetManagementObject <uint>(mo, "EventIdentifier"); csp.EventType = GetManagementObject <byte>(mo, "EventType"); csp.InsertionStrings = GetManagementObject <string[]>(mo, "InsertionStrings"); csp.Logfile = GetManagementObject <string>(mo, "Logfile"); csp.Message = GetManagementObject <string>(mo, "Message"); csp.RecordNumber = GetManagementObject <uint>(mo, "RecordNumber"); csp.SourceName = GetManagementObject <string>(mo, "SourceName"); csp.Cim_TimeGenerated = GetManagementObject <string>(mo, "TimeGenerated"); csp.Cim_TimeWritten = GetManagementObject <string>(mo, "TimeWritten"); csp.Type = GetManagementObject <string>(mo, "Type"); csp.User = GetManagementObject <string>(mo, "User"); ps.Add(csp); } } moc.Dispose(); }
public static string GetLocalIPAddress() { if (string.IsNullOrEmpty(Utils.m_IP)) { ManagementClass managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection instances = managementClass.GetInstances(); using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator()) { while (enumerator.MoveNext()) { ManagementObject managementObject = (ManagementObject)enumerator.Current; if ((bool)managementObject["IPEnabled"]) { string[] array = (string[])managementObject["IPAddress"]; if (array != null && array.Length > 0) { Utils.m_IP = array[0]; break; } } } } instances.Dispose(); managementClass.Dispose(); } return(Utils.m_IP); }
// Token: 0x06000C27 RID: 3111 RVA: 0x000243E0 File Offset: 0x000225E0 private static WmiInstanceClassCollection ParseObjectCollection(ManagementObjectCollection objectCollection) { List <WmiInstanceClass> list = new List <WmiInstanceClass>(); try { foreach (ManagementBaseObject managementBaseObject in objectCollection) { ManagementBaseObject managementBaseObject2 = (ManagementObject)managementBaseObject; List <WmiInstanceProperty> list2 = new List <WmiInstanceProperty>(); foreach (PropertyData propertyData in managementBaseObject2.Properties) { list2.Add(new WmiInstanceProperty(propertyData.Name, propertyData.Value)); } list.Add(new WmiInstanceClass(list2)); } } catch (ManagementException) { return(null); } if (objectCollection != null) { objectCollection.Dispose(); } return(new WmiInstanceClassCollection(list)); }
/// <summary> /// Starts a new instance of the OSInfo class. /// </summary> public OSInfo() { ManagementClass osinfo = new ManagementClass("win32_bootconfiguration"); ManagementObjectCollection moc = osinfo.GetInstances(); foreach (ManagementObject m in moc) { BootDirectory = m.Properties["BootDirectory"].Value.ToString(); ScratchDirectory = m.Properties["ScratchDirectory"].Value.ToString(); TempDirectory = m.Properties["TempDirectory"].Value.ToString(); break; } moc.Dispose(); osinfo.Dispose(); ManagementClass info = new ManagementClass("win32_operatingsystem"); ManagementObjectCollection c = info.GetInstances(); foreach (ManagementObject i in c) { BootDevice = i.Properties["bootdevice"].Value.ToString(); BuildNumber = i.Properties["buildnumber"].Value.ToString(); SystemName = i.Properties["csname"].Value.ToString(); MaxNumberofProcesses = i.Properties["maxnumberofprocesses"].Value.ToString(); MaxProcessMemorySize = i.Properties["maxprocessmemorysize"].Value.ToString(); NumberofProcesses = i.Properties["numberofprocesses"].Value.ToString(); NumberofUsers = i.Properties["numberofusers"].Value.ToString(); OSArchitecture = i.Properties["osarchitecture"].Value.ToString(); SystemDirectory = i.Properties["systemdirectory"].Value.ToString(); SystemDrive = i.Properties["systemdrive"].Value.ToString(); WindowsDirectory = i.Properties["windowsdirectory"].Value.ToString(); break; } c.Dispose(); info.Dispose(); }
/// <summary> /// Starts a new instance of the HardwareInfo class. /// </summary> public HardwareInfo() { ManagementClass processorid = new ManagementClass("win32_processor"); ManagementObjectCollection moc = processorid.GetInstances(); foreach (ManagementObject m in moc) { ProcessorID = m.Properties["processorID"].Value.ToString(); ProcessorClockSpeed = m.Properties["CurrentClockSpeed"].Value.ToString(); ProcessorMaxClockSpeed = m.Properties["MaxClockSpeed"].Value.ToString(); ProcessorName = m.Properties["Name"].Value.ToString(); ProcessorStatus = m.Properties["Status"].Value.ToString(); ProcessorArchitecture = m.Properties["Architecture"].Value.ToString(); break; } moc.Dispose(); processorid.Dispose(); ManagementClass biosinfo = new ManagementClass("win32_bios"); ManagementObjectCollection boc = biosinfo.GetInstances(); foreach (ManagementObject m in boc) { BIOSManufacturer = m.Properties["manufacturer"].Value.ToString(); BIOSName = m.Properties["name"].Value.ToString(); BIOSMajorVersion = m.Properties["systembiosmajorversion"].Value.ToString(); BIOSMinorVersion = m.Properties["systembiosminorversion"].Value.ToString(); break; } boc.Dispose(); biosinfo.Dispose(); }
//public static (int major, int minor, int build) tpGetOSVersion() public static void tpGetOSVersion(out int major, out int minor, out int build) { major = 0; minor = 0; build = 0; ManagementClass mc = new ManagementClass("Win32_OperatingSystem"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { string ver = mo["Version"].ToString(); string[] majorminor = ver.Split(new char[] { '.' }, StringSplitOptions.None); major = Convert.ToInt32(majorminor[0]); minor = Convert.ToInt32(majorminor[1]); build = Convert.ToInt32(mo["BuildNumber"]); break; // 1回ループで終了(でいいよね) } moc.Dispose(); mc.Dispose(); //return result; }
public static IEnumerable <string> GetDriveLetters(ManagementScope scope) { ManagementObjectCollection logicalDisks = WMIUtils.Query(scope, "select * from Win32_logicaldisk"); try { foreach (ManagementObject managementObject1 in logicalDisks) { ManagementObject managementObject = managementObject1; try { if (managementObject1["Name"] != null) { yield return((string)managementObject1["Name"]); } } finally { if (managementObject != null) { managementObject.Dispose(); } } managementObject = (ManagementObject)null; } } finally { if (logicalDisks != null) { logicalDisks.Dispose(); } } logicalDisks = (ManagementObjectCollection)null; }
protected override void FillFloppyDriveInfo() { ManagementObjectCollection moc = this.GetAllInfo(this.WSql); foreach (ManagementObject mo in moc) { Win32Processor csp = new Win32Processor(); if (mo != null) { csp.AddressWidth = GetManagementObject <ushort>(mo, "AddressWidth"); csp.Architecture = GetManagementObject <ushort>(mo, "Architecture"); csp.Availability = GetManagementObject <ushort>(mo, "Availability"); csp.Caption = GetManagementObject <string>(mo, "Caption"); csp.ConfigManagerErrorCode = GetManagementObject <uint>(mo, "ConfigManagerErrorCode"); csp.ConfigManagerUserConfig = GetManagementObject <bool>(mo, "ConfigManagerUserConfig"); csp.CpuStatus = GetManagementObject <ushort>(mo, "CpuStatus"); csp.CreationClassName = GetManagementObject <string>(mo, "CreationClassName"); csp.CurrentClockSpeed = GetManagementObject <uint>(mo, "CurrentClockSpeed"); csp.CurrentVoltage = GetManagementObject <ushort>(mo, "CurrentVoltage"); csp.DataWidth = GetManagementObject <ushort>(mo, "DataWidth"); csp.Description = GetManagementObject <string>(mo, "Description"); csp.DeviceID = GetManagementObject <string>(mo, "DeviceID"); csp.ErrorCleared = GetManagementObject <bool>(mo, "ErrorCleared"); csp.ErrorDescription = GetManagementObject <string>(mo, "ErrorDescription"); csp.ExtClock = GetManagementObject <uint>(mo, "ExtClock"); csp.Family = GetManagementObject <ushort>(mo, "Family"); csp.Cim_InstallDate = GetManagementObject <string>(mo, "InstallDate"); csp.L2CacheSize = GetManagementObject <uint>(mo, "L2CacheSize"); csp.L2CacheSpeed = GetManagementObject <uint>(mo, "L2CacheSpeed"); csp.LastErrorCode = GetManagementObject <uint>(mo, "LastErrorCode"); csp.Level = GetManagementObject <ushort>(mo, "Level"); csp.LoadPercentage = GetManagementObject <ushort>(mo, "LoadPercentage"); csp.Manufacturer = GetManagementObject <string>(mo, "Manufacturer"); csp.MaxClockSpeed = GetManagementObject <uint>(mo, "MaxClockSpeed"); csp.Name = GetManagementObject <string>(mo, "Name"); csp.OtherFamilyDescription = GetManagementObject <string>(mo, "OtherFamilyDescription"); csp.PNPDeviceID = GetManagementObject <string>(mo, "PNPDeviceID"); csp.PowerManagementCapabilities = GetManagementObject <ushort[]>(mo, "PowerManagementCapabilities"); csp.PowerManagementSupported = GetManagementObject <bool>(mo, "PowerManagementSupported"); csp.ProcessorId = GetManagementObject <string>(mo, "ProcessorId"); csp.ProcessorType = GetManagementObject <ushort>(mo, "ProcessorType"); csp.Revision = GetManagementObject <ushort>(mo, "Revision"); csp.Role = GetManagementObject <string>(mo, "Role"); csp.SocketDesignation = GetManagementObject <string>(mo, "SocketDesignation"); csp.Status = GetManagementObject <string>(mo, "Status"); csp.StatusInfo = GetManagementObject <ushort>(mo, "StatusInfo"); csp.Stepping = GetManagementObject <string>(mo, "Stepping"); csp.SystemCreationClassName = GetManagementObject <string>(mo, "SystemCreationClassName"); csp.SystemName = GetManagementObject <string>(mo, "SystemName"); csp.UniqueId = GetManagementObject <string>(mo, "UniqueId"); csp.UpgradeMethod = GetManagementObject <ushort>(mo, "UpgradeMethod"); csp.Version = GetManagementObject <string>(mo, "Version"); csp.VoltageCaps = GetManagementObject <uint>(mo, "VoltageCaps"); ps.Add(csp); } } moc.Dispose(); }
public static String getCpuSerialNumber() { String cpuNo = null; ManagementClass mcpu = null; ManagementObjectCollection mncpu = null; try { mcpu = new ManagementClass("Win32_Processor"); mncpu = mcpu.GetInstances(); foreach (ManagementObject MyObject in mncpu) { cpuNo = MyObject.Properties["ProcessorId"].Value.ToString(); break; } } catch { } finally { if (mncpu != null) { mncpu.Dispose(); } if (mcpu != null) { mcpu.Dispose(); } } return(cpuNo); }
public static ArrayList GetMyNetWorkInfo() { try { ManagementClass mc = new ManagementClass("Win32_NetworkAdapter"); ManagementObjectCollection moc = mc.GetInstances(); ArrayList net_list = new ArrayList(); String Name = ""; String MACAddress = ""; foreach (ManagementObject m in moc) { //物理适配器 if (Convert.ToBoolean(m.Properties["PhysicalAdapter"].Value.ToString())) { if (m.Properties["MACAddress"].Value != null) { Name = m.Properties["Name"].Value.ToString(); MACAddress = m.Properties["MACAddress"].Value.ToString(); //net_list.Add(new NetWorkInfo(Name, MACAddress)); Console.WriteLine("Name:" + Name + " MACAddress:" + MACAddress); } } } mc = null; moc.Dispose(); return(net_list); } catch (Exception) { return(null); } }
/// <summary> /// 此方法根据指定语句通过WMI查询用户指定内容 /// 并且返回 /// </summary> /// <param name="QueryString"></param> /// <param name="Item_Name"></param> /// <returns></returns> public String WMI_Searcher_Service_Ex(String QueryString) { String Result = ""; ManagementObjectSearcher MOS = new ManagementObjectSearcher(QueryString); ManagementObjectCollection MOC = MOS.Get(); foreach (ManagementObject MOB in MOC) { try { Result += MOB["Caption"].ToString() + ","; if (MOB["Started"].ToString() == "True") { Result += "启动中" + ","; } else { Result += "停止中" + ","; } Result += MOB["Description"].ToString() + "||"; } catch (Exception ex) { }; } MOC.Dispose(); MOS.Dispose(); return(Result); }
/// <summary> /// 获取硬盘序列号 /// </summary> public string GetDiskSerialNumber() { //这种模式在插入一个U盘后可能会有不同的结果,如插入我的手机时 String HDid = ""; ManagementClass mc = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { HDid = (string)mo.Properties["Model"].Value; //SerialNumber break; //这名话解决有多个物理盘时产生的问题,只取第一个物理硬盘 } moc.Dispose(); mc.Dispose(); return(HDid); /*ManagementClass mc = new ManagementClass("Win32_PhysicalMedia"); * ManagementObjectCollection moc = mc.GetInstances(); * string str = ""; * foreach (ManagementObject mo in moc) * { * str = mo.Properties["SerialNumber"].Value.ToString(); * break; * } * return str;*/ }
private int __total() //MB単位 { if (NWEnviroment.isWindows()) { float total = 0; ManagementClass mc = new ManagementClass("Win32_OperatingSystem"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { total = (int.Parse(mo["TotalVisibleMemorySize"].ToString()) + int.Parse(mo["TotalVirtualMemorySize"].ToString())) / 1000; } moc.Dispose(); mc.Dispose(); return((int)total); } else { string free = LinuxCommand.execute("free -m"); using (StringReader sr = new StringReader(free)){ string line = ""; while ((line = sr.ReadLine()) != null) { if (line.Contains("-/+")) { string[] parts = Regex.Split(line, @"\s+"); int total = int.Parse(parts[parts.Length - 1]) + int.Parse(parts[parts.Length - 2]); sr.Close(); sr.Dispose(); return(total); } } } } return(0);//TODO: Exception? }
/// <summary> /// 操作系统类型 /// </summary> public string GetSystemName() { string st = ""; try { ManagementClass mc = new ManagementClass("Win32_OperatingSystem"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { try { st = $"{mo["Caption"]}_{mo["OSArchitecture"]}"; } catch (Exception e) { st = $"{mo["Caption"]}"; } } moc.Dispose(); mc.Dispose(); return(st); } catch (Exception e) { Console.WriteLine(e); return(st); } }
/// <summary> /// 此方法调用Windows WMI /// 列举当前电脑所有盘符 /// </summary> public void getLocalDisk() { this.localDiskList = "$GetDir||"; ManagementObjectSearcher MOS = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk"); ManagementObjectCollection MOC = MOS.Get(); foreach (ManagementObject MOB in MOC) { this.localDiskList += MOB["Description"].ToString() + "#" + MOB["Caption"].ToString() + ","; } MOC.Dispose(); MOS.Dispose(); try { //得到硬盘分区列表后,尝试发送 using (NetworkStream Ns = new NetworkStream(this.Lis_socket)) { Ns.Write(Encoding.Default.GetBytes(this.localDiskList), 0, Encoding.Default.GetBytes(this.localDiskList).Length); Ns.Flush(); } } catch (Exception ex) { MessageBox.Show("尝试发送硬盘分区列表失败 : " + ex.Message); } }
protected override void FillFloppyDriveInfo() { ManagementObjectCollection moc = this.GetAllInfo(this.WSql); foreach (ManagementObject mo in moc) { Win32Group csp = new Win32Group(wi); if (mo != null) { csp.Caption = GetManagementObject <string>(mo, "Caption"); csp.Description = GetManagementObject <string>(mo, "Description"); csp.Domain = GetManagementObject <string>(mo, "Domain"); csp.Cim_InstallDate = GetManagementObject <string>(mo, "InstallDate"); csp.LocalAccount = GetManagementObject <bool>(mo, "LocalAccount"); csp.Name = GetManagementObject <string>(mo, "Name"); csp.SID = GetManagementObject <string>(mo, "SID"); csp.SIDType = GetManagementObject <byte>(mo, "SIDType"); csp.Status = GetManagementObject <string>(mo, "Status"); ps.Add(csp); } } moc.Dispose(); }
internal static int GetActiveFirewallRulesCount() { ManagementObjectCollection results = null; ManagementObjectSearcher searcher = null; int count = -1; try { var scope = new ManagementScope("\\\\.\\ROOT\\StandardCimv2"); var q = new ObjectQuery("SELECT * FROM MSFT_NetFirewallRule WHERE Enabled=1"); searcher = new ManagementObjectSearcher(scope, q); results = searcher.Get(); count = results.Count; } catch (ManagementException) { } finally { results?.Dispose(); searcher?.Dispose(); } return(count); }
public StorageGroup(ISettings settings) { if (Software.OperatingSystem.IsUnix) { return; } //https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskdrive var mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); ManagementObjectCollection queryCollection = mosDisks.Get(); // get the results foreach (ManagementBaseObject disk in queryCollection) { string deviceId = (string)disk.Properties["DeviceId"].Value; // is \\.\PhysicalDrive0..n uint idx = Convert.ToUInt32(disk.Properties["Index"].Value); ulong diskSize = Convert.ToUInt64(disk.Properties["Size"].Value); int scsi = Convert.ToInt32(disk.Properties["SCSIPort"].Value); if (deviceId != null) { var instance = AbstractStorage.CreateInstance(deviceId, idx, diskSize, scsi, settings); if (instance != null) { _hardware.Add(instance); } } } queryCollection.Dispose(); mosDisks.Dispose(); }
internal static int GetActiveFirewallRulesCount() { ManagementObjectCollection results = null; ManagementObjectSearcher searcher = null; int count = -1; // This method is not implemented for Linux yet. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { try { var scope = new ManagementScope("\\\\.\\ROOT\\StandardCimv2"); var q = new ObjectQuery("SELECT * FROM MSFT_NetFirewallRule WHERE Enabled=1"); searcher = new ManagementObjectSearcher(scope, q); results = searcher.Get(); count = results.Count; } catch (ManagementException) { } finally { results?.Dispose(); searcher?.Dispose(); } } return(count); }
public WMI(string path) { this.names = new StringDictionary(); this.mocs = new ArrayList(); try { ManagementClass managementClass = new ManagementClass(path); ManagementObjectCollection instances = managementClass.GetInstances(); bool flag = false; using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator()) { while (enumerator.MoveNext()) { ManagementObject managementObject = (ManagementObject)enumerator.Current; Hashtable hashtable = new Hashtable(); this.mocs.Add(hashtable); foreach (PropertyData current in managementObject.Properties) { hashtable.Add(current.Name, current.Value); if (!flag) { this.names.Add(current.Name, current.Name); } } flag = true; managementObject.Dispose(); } } instances.Dispose(); } catch (Exception ex) { throw new Exception(ex.Message); } }
private static WmiClassCollection ParseObjectCollection(ManagementObjectCollection objectCollection) { List <WmiClass> classList = new List <WmiClass>(); try { foreach (ManagementObject obj in objectCollection) { List <WmiProperty> propertyList = new List <WmiProperty>(); foreach (PropertyData property in obj.Properties) { propertyList.Add(new WmiProperty(property.Name, property.Value)); } classList.Add(new WmiClass(propertyList)); } } catch (ManagementException) { return(null); } objectCollection?.Dispose(); return(new WmiClassCollection(classList)); }
public static IEnumerable <IVirtualSystemSettingData> Query(ManagementScope scope, string condition) { string query = "Select * From Msvm_VirtualSystemSettingData"; if (!string.IsNullOrEmpty(condition)) { query = query + " Where " + condition; } ManagementObjectCollection vms = scope.Query(query); try { foreach (ManagementObject instance in vms) { yield return((IVirtualSystemSettingData) new VirtualSystemSettingData(instance)); } } finally { if (vms != null) { vms.Dispose(); } } vms = (ManagementObjectCollection)null; }
public void UpdatePluggedInDevice() { using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBControllerDevice")) { ManagementObjectCollection devices = searcher.Get(); foreach (ManagementBaseObject device in devices) { try { string dependent = (string)device.GetPropertyValue("Dependent"); string devId = dependent.Substring(dependent.IndexOf("DeviceID=\"")); if (devId.Contains("02B0") || devId.Contains("02BB") || devId.Contains("02AE")) { pluggedInDevice = TrackingDevice.Xbox360Kinect; } if (devId.Contains("02C4")) { pluggedInDevice = TrackingDevice.XboxOneKinect; } } catch (ManagementException) { } } devices.Dispose(); } }
public void Dispose() { _data?.Dispose(); _data = null; _searcher?.Dispose(); _searcher = null; }
public static string[] IPAddresses() { ArrayList lst = new ArrayList(); string pcname = WMI.ComputerName(); ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { if ((bool)mo["IPEnabled"] == true) { string[] addresses = mo["IPAddress"] as string[]; if (addresses.Length > 0) { if (!addresses[0].Equals("0.0.0.0")) { lst.Add(addresses[0]); } } } mo.Dispose(); } moc.Dispose(); mc.Dispose(); return(lst.ToArray(typeof(String)) as string[]); }
//内存大小 public static string GetMemerySize() { try { var st = string.Empty; double size = 0; ManagementClass mc = new ManagementClass("Win32_PhysicalMemory"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject m in moc) { if (m.Properties["Capacity"] != null) { size += Convert.ToDouble(m.Properties["Capacity"].Value); } } st = (size / 1024 / 1024 / 1024).ToString("f1") + " GB"; //Console.WriteLine(st); mc = null; moc.Dispose(); return(st); } catch (Exception) { return("unknow"); } }