起步文档:
WMI调用基本步骤
一个简单的远程访问例子:(参考自MSDN: How To: Connect to a Remote Computer)
using System;
using System.Management;
namespace TestCaseProj
{
public class WMI_Validate
{
public static void start()
{
try
{
//// 获取本机信息,注意这里不带ConnectionOptions参数;
//ManagementScope scope = new ManagementScope("\\\\127.0.0.1\\root\\CIMv2");
// 获取远端主机信息,注意这里需要使用ConnectionOptions参数控制连接;
ConnectionOptions options = new ConnectionOptions();
options.Username = "Administrator";
options.Password = "xxxxxxxxx";
options.EnablePrivileges = true; //获取尽可能高的权限;
options.Impersonation = ImpersonationLevel.Impersonate;
options.Authentication = AuthenticationLevel.PacketPrivacy; //加密数据流