2011-06-03 34 views
0

任何人都知道如何找到範圍?
微軟說如何查找ManagementScope的範圍?

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

我在本地主機工作。 我已經測試過「\\ HOSTNAME \ root \ cimv2」和「\\ HOSTNAME \ MY_ACCOUNT_NAME \ cimv2」,但它們不起作用。

我在Windows 7專業版,我使用Visual Studio 2010和它的.Net 4

更新1

int i = Convert.ToInt32(processIds[index]); 
String queryString = "select CreationDate from Win32_Process where ProcessId='" + processIds[index] + "'"; 
SelectQuery query = new SelectQuery(queryString); 

ManagementScope scope = new System.Management.ManagementScope("\\\\XXX-PC\\YYY\\cimv2"); 
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); 
ManagementObjectCollection processes = searcher.Get(); 

@keyboardP:Searcher.Get()工作異常,所以我認爲我的範圍不對。

+0

是否有任何錯誤消息? – keyboardP 2011-06-03 02:15:27

+0

主題中的更多信息 – 2011-06-03 02:20:53

+0

我的猜測是你得到了「拒絕訪問」異常。嘗試添加'ConnectionOptions選項= 新的ConnectionOptions(); options.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;'範圍之前。 – keyboardP 2011-06-03 02:24:34

回答

1

我一直在開發一個使用管理範圍很長一段時間的應用程序。我想你只需要省略主機名稱

這個工作對我來說:

​​