c#擷取電腦資訊

來源:互聯網
上載者:User

ManagementObjectSearcher 類

基於指定的查詢檢索管理對象的集合。此類是用於檢索管理資訊的較為常用的進入點之一。例如,它可以用於枚舉系統中的所有磁碟機、網路介面卡、進程及更多管理對象,或者用於查詢所有處於活動狀態的網路連接以及暫停服務等。在執行個體化之後,此類的執行個體可以接受在 ObjectQuery 或其衍生類別中表示的 WMI 查詢作為輸入,並且還可以選擇接受一個 ManagementScope(表示執行查詢時所在的 WMI 命名空間)。它還可以接受 EnumerationOptions 中的其他進階選項。當調用此對象的 Get 方法時,ManagementObjectSearcher 在指定的範圍內執行給定的查詢,並返回與 ManagementObjectCollection 中的查詢匹配的管理對象的集合。

using System;
using System.Management;
public class RemoteConnect
{
    public static void Main()
    {
        /*// Build an options object for the remote connection
        //   if you plan to connect to the remote
        //   computer with a different user name
        //   and password than the one you are currently using
         
             ConnectionOptions options =
                 new ConnectionOptions();
                
             // and then set the options.Username and
             // options.Password properties to the correct values
             // and also set
             // options.Authority = "ntdlmdomain:DOMAIN";
             // and replace DOMAIN with the remote computer's
             // domain.  You can also use kerberose instead
             // of ntdlmdomain.
        */

        // Make a connection to a remote computer.
        // Replace the "FullComputerName" section of the
        // string "\\\\FullComputerName\\root\\cimv2" with
        // the full computer name or IP address of the
        // remote computer.
        ManagementScope scope =
            new ManagementScope(
            "\\\\FullComputerName\\root\\cimv2");
        scope.Connect();

        // Use this code if you are connecting with a
        // different user name and password:
        //
        // ManagementScope scope =
        //    new ManagementScope(
        //        "\\\\FullComputerName\\root\\cimv2", options);
        // scope.Connect();

        //Query system for Operating System information
        ObjectQuery query = new ObjectQuery(
            "SELECT * FROM Win32_OperatingSystem");
        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(scope,query);

        ManagementObjectCollection queryCollection = searcher.Get();
        foreach ( ManagementObject m in queryCollection)
        {
            // Display the remote computer information
            Console.WriteLine("Computer Name : {0}",
                m["csname"]);
            Console.WriteLine("Windows Directory : {0}",
                m["WindowsDirectory"]);
            Console.WriteLine("Operating System: {0}", 
                m["Caption"]);
            Console.WriteLine("Version: {0}", m["Version"]);
            Console.WriteLine("Manufacturer : {0}",
                m["Manufacturer"]);
        }
    }
}
參數集合
Win32_1394Controller
Win32_1394ControllerDevice
Win32_Account
Win32_AccountSID
Win32_ACE
Win32_ActionCheck
Win32_AllocatedResource
Win32_ApplicationCommandLine
Win32_ApplicationService
Win32_AssociatedBattery
Win32_AssociatedProcessorMemory
Win32_BaseBoard
Win32_BaseService
Win32_Battery
Win32_Binary
Win32_BindImageAction
Win32_BIOS
Win32_BootConfiguration
Win32_Bus
Win32_CacheMemory
Win32_CDROMDrive
Win32_CheckCheck
Win32_CIMLogicalDeviceCIMDataFile
Win32_ClassicCOMApplic

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.