远程WMI连接C# - 无效的参数错误 [英] remote wmi connection c# - invalid parameter error

查看:829
本文介绍了远程WMI连接C# - 无效的参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行下面的代码

ConnectionOptions options = new ConnectionOptions();
        options.EnablePrivileges = true;
        options.Impersonation = ImpersonationLevel.Impersonate;
        options.Authentication = AuthenticationLevel.Packet;
        options.Authority = "ntdlmdomain:InsTIL.com";
        options.Username = "instil" + @"\" + "admin";
        options.Password = "Pwd";

        ManagementScope scope= new ManagementScope(string.Format(@"\\172.16.2.171\root\cimv2"),options);
        scope.Connect();
        if (scope.IsConnected == true)
        {
           Console.WriteLine("Connection Succeeded");
        }
        else
        {
            Console.WriteLine("Connection Failed");
        }


        ObjectQuery query = new ObjectQuery("Select * from win32_operatingsystem");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

        ManagementObjectCollection querycollection = searcher.Get();
        foreach (ManagementObject mobj in querycollection)
        {
            Console.WriteLine("Computer name: {0}", mobj["csname"]);
            Console.WriteLine("Windows Directory : {0}", mobj["WindowsDirectory"]);
            Console.WriteLine("Operating System: {0}", mobj["Caption"]);
            Console.WriteLine("Version: {0}", mobj["Version"]);
            Console.WriteLine("Manufacturer : {0}", mobj["Manufacturer"]);
        }



我得到以下错误

i get following error

  Unhandled Exception: System.Management.ManagementException: Invalid parameter
   at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
    at System.Management.ManagementScope.InitializeGuts(Object o)
   at System.Management.ManagementScope.Initialize()
  at remote_wmi.Program.Main(String[] args) in E:\.net prep\.net examples\remote wmi\remote wmi\Program.cs:line 21

请帮助我了解为什么它发生?什么是错的代码?是我们需要执行该代码之前,做任何事情吗?如果是,请指定它。

please help me to know why its happening.? what's wrong in this code? is we need to do any thing before executing this code? if yes, please specify it .

先谢谢了。

推荐答案

我做了以下的变化,然后我得到的回答。

I did the following changes then i got an answer.

1)我没有指定域名和用户名。
options.Username =管理; 而不是 options.Username =灌输+ @\+管理员 ;

1) i haven't specified the domain name with user name. options.Username = "admin"; instead of options.Username = "instil" + @"\" + "admin";

2)
options.Authority =ntlmdomain:InsTIL.com; ,而不是 options.Authority =ntdlmdomain:InsTIL.com;

这篇关于远程WMI连接C# - 无效的参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆