繁体   English   中英

如何找到已登录的Windows用户的会话名称?

[英]How to find the session name of the logged in Windows user?

如您在Windows任务管理器的选项卡用户中看到的,共有5列:

User   ID   Status  Client Name  Session
Mike   1    Active               Console

我用它来获取会话ID:

System.Diagnostics.Process.GetCurrentProcess().SessionId.ToString();

我想知道会话名称以查看它是控制台还是远程桌面等。

private string getsessionname()
{
  // function to get session name
}

if(getsessionname=="console")
{
  // do staff1
}
else
{
  // do staff2
}

谢谢。

您不仅在寻找SystemInformation.TerminalServerSession吗?

获取一个值,该值指示呼叫过程是否与终端服务客户端会话相关联。

例如:

using System.Windows.Forms;

...

if(SystemInformation.TerminalServerSession)
{
  // do stuff where the user is using remote desktop
}
else
{
  // user is connected locally, e.g. the console
}

没有托管的API。 一种方法是通过P-Invoke使用本机API,请参阅检索登录会话信息 但是更简单的方法是使用WMI并查询Win32_LogonSession对象

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM