1
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);
示出了是該消息:如何檢查特定進程是否在遠程PC /服務器上運行?
值不在所述預期範圍內。
是憑據是否正確?爲什麼在'else'子句的構造函數中添加'null'作爲參數?根據https://msdn.microsoft.com/de-de/library/system.management.managementscope%28v=vs.110%29.aspx,您可以忽略它。另外,你能給出一個更詳細的堆棧跟蹤,它究竟在哪裏崩潰的內部函數? –
它在Scope.Connect崩潰(我在代碼中評論它) –