Window Service程序中如何获取登陆用户的信息

来源:互联网 发布:程序员基本要求 编辑:程序博客网 时间:2024/05/16 10:07

    在windows底层的api中,提供了以下的方法来满足需求:

    WTSGetActiveConsoleSessionId: 获取当前active User的 session ID。

    CreateProcessAsUser:用当前用户创建一个新的进程。


  1. public static string GetCurrentActiveUser()
  2.         {
  3.             IntPtr hServer = IntPtr.Zero, state = IntPtr.Zero;
  4.             uint bCount = 0;

  5.             // obtain the currently active session id; every logged on user in the system has a unique session id
  6.             uint dwSessionId = WTSGetActiveConsoleSessionId();
  7.             string domain = string.Empty, userName = string.Empty;

  8.             if (WTSQuerySessionInformation(hServer, (int)dwSessionId, WTSInfoClass.DomainName, out state, out bCount))
  9.             {
  10.                 domain = Marshal.PtrToStringAuto(state);
  11.             }

  12.             if (WTSQuerySessionInformation(hServer, (int)dwSessionId, WTSInfoClass.UserName, out state, out bCount))
  13.             {
  14.                 userName = Marshal.PtrToStringAuto(state);
  15.             }

  16.             return string.Format("{0}\\{1}", domain, userName);
  17.         }

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(717) | 评论(0) | 转发(0) |
0

上一篇:穿透Session 0 隔离

下一篇:Windows 使用事件

相关热门文章
  • LNK1123: 转换到 COFF 期间失...
  • WIN7访问共享:0x80070035 找不...
  • Delphi 2010下载+完美破解...
  • vs2010调试C++程序时提示 无...
  • VISIO,不规则封闭图形填充方...
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
0 0