代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
Windows任务管理 连接用户登录信息
作者:
stone_w
/ 发布于
2013/11/8
/
883
代码 using System; //---引用 using System.Runtime.InteropServices; using System.Text; /// <summary> /// Windows 任务管理器登录用户信息 /// author:Stone_W /// date:2011.1.14 /// </summary> public class ComputerLoginUserInfo { #region 本机连接用户信息API封装 public class TSControl { [DllImport("wtsapi32", CharSet = CharSet.Auto, SetLastError = true)] private static extern bool WTSEnumerateSessions(int hServer, int Reserved, int Version, ref long ppSessionInfo, ref int pCount); [DllImport("wtsapi32.dll")] public static extern void WTSFreeMemory(System.IntPtr pMemory); [DllImport("wtsapi32.dll")] public static extern bool WTSLogoffSession(int hServer, long SessionId, bool bWait); [DllImport("Wtsapi32.dll")] public static extern bool WTSQuerySessionInformation( System.IntPtr hServer, int sessionId, WTSInfoClass wtsInfoClass, out StringBuilder ppBuffer, out int pBytesReturned); public enum WTSInfoClass { WTSInitialProgram, WTSApplicationName, WTSWorkingDirectory, WTSOEMId, WTSSessionId, WTSUserName, WTSWinStationName, WTSDomainName, WTSConnectState, WTSClientBuildNumber, WTSClientName, WTSClientDirectory, WTSClientProductId, WTSClientHardwareId, WTSClientAddress, WTSClientDisplay, WTSClientProtocolType } public enum WTS_CONNECTSTATE_CLASS { WTSActive, WTSConnected, WTSConnectQuery, WTSShadow, WTSDisconnected, WTSIdle, WTSListen, WTSReset, WTSDown, WTSInit, } public struct WTS_SESSION_INFO { public int SessionID; [MarshalAs(UnmanagedType.LPTStr)] public string pWinStationName; public WTS_CONNECTSTATE_CLASS state; } public static WTS_SESSION_INFO[] SessionEnumeration() { //Set handle of terminal server as the current terminal server int hServer = 0; bool RetVal; long lpBuffer = 0; int Count = 0; long p; WTS_SESSION_INFO Session_Info = new WTS_SESSION_INFO(); WTS_SESSION_INFO[] arrSessionInfo; RetVal = WTSEnumerateSessions(hServer, 0, 1, ref lpBuffer, ref Count); arrSessionInfo = new WTS_SESSION_INFO[0]; if (RetVal) { arrSessionInfo = new WTS_SESSION_INFO[Count]; int i; p = lpBuffer; for (i = 0; i < Count; i++) { arrSessionInfo[i] = (WTS_SESSION_INFO)Marshal.PtrToStructure(new IntPtr(p), Session_Info.GetType()); p += Marshal.SizeOf(Session_Info.GetType()); } WTSFreeMemory(new IntPtr(lpBuffer)); } else { //Insert Error Reaction Here } return arrSessionInfo; } } #endregion public System.Collections.Generic.List<ComputerLoginUserInfoModel> ComputerLoginUserInfoList; public ComputerLoginUserInfo() { #region 查询代码 TSControl.WTS_SESSION_INFO[] pSessionInfo = TSControl.SessionEnumeration(); ComputerLoginUserInfoModel cum = null; ComputerLoginUserInfoList = new System.Collections.Generic.List<ComputerLoginUserInfoModel>(); for (int i = 0; i < pSessionInfo.Length; i++) { if ("RDP-Tcp" != pSessionInfo[i].pWinStationName) { try { int count = 0; IntPtr buffer = IntPtr.Zero; StringBuilder userName = new StringBuilder(); // 用户名 StringBuilder clientUser = new StringBuilder(); // 客户端名 StringBuilder stateType = new StringBuilder(); // 会话类型 bool userNameBool = TSControl.WTSQuerySessionInformation(IntPtr.Zero, pSessionInfo[i].SessionID, TSControl.WTSInfoClass.WTSUserName, out userName, out count); bool clientUserBool = TSControl.WTSQuerySessionInformation(IntPtr.Zero, pSessionInfo[i].SessionID, TSControl.WTSInfoClass.WTSClientName, out clientUser, out count); bool stateTypeBool = TSControl.WTSQuerySessionInformation(IntPtr.Zero, pSessionInfo[i].SessionID, TSControl.WTSInfoClass.WTSWinStationName, out stateType, out count); if (userNameBool && clientUserBool && stateTypeBool) { cum = new ComputerLoginUserInfoModel(); cum.UserName = userName.ToString(); cum.ClientUserName = clientUser.ToString(); cum.SessionType = stateType.ToString(); } ComputerLoginUserInfoList.Add(cum); } catch (Exception ex) { } } } #endregion } } public class ComputerLoginUserInfoModel { #region 用户信息字段 private string userName; private string clientUserName; private string sessionType; /// <summary> /// 会话类型 /// </summary> public string SessionType { get { return sessionType; } set { sessionType = value; } } /// <summary> /// 客户端名 /// </summary> public string ClientUserName { get { return clientUserName; } set { clientUserName = value; } } /// <summary> /// 登录用户名 /// </summary> public string UserName { get { return userName; } set { userName = value; } } #endregion }
试试其它关键字
用户登录
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
stone_w
贡献的其它代码
(
9
)
.
Windows任务管理 连接用户登录信息
.
获取电脑硬件信息通用查询类
.
操作线程的通用类
.
操作IIS应用程序池
.
查询本机日志
.
Js、Css文件压缩辅助类
.
模拟POST表单提交WebClient
.
T-SQL查询库、表、列数据结构信息汇总
.
字符相似度对比通用类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3