我们有 6 台 Citrix 服务器。我正在尝试确定是否启用/禁用了远程登录。
我打算把它放到一个网页上显示,如果它们是绿色图标,如果不是红色图标。
我已经设法连接到机器并提取操作系统信息等。但是,当我尝试连接以查看 TerminalServiceSetting 信息时。我收到 Invalid Class 错误。
这是我的代码。
ManagementScope scope = new ManagementScope("\\\\MACHINENAME\\ROOT\\cimv2");
scope.Connect();
//create object query
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_TerminalServiceSetting");
//create object searcher
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
//get collection of WMI objects
ManagementObjectCollection queryCollection = searcher.Get();
//enumerate the collection.
foreach (ManagementObject m in queryCollection)
{
// access properties of the WMI object
Label1.Text = m["AllowTSConnections"].ToString();
}
如果有人能对此有所了解,那就太好了。
谢谢
更新:
我现在找到了检查远程连接是启用还是禁用的代码(我认为)。
ManagementScope scope =
new ManagementScope("\\\\MACHINENAME\\root\\CIMV2\\TerminalServices",con);
scope.Options.EnablePrivileges = true;
scope.Options.Authentication = AuthenticationLevel.PacketPrivacy;
scope.Options.Impersonation = ImpersonationLevel.Impersonate;
scope.Connect();
//create object query
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_TerminalServiceSetting");
//create object searcher
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
//get collection of WMI objects
ManagementObjectCollection queryCollection = searcher.Get();
//enumerate the collection.
foreach (ManagementObject m in queryCollection)
{
if (m["AllowTSConnections"].ToString() == "1")
{
Redicon.Visible = false;
}
else
{
Greenicon.Visible = false;
}
}
但是,当我运行代码时,我会返回“1”.. 这很好。但是,如果我拒绝服务器上的远程登录并重新运行代码,它会保持在 1..
有任何想法吗?