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