2015-05-05 38 views
0

我嘗試連接到遠程PC並查詢其進程,但是當我運行代碼時,它與本地PC連接並獲得其進程而不是遠程PC。 該代碼是WMI管理範圍連接到本地而不是遠程

ManagementScope scope = new ManagementScope(@"\\remote-user\\root\\cimv2"); 
scope.Connect(); 
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process"); 
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); 
ManagementObjectCollection queryCollection = searcher.Get(); 
foreach (ManagementObject m in queryCollection) 
+0

如果答案解決了您的問題,請相應標記它們。否則,需要更多細節(這次出錯了)等等。 – w128

回答

0

你似乎是通過一個用戶名(「遠程-user「)而不是遠程機器的主機名到您的管理範圍。將您的代碼改爲例如:

ConnectionOptions options = new ConnectionOptions(); 
options.Password = "remoteUserPassword"; // you may want to avoid plain text password and use SecurePassword property instead 
options.Username = "remote-user"; 
ManagementScope scope = new ManagementScope(@"\\remoteMachineHostname\root\cimv2", options); 
0

(I假定遠程用戶是完整的計算機名稱)的變化:

ManagementScope scope = new ManagementScope(@"\\remote-user\\root\\cimv2"); 

到:

ManagementScope scope = new ManagementScope(@"\\<FullComputerName>\root\cimv2"); 

另一種選擇:

ManagementScope scope = new ManagementScope("\\\\<FullComputerName>\\root\\cimv2"); 

請參閱this鏈接(這是微軟的例子)

編輯

,如果你想與你需要傳遞ConnectionOptions(見上面的鏈接)deffrent用戶連接

相關問題