로그인 한 사용자를 찾기 위해 모든 도메인 컴퓨터에서 WMI 쿼리를 실행하는 .NET 응용 프로그램이 있습니다. 각 컴퓨터를 핑 (ping)하여 온라인인지 여부를 찾은 다음 실제 쿼리를 실행합니다.WMI 쿼리에서 시간 초과를 설정하는 방법은 무엇입니까?
코드 스 니펫 :
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 쿼리를 무기한에 달려 있습니다.
어떻게 타임 아웃을 설정할 수 있습니까?
훌륭합니다. – Massimo