相关疑难解决方法(0)

如何使用远程计算机上的状态登录用户

我正在寻找一种方法来获取在远程计算机上登录的用户.我很想知道他们是在当地还是远程登录,但最重要的是我必须知道他们的状态.我在网上看到了一些用VB编写的答案,但我需要在c#中使用它.markdmak在这里给出的解决方案看起来是一个好的开始,但它在VB中,它只查找远程会话.我有这段代码,这可能是一个开始,但我想将LogonId耦合到用户名并查看其状态:

string fqdn = ""; // set!!!    
ConnectionOptions options = new ConnectionOptions();
options.EnablePrivileges = true;
// To connect to the remote computer using a different account, specify these values:
// these are needed in dev environment
options.Username = ConfigurationManager.AppSettings["KerberosImpersonationUser"];
options.Password = ConfigurationManager.AppSettings["KerberosImpersonationPassword"];
options.Authority = "ntlmdomain:" + ConfigurationManager.AppSettings["KerberosImpersonationDomain"];

ManagementScope scope = new ManagementScope("\\\\" + fqdn + "\\root\\CIMV2", options);
try
{
    scope.Connect();
}
catch (Exception ex)
{
    if (ex.Message.StartsWith("The RPC server is unavailable"))
    {
        // The Remote Procedure Call server …
Run Code Online (Sandbox Code Playgroud)

c# wmi

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

wmi ×1