我有一个.NET应用程序,它在所有域计算机上运行WMI查询,以便找到登录用户; 它ping每台计算机以查找它是否在线,然后运行实际查询.
代码段:
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
}
Run Code Online (Sandbox Code Playgroud)
问题:有时WMI查询会无限期地挂起.
如何设置超时?
我在存储过程中有一个本地表变量,包含几列;我需要根据该行的第 1 列的值使用子查询的结果更新每行的第 2 列。
就像是:
UPDATE @mytable
SET column2 = (SELECT ... FROM ... WHERE something = @mytable.column1)
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用,我收到有关 @mytable 未定义的错误。
此查询的正确语法是什么?