您的位置:首页 > 理论基础

c#获取计算机信息

2008-07-09 17:38 381 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: