当前位置: 首页>>代码示例>>C#>>正文


C# ManagementClass.GetInstances方法代码示例

本文整理汇总了C#中System.Management.ManagementClass.GetInstances方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementClass.GetInstances方法的具体用法?C# ManagementClass.GetInstances怎么用?C# ManagementClass.GetInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementClass的用法示例。


在下文中一共展示了ManagementClass.GetInstances方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ViewModel

        public ViewModel()
        {
            mgt = new ManagementClass("Win32_Processor");
            procs = mgt.GetInstances();

            CPU = new ObservableCollection<Model>();
            timer = new DispatcherTimer();
            random = new Random();
            time = DateTime.Now;
            cpuCounter = new PerformanceCounter();
            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName = "% Processor Time";
            cpuCounter.InstanceName = "_Total";
            ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            ProcessorID = GetProcessorID();
            processes = Process.GetProcesses();
            Processes = processes.Length;
            MaximumSpeed = GetMaxClockSpeed();
            LogicalProcessors = GetNumberOfLogicalProcessors();
            Cores = GetNumberOfCores();
            L2Cache = GetL2CacheSize();
            L3Cache = GetL3CacheSize();
            foreach (ManagementObject item in procs)
                L1Cache = ((UInt32)item.Properties["L2CacheSize"].Value / 2).ToString() + " KB";

            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += timer_Tick;
            timer.Start();
            for (int i = 0; i < 60; i++)
            {
                CPU.Add(new Model(time, 0,0));
                time = time.AddSeconds(1);
            }
        }
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:34,代码来源:ViewModel.cs

示例2: GetSystemUniqueSerial

        private string GetSystemUniqueSerial()
        {
            try
            {
                string wmiClass = "Win32_DiskDrive";
                string wmiProperty = "SerialNumber";

                ManagementClass mc = new ManagementClass(wmiClass);
                ManagementObjectCollection moc = mc.GetInstances();

                foreach (ManagementObject mo in moc)
                {
                    string serialNumber = mo[wmiProperty].ToString().Trim();
                    if (!string.IsNullOrEmpty(serialNumber))
                    {
                        return serialNumber;
                    }
                }
            }
            catch (Exception exp)
            {
                Logger.Log(exp, "");
                return "";
            }

            return "";
        }
开发者ID:Ashna,项目名称:ShayanDent,代码行数:27,代码来源:FrmUpdate.cs

示例3: GetUncPath

        private static string GetUncPath(string path)
        {
            string uncPath = string.Empty;
            using (ManagementClass managementClass = new ManagementClass("Win32_Share"))
            {
                foreach (ManagementObject item in managementClass.GetInstances())
                {
                    if (item.Properties["Path"].Value.ToString().Trim() == "" | item.Properties["Name"].Value.ToString().EndsWith("$") == true)
                        continue;
                    if (path.StartsWith(item.Properties["Path"].Value.ToString(), StringComparison.CurrentCultureIgnoreCase) == true)
                    {
                        uncPath = @"\\" + Environment.MachineName + @"\";
                        uncPath += item.Properties["Name"].Value;
                        uncPath += path.Substring(item.Properties["Path"].Value.ToString().Length);
                        break;
                    }

                }
            }
            if (string.IsNullOrEmpty(uncPath))
            {
                throw new IOException("No unc path found for path");
            }
            return uncPath;
        }
开发者ID:dot-i,项目名称:ARGUS-TV-Clients,代码行数:25,代码来源:Process.cs

示例4: GetIPAddress

 /// <summary>
 ///����ȡIP��ַ
 /// </summary>
 /// <returns></returns>
 public static string GetIPAddress()
 {
     try
     {
         string st = string.Empty;
         ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection moc = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             if ((bool)mo["IPEnabled"] == true)
             {
                 System.Array ar = null;
                 ar = (System.Array)(mo.Properties["IpAddress"].Value);
                 st = ar.GetValue(0).ToString();
                 break;
             }
         }
         moc = null;
         mc = null;
         return st;
     }
     catch
     {
         return "0";
     }
     finally
     {
     }
 }
开发者ID:wxanywhere,项目名称:WX_DEMO,代码行数:33,代码来源:VO_SYS_HEAD.cs

示例5: SendInstallData

        private static void SendInstallData(string error)
        {
            try
            {
                using (var client = new WebClient())
                {
                    var data = new NameValueCollection();
                    data.Add("error", error);
                    data.Add("computername", SystemInformation.ComputerName);

                    using (var mgmt = new ManagementClass("Win32_OperatingSystem"))
                    {
                        try
                        {
                            foreach (ManagementObject mgmtObj in mgmt.GetInstances())
                            {
                                // Just get first value.
                                data.Add("os", mgmtObj["Caption"].ToString().Trim());
                                break;
                            }
                        }
                        catch { }
                        var result = System.Text.Encoding.Default.GetString(client.UploadValues("http://www.filmkhoj.com/api/install", data));
                    }
                }
            }
            catch { }
        }
开发者ID:huoxudong125,项目名称:VideoSearch,代码行数:28,代码来源:EthicalRestartForm.cs

示例6: identifier

 //Return a hardware identifier
 private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
 {
     string result = "";
     System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
     System.Management.ManagementObjectCollection moc = mc.GetInstances();
     foreach (System.Management.ManagementObject mo in moc)
     {
         if (mo[wmiMustBeTrue].ToString() == "True")
         {
             //Only get the first one
             if (result == "")
             {
                 try
                 {
                     result = mo[wmiProperty].ToString();
                     break;
                 }
                 catch
                 {
                 }
             }
         }
     }
     return result;
 }
开发者ID:RFranta,项目名称:UVDLPSlicerController,代码行数:26,代码来源:FingerPrint.cs

示例7: Shutdown

        public static void Shutdown(string mode)
        {
            if (mode == "WMI")
            {
                ManagementBaseObject mboShutdown = null;
                ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
                mcWin32.Get();

                // Get Security Privilages
                mcWin32.Scope.Options.EnablePrivileges = true;
                ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");

                //Option Flags
                mboShutdownParams["Flags"] = "1";
                mboShutdownParams["Reserved"] = "0";
                foreach (ManagementObject manObj in mcWin32.GetInstances())
                {
                    mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
                }
            }
            else if (mode == "Core")
            {
                Process.Start("shutdown", "/s /t 0");
            }
        }
开发者ID:Porterbg,项目名称:Freeflex,代码行数:25,代码来源:Core.cs

示例8: GetMacAddress

 /// <summary>
 /// 获取网卡地址
 /// </summary>
 /// <returns></returns>
 public static string GetMacAddress()
 {
     try
     {
         //获取网卡硬件地址
         string mac = "";
         ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection moc = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             if ((bool)mo["IPEnabled"] == true)
             {
                 mac = mo["MacAddress"].ToString();
                 break;
             }
         }
         moc = null;
         mc = null;
         return mac;
     }
     catch
     {
         return "unknow";
     }
     finally
     {
     }
 }
开发者ID:cityjoy,项目名称:CommonToolkit,代码行数:32,代码来源:ComputerHelper.cs

示例9: GetCPUProperties

        /// <summary>
        /// 获取 CPU 属性参数
        /// </summary>
        /// <returns>返回 CPU 属性参数</returns>
        public static string GetCPUProperties()
        {
            // Get the WMI class
            ManagementClass c = new ManagementClass(new ManagementPath("Win32_Processor"));
            // Get the properties in the class
            ManagementObjectCollection moc = c.GetInstances();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            // display the properties
            sb.AppendLine("Property Names: ");
            sb.AppendLine("=================");
            foreach (ManagementObject mo in moc)
            {
                PropertyDataCollection properties = mo.Properties;
                //获取内核数代码
                sb.AppendLine("物理内核数:" + properties["NumberOfCores"].Value);
                sb.AppendLine("逻辑内核数:" + properties["NumberOfLogicalProcessors"].Value);
                //其他属性获取代码
                foreach (PropertyData property in properties)
                {
                    sb.AppendLine(property.Name + ":" + property.Value);
                }
            }
            string s = sb.ToString();
            return s;
        }
开发者ID:cheehwasun,项目名称:BaiduPCS_NET,代码行数:30,代码来源:Utils.cs

示例10: GetMACAddress

 public static string GetMACAddress()
 {
     ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
     ManagementObjectCollection moc = mc.GetInstances();
     string MACAddress = string.Empty;
     try
     {
         ManagementObjectCollection.ManagementObjectEnumerator enumerator = moc.GetEnumerator();
         while (enumerator.MoveNext())
         {
             ManagementObject mo = (ManagementObject)enumerator.Current;
             if (Operators.CompareString(MACAddress, string.Empty, false) == 0 && Conversions.ToBoolean(mo["IPEnabled"]))
             {
                 MACAddress = mo["MacAddress"].ToString();
             }
             mo.Dispose();
         }
     }
     finally
     {
         ManagementObjectCollection.ManagementObjectEnumerator enumerator;
         if (enumerator != null)
         {
             ((IDisposable)enumerator).Dispose();
         }
     }
     MACAddress = MACAddress.Replace(":", "");
     return MACAddress;
 }
开发者ID:khaha2210,项目名称:CodeNewTeam,代码行数:29,代码来源:Class1.cs

示例11: GetCPUId

 public static string GetCPUId()
 {
     string cpuInfo = string.Empty;
     string temp = string.Empty;
     ManagementClass mc = new ManagementClass("Win32_Processor");
     ManagementObjectCollection moc = mc.GetInstances();
     try
     {
         ManagementObjectCollection.ManagementObjectEnumerator enumerator = moc.GetEnumerator();
         while (enumerator.MoveNext())
         {
             ManagementObject mo = (ManagementObject)enumerator.Current;
             if (Operators.CompareString(cpuInfo, string.Empty, false) == 0)
             {
                 cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
             }
         }
     }
     finally
     {
         ManagementObjectCollection.ManagementObjectEnumerator enumerator;
         if (enumerator != null)
         {
             ((IDisposable)enumerator).Dispose();
         }
     }
     return cpuInfo;
 }
开发者ID:khaha2210,项目名称:CodeNewTeam,代码行数:28,代码来源:Class1.cs

示例12: query_Click

        private void query_Click(object sender, EventArgs e)
        {
            if (string.Empty.Equals(queryClass.Text.Trim()) || string.Empty.Equals(queryProperty.Text.Trim()))
            {
                MessageBox.Show("Class and property need to be specified.", "Error");
                return;
            }
            if (!queryClass.Items.Contains(queryClass.Text))
                queryClass.Items.Add(queryClass.Text);
            if (!queryProperty.Items.Contains(queryProperty.Text))
                queryProperty.Items.Add(queryProperty.Text);

            ManagementClass mc = new System.Management.ManagementClass(queryClass.Text);
            ManagementObjectCollection moc = mc.GetInstances();
            string value = string.Empty;
            foreach (System.Management.ManagementObject mo in moc)
            {
                try
                {
                    value = mo[queryProperty.Text].ToString();
                    log.AppendText(string.Format("{0}.{1}=\"{2}\"{3}", queryClass.Text, queryProperty.Text, value, Environment.NewLine));
                }
                catch
                {
                }
            }
        }
开发者ID:tewarid,项目名称:NetWmiQuery,代码行数:27,代码来源:WmiQueryForm.cs

示例13: SetGateway

        public static void SetGateway(string gateway)
        {
            //!++     как именно работает данный участок кода я не знаю,
            //!++    но знаю, что он успешно переключает основной шлюз сетевого подключения

            //!++    начало кода покрытого мраком

            ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection objMOC = objMC.GetInstances();

            foreach (ManagementObject objMO in objMOC)
            {
                if ((bool)objMO["IPEnabled"])
                {
                    try
                    {
                        ManagementBaseObject setGateway;
                        ManagementBaseObject newGateway =
                            objMO.GetMethodParameters("SetGateways");

                        newGateway["DefaultIPGateway"] = new string[] { gateway };
                        newGateway["GatewayCostMetric"] = new int[] { 1 };

                        setGateway = objMO.InvokeMethod("SetGateways", newGateway, null);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }

            //!++   конец кода покрытого мраком!
        }
开发者ID:sivatorov,项目名称:rcc,代码行数:34,代码来源:f_main.cs

示例14: showSpec

        public string showSpec()
        {
            String msg = "";

            mc = new ManagementClass("Win32_OperatingSystem");
            foreach (ManagementObject mo in mc.GetInstances())
            {

                msg += String.Format("Phisical Memory = {0} MBytes\n", (ulong)(mo["TotalVisibleMemorySize"]) / 1024);
                msg += String.Format("Locale = {0} {1}\n", mo["Locale"], mo["LocalDateTime"]);
            }

            mc = new ManagementClass("Win32_Processor");
            foreach (ManagementObject mo in mc.GetInstances())
            {
                msg += String.Format("{0}, {1}MHz, {2} cores\n", mo["Name"], mo["CurrentClockSpeed"], mo["NumberOfCores"]);
                msg += "Architecture/Family = " + architecture[(ushort)mo["Architecture"]] + " ";
                msg += String.Format("{0}\n", family[(ushort)mo["Family"]]);
                msg += "Caption = " + mo["Caption"] + "\n";
                msg += String.Format("DataWidth = {0} bits", mo["DataWidth"]);

            }

            return msg;
        }
开发者ID:masaakif,项目名称:PerfLog,代码行数:25,代码来源:Program.cs

示例15: GetDnsServers

        public IPAddress[] GetDnsServers()
        {
            var mgmt = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection objCol = mgmt.GetInstances();

            //we may have more than one network adapter, each configured with dns servers.
            //we need to order the dns servers by the adapters IPConnectionMetric, which is the preferred order for querying against.
            var dnsHostsByConnectionMetric = new SortedList<UInt32, List<IPAddress>>();

            foreach (ManagementObject obj in objCol) {
                if ((bool) obj["IPEnabled"]) {
                    var connectionMetric = ((UInt32) obj["IPConnectionMetric"]);
                    var dnsItems = (string[]) obj["DNSServerSearchOrder"];
                    if (dnsItems != null && dnsItems.Length > 0) {
                        var ipAddresses = new List<IPAddress>();
                        foreach (string dns in dnsItems) {
                            ipAddresses.Add(IPAddress.Parse(dns));
                        }
                        dnsHostsByConnectionMetric.Add(connectionMetric, ipAddresses);
                    }
                }
                obj.Dispose();
            }
            if(dnsHostsByConnectionMetric.Count == 0) {
                return null;
            }
            var dnsHosts = new List<IPAddress>();
            foreach (KeyValuePair<uint, List<IPAddress>> item in dnsHostsByConnectionMetric) {
                dnsHosts.AddRange(item.Value);
            }
            return dnsHosts.ToArray();
        }
开发者ID:Andrea,项目名称:nxmpp,代码行数:32,代码来源:WmiDnsServerLookup.cs


注:本文中的System.Management.ManagementClass.GetInstances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。