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


C# ManagementObjectSearcher.Get方法代码示例

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


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

示例1: RAM

        public RAM()
        {
            int counter = 0;
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PhysicalMemory");

            ManagementObjectCollection searchList = searcher.Get();

            this.numModules = searcher.Get().Count;
            this.installedRAM = new RAM[numModules];

            foreach (ManagementObject mo in searchList)
            {
                installedRAM[counter] = new RAM(counter);
                try
                {
                    installedRAM[counter].SetManufacturer(mo["manufacturer"].ToString().Trim());
                }
                catch (Exception e)
                {
                    installedRAM[counter].SetManufacturer("none");
                }

                try
                {
                    installedRAM[counter].SetModel(mo["partnumber"].ToString().Trim());
                }
                catch (Exception e)
                {
                    installedRAM[counter].SetModel("none");
                }

                try
                {
                    installedRAM[counter].SetID(mo["serialnumber"].ToString().Trim());
                }
                catch (Exception e)
                {
                    installedRAM[counter].SetID("none");
                }

                try
                {
                    installedRAM[counter].speed = mo["speed"].ToString().Trim() + "MHz";
                }
                catch (Exception e)
                {
                    installedRAM[counter].speed = "none";
                }

                try
                {
                    installedRAM[counter].moduleSize = long.Parse(mo["capacity"].ToString().Trim()) / 1048576;
                }
                catch (Exception e)
                {
                    installedRAM[counter].moduleSize = 0;
                }
                counter++;
            }
        }
开发者ID:GavinKenna,项目名称:Muroidea,代码行数:60,代码来源:RAM.cs

示例2: GetUsbInformation

        // USBメモリのベンダー名、シリアル番号を取得する
        public Dictionary<string, string> GetUsbInformation()
        {
            Dictionary<string, string> usbInformations = new Dictionary<string, string>();
            ManagementObjectSearcher mosUsb = new ManagementObjectSearcher(
                "root\\CIMV2",
                "SELECT * FROM Win32_DiskDrive WHERE InterfaceType = 'USB'"
            );
            try {
                if (mosUsb.Get().Count > 0) {
                    foreach (ManagementObject queryObj in mosUsb.Get()) {
                        // PNPDeviceIDに含まれるベンダー情報とシリアル番号を取得するため
                        // &区切りで配列に切り出す必要がある
                        string pnpDeviceId      = queryObj["PNPDeviceID"].ToString();
                        string[] arrPnpDeviceId = pnpDeviceId.Split('&');
                        // ベンダー情報とシリアル番号を変数へ格納
                        string usbVendorName = arrPnpDeviceId[1].Substring(4);
                        string usbSerialNo   = arrPnpDeviceId[3];

                        usbInformations.Add("usbVendorName", usbVendorName);
                        usbInformations.Add("usbSerialNo"  , usbSerialNo);
                    }
                }
            } catch (ManagementException manageExc) {
                DispException(manageExc);
            }

            return usbInformations;
        }
开发者ID:tomoyashibata,项目名称:UsbLogger,代码行数:29,代码来源:Mos.cs

示例3: CheckMSHyperV

        public void CheckMSHyperV()
        {
            try
            {
                ObjectQuery MyobjectQuery = null;
                //query for "Win32_Processor" class under WMI
                MyobjectQuery = new ObjectQuery("select * from Win32_BaseBoard");

                //searcher is what runs the query, set the Query object as a parameter        
                ManagementObjectSearcher MySearcher = new ManagementObjectSearcher(MyobjectQuery);
                foreach (ManagementObject Mgmt in MySearcher.Get())
                {
                    foreach (ManagementObject SubMgmt in MySearcher.Get())
                    {
                        string manuf = (SubMgmt["Manufacturer"].ToString());
                        manuf = manuf.ToLower();
                        if (manuf.IndexOf("microsoft") != -1)
                        {
                            bIsHyperV = true;
                        }
                    }
                }

                lock (lockObj)
                {
                    Monitor.Pulse(lockObj);
                }
            }
            catch (Exception)
            {
                bIsHyperV = false;
            }
        }
开发者ID:javithalion,项目名称:NCache,代码行数:33,代码来源:MSHyperVThread.cs

示例4: NIC

        private long KBytesTotal = 0; //Current MBytes Per Second Total

        #endregion Fields

        #region Constructors

        public NIC()
        {
            int counter = 0;
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface");

            this.NICS = new NIC[searcher.Get().Count];

            ManagementObjectCollection searchList = searcher.Get();

            foreach (ManagementObject mo in searchList)
            {
                this.NICS[counter] = new NIC(mo["Name"].ToString().Trim());
                try
                {
                    this.NICS[counter].SetManufacturer(mo["Name"].ToString().Split(' ')[0]);
                }
                catch(Exception ex)
                {
                    this.NICS[counter].SetManufacturer(mo["Name"].ToString().Trim());
                }
                try
                {
                    this.NICS[counter].SetID(mo["Name"].ToString().Split(' ')[1]);
                }
                catch (Exception ex)
                {
                    this.NICS[counter].SetID(mo["Name"].ToString().Trim());
                }
                this.NICS[counter].KBytesIn = long.Parse(mo["BytesReceivedPersec"].ToString().Trim()) / 1024 ;
                this.NICS[counter].KBytesOut = long.Parse(mo["BytesSentPersec"].ToString().Trim()) / 1024 ;
                this.NICS[counter].KBytesTotal = long.Parse(mo["BytesTotalPersec"].ToString().Trim()) / 1024 ;
                counter++;
            }
            //this.SetBandwidth();
        }
开发者ID:GavinKenna,项目名称:Muroidea,代码行数:41,代码来源:NIC.cs

示例5: GetOtherPrinterNames

        public static String[] GetOtherPrinterNames()
        {
            var query = new ObjectQuery("SELECT * FROM Win32_Printer");
            var searcher = new ManagementObjectSearcher(query);
            int num = searcher.Get().Count;
            int count = 0;
            string[] otherprinters = new string[(num)];

            foreach (ManagementObject mo in searcher.Get())
            {
                if (((bool)mo["Default"]) == false)
                {
                    string whole = mo["Name"] as string;

                    if (whole.Contains("opsprint"))
                    {
                        string[] actual;
                        actual = whole.Split('\\');
                        otherprinters[count] = actual[3];
                    }
                    else if (whole.Contains("Fax") || whole.Contains("XPS") || whole.Contains("OneNote"))
                    {
                        otherprinters[count] = null;
                    }
                    else
                    {
                        otherprinters[count] = whole;
                    }
                }

                count = count +1;
            }

            return otherprinters;
        }
开发者ID:kaburkett,项目名称:Windows-Password-Reminder,代码行数:35,代码来源:QueryPrinter.cs

示例6: DisplayDevices

        public DisplayDevices()
        {
            int counter = 0;

            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController");

            ManagementObjectCollection searchList = searcher.Get();

            this.myDevices = new DisplayDevices[searcher.Get().Count];

            try
            {

                foreach (ManagementObject mo in searchList)
                {
                    myDevices[counter] = new DisplayDevices(counter);
                    try
                    {
                        myDevices[counter].SetManufacturer(mo["AdapterCompatibility"].ToString().Trim());
                    }
                    catch (Exception e)
                    {
                        myDevices[counter].SetManufacturer("none");
                    }
                    try
                    {
                        myDevices[counter].SetModel(mo["name"].ToString().Trim());
                    }
                    catch (Exception e)
                    {
                        myDevices[counter].SetModel("none");
                    }
                    try
                    {
                        myDevices[counter].SetID(mo["deviceid"].ToString().Trim());
                    }
                    catch
                    {
                        myDevices[counter].SetID("none");
                    }
                    try
                    {
                        myDevices[counter].deviceMem = long.Parse(mo["adapterram"].ToString().Trim()) / 1048576;
                    }
                    catch
                    {
                        myDevices[counter].deviceMem = 0;
                    }

                    counter++;

                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:GavinKenna,项目名称:Muroidea,代码行数:58,代码来源:DisplayDevices.cs

示例7: GetServers

        internal void GetServers()
        {
            StringBuilder sb2 = new StringBuilder();
            string serversStr = "CP1002";
            string sqlServerServiceName = "SQLExpress";

            string[] servers = serversStr.Split(',');
            string path;

            StringBuilder sb = new StringBuilder(DateTime.Now + "\nThe following system(s) status was recorded:\n\n");
            bool reportNeeded = false;

            sb = new StringBuilder(DateTime.Now + "\nThe following system(s) status was recorded:\n\n");

            buildServerMap();

            if (isThreadEnabled())
            {
                foreach (string sqlServer in servers)
                {
                    if (serverFound(sqlServer))
                    {
                        sb2.Append(sqlServer + " SQL Server - FOUND\n");
                    }
                    else
                    {
                        sb2.Append(sqlServer + " SQL Server - UNVERIFIABLE\n");
                    }

                    try
                    {
                        path = @"\\" + sqlServer + @"\root\cimv2";

                        ManagementScope ms = new ManagementScope(path);

                        ms.Connect();

                        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Service WHERE Started = TRUE AND DisplayName='" + sqlServerServiceName + "'");
                        searcher.Scope = ms;

                        if (searcher != null && searcher.Get() != null)
                        {
                            foreach (ManagementObject service in searcher.Get())
                            {
                                sb.Append(sqlServer + " SQL Server service - RUNNING\n");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        sb.Append(sqlServer + " SQL Server service - UNVERIFIABLE\n");
                        reportNeeded = true;
                    }
                }
            }
        }
开发者ID:aturgarg,项目名称:SqlServerStudio,代码行数:56,代码来源:wmiSql.cs

示例8: DispSession

        public static void DispSession(Form1 formpassed)
        {
            form = formpassed;
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ServerConnection");
                form.textBox1.AppendText("Win32_ServerConnection instance" + Environment.NewLine + Environment.NewLine);
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    foreach (PropertyData item in queryObj.Properties)
                    {
                        form.textBox1.AppendText(item.Name + " = " + queryObj[item.Name] + Environment.NewLine);
                    }
                    form.textBox1.AppendText(Environment.NewLine);
                }

                searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ServerSession");
                form.textBox1.AppendText("Win32_ServerSession instance" + Environment.NewLine + Environment.NewLine);
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    foreach (PropertyData item in queryObj.Properties)
                    {
                        form.textBox1.AppendText(item.Name + " = " + queryObj[item.Name] + Environment.NewLine);
                    }
                    ManagementObjectCollection serConn = queryObj.GetRelated("Win32_ServerConnection"); //related works its way through dependent/antecedent relationship ALso see below 2 different ways of getting property value
                    foreach (ManagementObject item in serConn)
                    {
                        form.textBox1.AppendText(string.Format("ServerConn for this session: {0} from {1} with {2} ShareName", item.GetPropertyValue("UserName"), item.GetPropertyValue("ComputerName"), item.Properties["ShareName"].Value) + Environment.NewLine);
                    }
                    form.textBox1.AppendText(Environment.NewLine);
                }
                searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ConnectionShare");
                ManagementObjectCollection connShares = searcher.Get();
                form.textBox1.AppendText("Win32_ConnectionShare instance Count = " + connShares.Count.ToString() + Environment.NewLine + Environment.NewLine);
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj.GetPropertyValue("Antecedent").ToString().Contains("TaxWiseServer_P"))
                    {
                        string str = queryObj.GetPropertyValue("Dependent").ToString();
                        form.textBox1.AppendText("Hooray TaxWiseServer_P from " + str.Substring(str.IndexOf("ComputerName"), str.IndexOf("ShareName") - str.IndexOf("ComputerName")) + Environment.NewLine);
                    }
                    foreach (PropertyData item in queryObj.Properties)
                    {
                        form.textBox1.AppendText(item.Name + " = " + queryObj[item.Name] + Environment.NewLine);
                    }
                    form.textBox1.AppendText(Environment.NewLine);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
            form.ShowDialog();
        }
开发者ID:chughes-3,项目名称:WMI-Accessing,代码行数:54,代码来源:DisplaySession.cs

示例9: GetSQLVersion

        /// <summary>
        /// Enumerates all SQL Server instances on the machine.
        /// </summary>
        /// <returns></returns>
        public static SQLVersion GetSQLVersion()
        {
            SQLVersion retVal = SQLVersion.None;
            string correctNamespace = GetCorrectWmiNameSpace();
            if (!string.Equals(correctNamespace, string.Empty))
            {
                string query = string.Format("select * from SqlServiceAdvancedProperty where SQLServiceType = 1 and PropertyName = 'instanceID'");
                ManagementObjectSearcher getSqlEngine = new ManagementObjectSearcher(correctNamespace, query);
                if (getSqlEngine.Get().Count > 0)
                {
                    string serviceName = string.Empty;
                    string version = string.Empty;
                    foreach (ManagementObject sqlEngine in getSqlEngine.Get())
                    {
                        serviceName = sqlEngine["ServiceName"].ToString();
                        version = GetWmiPropertyValueForEngineService(serviceName, correctNamespace, "Version");
                    }
                    Version v = new Version(version);
                    if (v.Major > 10 && retVal == SQLVersion.None || retVal == SQLVersion.SQL2005)
                    {
                        retVal = SQLVersion.Later;
                    }
                    if (v.Major == 10 && retVal == SQLVersion.None || retVal == SQLVersion.SQL2005 || retVal == SQLVersion.Later)
                    {
                        retVal = SQLVersion.SQL2008;
                    }
                    if (v.Major == 9 && retVal == SQLVersion.None)
                    {
                        retVal = SQLVersion.SQL2005;
                    }

                    //Console.WriteLine("SQL Server database instances discovered :");
                    //string instanceName = string.Empty;
                    //string serviceName = string.Empty;
                    //string version = string.Empty;
                    //string edition = string.Empty;
                    //Console.WriteLine("Instance Name \t ServiceName \t Edition \t Version \t");
                    //foreach (ManagementObject sqlEngine in getSqlEngine.Get())
                    //{
                    //    serviceName = sqlEngine["ServiceName"].ToString();
                    //    instanceName = GetInstanceNameFromServiceName(serviceName);
                    //    version = GetWmiPropertyValueForEngineService(serviceName, correctNamespace, "Version");
                    //    edition = GetWmiPropertyValueForEngineService(serviceName, correctNamespace, "SKUNAME");
                    //    Console.Write("{0} \t", instanceName);
                    //    Console.Write("{0} \t", serviceName);
                    //    Console.Write("{0} \t", edition);
                    //    Console.WriteLine("{0} \t", version);
                    //}
                }
            }

            return retVal;
        }
开发者ID:dedimarco,项目名称:evemarketmonitorapp,代码行数:57,代码来源:SQLExpressChecks.cs

示例10: GetProcessInfoByPID

        const int MAXSIZE = 16384; // size _does_ matter

        public static string GetProcessInfoByPID(int PID, out string User, out string Domain, out string OwnerSID)
        {
            //DataTable dt = new DataTable();
            //dt.Columns.Add("ProcessID");
            //dt.Columns.Add("Name");
            //dt.Columns.Add("Description");
            //dt.Columns.Add("User");
            //dt.Columns.Add("Domain");
            //dt.Columns.Add("OwnerSID");
            User = String.Empty;
            Domain = String.Empty;
            OwnerSID = String.Empty;
            string processname = String.Empty;
            try
            {

                ObjectQuery sq = new ObjectQuery("Select * from Win32_Process Where ProcessID = '" + PID + "'");
                //ObjectQuery sq = new ObjectQuery(Query);
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(sq);
                if (searcher.Get().Count == 0)
                    return "Unknown";
                foreach (ManagementObject oReturn in searcher.Get())
                {
                    //Name of process
                    //arg to send with method invoke to return user and domain - below is link to SDK doc on it

                    string[] o = new String[2];
                    //Invoke the method and populate the o var with the user name and domain
                    oReturn.InvokeMethod("GetOwner", (object[])o);

                    //int pid = (int)oReturn["ProcessID"];
                    processname = (string)oReturn["Name"];
                    //dr[2] = oReturn["Description"];
                    User = o[0];
                    if (User == null)
                        User = String.Empty;
                    Domain = o[1];
                    if (Domain == null)
                        Domain = String.Empty;
                    string[] sid = new String[1];
                    oReturn.InvokeMethod("GetOwnerSid", (object[])sid);
                    OwnerSID = sid[0];
		    return OwnerSID;
                }
            }
            catch 
            {
                return OwnerSID;
            }
            return OwnerSID;
        }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:53,代码来源:getprocessownersid.cs

示例11: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            // ログインチェック
            if (Session.Count.Equals(0)) {
                Session.RemoveAll();
                Response.Redirect("Login.aspx");
            }

            Db db = new Db();
            MySqlCommand commGetUserName = new MySqlCommand(@"
                SELECT user_name
                FROM   t_user
                WHERE  user_id = '@user_id'
                ",
                db.conn
            );

            commGetUserName.CommandText = commGetUserName.CommandText.Replace("@user_id", (string)Session["userId"]);

            try {
                db.conn.Open();
                MySqlDataReader read = commGetUserName.ExecuteReader();
                while (read.Read()) {
                    ltrRegistrantName.Text = (string)read["user_name"];
                }
                read.Close();
                db.conn.Close();
            } catch (MySqlException mysqlE) {
            }

            // 接続されているUSBメモリ情報を表示
            ManagementObjectSearcher mosUsb = new ManagementObjectSearcher(
                "root\\CIMV2",
                "SELECT * FROM Win32_DiskDrive WHERE InterfaceType = 'USB'"
            );
            try {
                // レジストリからインターフェイスタイプがUSBであるものを検索
                if (mosUsb.Get().Count != 0) {
                    foreach (ManagementObject queryObj in mosUsb.Get()) {
                        // PNPDeviceIDに含まれるベンダー情報とシリアル番号を取得するため
                        // &区切りで配列に切り出す必要がある
                        string pnpDeviceId      = queryObj["PNPDeviceID"].ToString();
                        string[] arrPnpDeviceId = pnpDeviceId.Split('&');
                        // ベンダー情報とシリアル番号を変数へ格納
                        ltrUsbVendorName.Text = arrPnpDeviceId[1].Substring(4);
                        ltrUsbSerialNo.Text   = arrPnpDeviceId[3];
                    }
                }
            } catch (ManagementException manE) {
            }
        }
开发者ID:tomoyashibata,项目名称:UsbLogger,代码行数:51,代码来源:WhitelistAdd.aspx.cs

示例12: ForEachWithScope

		public static void ForEachWithScope( string computerName, string queryString, Func<ManagementObject, ManagementScope, bool> func, bool needPrivileges = false, bool expectOne = true ) {
			var conOpt = new ConnectionOptions { Impersonation = ImpersonationLevel.Impersonate, EnablePrivileges = needPrivileges };
			var scope = new ManagementScope( string.Format( @"\\{0}\root\CIMV2", computerName ), conOpt );
			var query = new ObjectQuery( queryString );
			using( var objSearch = new ManagementObjectSearcher( scope, query ) ) {
				Debug.Assert( !expectOne || 1 == objSearch.Get( ).Count, string.Format( @"Only expecting one result, {0} found", objSearch.Get( ).Count ) );
				foreach( var obj in objSearch.Get( ) ) {
					Debug.Assert( null != obj, @"WMI Error, null value returned." );
					if( !func( (ManagementObject)obj, scope ) ) {
						break;
					}
				}
			}
		}
开发者ID:beached,项目名称:RemoteWinAdmin,代码行数:14,代码来源:wmi_helpers.cs

示例13: GetInformationTest

        public void GetInformationTest()
        {
            var searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData");
            var thresSearcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_FailurePredictThresholds");

            var searcherEnumerator = searcher.Get().GetEnumerator();
            var thresSearcherEnumerator = thresSearcher.Get().GetEnumerator();

            while (searcherEnumerator.MoveNext() && thresSearcherEnumerator.MoveNext())
            {
                byte[] arrVendorSpecific = (byte[])searcherEnumerator.Current.GetPropertyValue("VendorSpecific");
                byte[] arrThreshold = (byte[])thresSearcherEnumerator.Current.GetPropertyValue("VendorSpecific");

                Console.WriteLine("-----------------------------------");
                Console.WriteLine("MSStorageDriver_ATAPISmartData instance");
                Console.WriteLine("-----------------------------------");

                // Create SMART data from 'vendor specific' array
                var d = new SmartData(arrVendorSpecific, arrThreshold);
                foreach (var b in d.Attributes)
                {
                    Console.Write("{0} : {1} : {2} : ", b.AttributeType, b.Value, b.Threshold);
                    string rawData = BitConverter.ToString(b.VendorData.Reverse().ToArray()).Replace("-", string.Empty);
                    Console.Write("{0}, {1}", rawData, int.Parse(rawData, NumberStyles.HexNumber));
                    Console.WriteLine();
                }
            }

            searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_FailurePredictStatus");
            foreach (ManagementObject queryObj in searcher.Get())
            {
                var arrVendorSpecific = (bool) queryObj.GetPropertyValue("PredictFailure");
                Console.Write("IsOK: {0}", !arrVendorSpecific);
            }
        }
开发者ID:vhst,项目名称:DiskUtilities,代码行数:35,代码来源:SMARTUnitTests.cs

示例14: find_arduino

        private void find_arduino()
        {
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_SerialPort");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    string deviceName = queryObj["Name"].ToString();
                    if (deviceName.Contains("Arduino"))
                    {
                        _arduinoPort.PortName = queryObj["DeviceID"].ToString();
                        _comPortSelection.Text = queryObj["DeviceID"].ToString();
                        return;
                    }

                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
开发者ID:jplumpto,项目名称:KatanaSimTools-V2012,代码行数:25,代码来源:ArduinoCalibration.cs

示例15: ObjectQuery

        public static List<EntDisk>GetDiskDetails(ManagementScope scope)
        {
            _logger.Info("Collecting disk details for machine " + scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntDisk> lstDisk = new List<EntDisk>();

            try
            {
                query = new ObjectQuery("Select * from Win32_DiskDrive");
                searcher = new ManagementObjectSearcher(scope, query);
                objects = searcher.Get();
                lstDisk.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstDisk.Add(FillDetails(obj));
                    obj.Dispose();
                }
            }
            catch (Exception e)
            {
                _logger.Error("Exception is disk collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
            }
            return lstDisk;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:Disk.cs


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