【发布时间】:2011-09-15 09:14:09
【问题描述】:
我有一个 .NET 应用程序,它在所有域计算机上运行 WMI 查询以查找登录用户;它 ping 每台计算机以查找它是否在线,然后运行实际查询。
代码sn-p:
try
{
string loggedonuser = null;
string computername = "ComputerToQuery";
ConnectionOptions co = new ConnectionOptions();
co.Username = "DOMAIN\MyUser";
co.Password = "MyPassword";
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.Default;
ManagementPath mp = new ManagementPath(@"\\" + computername + @"\root\cimv2");
ManagementScope ms = new ManagementScope(mp,co);
ms.Connect();
ObjectQuery oq = new ObjectQuery("SELECT username FROM Win32_ComputerSystem");
ManagementObjectSearcher mos = new ManagementObjectSearcher(ms,oq);
foreach(ManagementObject mo in mos.Get())
loggedonuser = (String) mo["username"];
}
catch(Exception e)
{
// Handle WMI exception
}
问题:有时 WMI 查询会无限期挂起。
如何设置超时时间?
【问题讨论】: