【发布时间】:2015-12-14 16:26:11
【问题描述】:
string ComputerName = serverName;
ManagementScope Scope;
if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
ConnectionOptions Conn = new ConnectionOptions();
Conn.Username = "";
Conn.Password = "";
Conn.Authority = "ntlmdomain:DOMAIN";
Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), Conn);
}
else
Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null);
Scope.Connect(); // CRASH HERE
ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_Process Where Name='" + processName + "'");
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);
显示的消息是:
值不在预期范围内。
【问题讨论】:
-
凭据是否正确?为什么要在
else子句的构造函数中添加null作为参数?根据msdn.microsoft.com/de-de/library/… ,您可以忽略它。另外,您能否提供更详细的堆栈跟踪,它究竟在内部函数的哪个位置崩溃? -
它在 Scope.Connect 崩溃(我在代码中对其进行了注释)