List connected users–similar to task manager
class Program
{
[DllImport("wtsapi32.dll")]
static extern IntPtr WTSOpenServer([MarshalAs(UnmanagedType.LPStr)] String pServerName); [DllImport("wtsapi32.dll")]
static extern void WTSCloseServer(IntPtr hServer); [DllImport("wtsapi32.dll")]
static extern Int32 WTSEnumerateSessions(
IntPtr hServer,
[MarshalAs(UnmanagedType.U4)] Int32 Reserved,
[MarshalAs(UnmanagedType.U4)] Int32 Version,
ref IntPtr ppSessionInfo,
[MarshalAs(UnmanagedType.U4)] ref Int32 pCount); [DllImport("wtsapi32.dll")]
static extern void WTSFreeMemory(IntPtr pMemory); [DllImport("Wtsapi32.dll")]
static extern bool WTSQuerySessionInformation(
System.IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out System.IntPtr ppBuffer, out uint pBytesReturned); [StructLayout(LayoutKind.Sequential)]
private struct WTS_SESSION_INFO
{
public Int32 SessionID; [MarshalAs(UnmanagedType.LPStr)]
public String pWinStationName; public WTS_CONNECTSTATE_CLASS State;
} public enum WTS_INFO_CLASS
{
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
} static void Main(string[] args)
{
ListUsers(Environment.MachineName);
Console.ReadKey();
} public static IntPtr OpenServer(String Name)
{
IntPtr server = WTSOpenServer(Name);
return server;
}
public static void CloseServer(IntPtr ServerHandle)
{
WTSCloseServer(ServerHandle);
}
public static void ListUsers(String ServerName)
{
IntPtr serverHandle = IntPtr.Zero;
List<String> resultList = new List<string>();
serverHandle = OpenServer(ServerName); try
{
IntPtr SessionInfoPtr = IntPtr.Zero;
IntPtr userPtr = IntPtr.Zero;
IntPtr domainPtr = IntPtr.Zero;
Int32 sessionCount = ;
Int32 retVal = WTSEnumerateSessions(serverHandle, , , ref SessionInfoPtr, ref sessionCount);
Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));
Int32 currentSession = (int)SessionInfoPtr;
uint bytes = ; if (retVal != )
{
for (int i = ; i < sessionCount; i++)
{
WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)currentSession, typeof(WTS_SESSION_INFO));
currentSession += dataSize; WTSQuerySessionInformation(serverHandle, si.SessionID, WTS_INFO_CLASS.WTSUserName, out userPtr, out bytes);
WTSQuerySessionInformation(serverHandle, si.SessionID, WTS_INFO_CLASS.WTSDomainName, out domainPtr, out bytes); Console.WriteLine(string.Format("SessionID : {0} Domain : {1} User : {2} StationName : {3} State : {4}",
si.SessionID, Marshal.PtrToStringAnsi(domainPtr), Marshal.PtrToStringAnsi(userPtr), si.pWinStationName, si.State)); WTSFreeMemory(userPtr);
WTSFreeMemory(domainPtr);
} WTSFreeMemory(SessionInfoPtr);
}
}
finally
{
CloseServer(serverHandle);
} } }
List connected users–similar to task manager的更多相关文章
- My To Do List (Task Manager)
My To Do List (Task Manager) With everything that business owners deal with throughout their day, th ...
- Flink 源码解析 —— Standalone Session Cluster 启动流程深度分析之 Task Manager 启动
Task Manager 启动 https://t.zsxq.com/qjEUFau 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Ma ...
- GPO - Disabling Task Manager Access
Create a GPO to disable Task Manager Access to normal users. Add an exception to Domain Admins.
- SQL Server 在task manager里面显示CPU 使用率过高
发现一篇好文章 https://mssqlwiki.com/2012/10/04/troubleshooting-sql-server-high-cpu-usage/
- Apparatus, system, and method for automatically minimizing real-time task latency and maximizing non-real time task throughput
An apparatus, system, and method are provided for automatically minimizing Real-Time (RT) task laten ...
- 1.1 让CPU占用率曲线听你指挥[cpu manager]
[本文链接] http://www.cnblogs.com/hellogiser/p/cpu-manager.html [题目] 写一个程序,让用户来决定Windows任务管理器(Task Manag ...
- Flink 源码解析 —— Standalone Session Cluster 启动流程深度分析之 Job Manager 启动
Job Manager 启动 https://t.zsxq.com/AurR3rN 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Mac ...
- Total Commander 8.52 Beta 1
Total Commander 8.52 Beta 1http://www.ghisler.com/852_b1.php 10.08.15 Release Total Commander 8.52 b ...
- ovirt user guide
Contents [hide] 1 Accessing the User Portal 1.1 Logging in to the User Portal 1.2 Logging out of t ...
随机推荐
- dp_c_区间dp_g
You Are The One 题意:有n个人准备按顺序上台,上台前有个小黑屋(先进后出,即栈),可以被安排进去等待,也可以直接上台,一个人一旦被安排进去,后面的人就可以先上台(小黑屋无限大).每个人 ...
- 【转】chrome 67版本后无法拖拽离线安装CRX格式插件的解决方法
第一种:开启开发者模式即可 (推荐) chrome 的设置 -> 更多工具 -> 扩展程序,开启开发者模式即可! 第二种方法:修改参数 首先打开下面地址:chrome://flags/# ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Sum
2017-09-16 12:13:44 writer:pprp 特判 #include <iostream> using namespace std; int main() { int c ...
- PAT1072. Gas Station (30)
题目的测试用例数据有问题! 第一个Case 应该是 G1 2.0 3.2 一直在想3.3分母的3怎么来了.ORZ #include <iostream> #include <ccty ...
- Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
一.linux中配置redis,使用java连接测试时报错: Exception in thread "main" redis.clients.jedis.exceptions.J ...
- Python类变量,实例变量,类方法,实例方法,静态方法的分析
Python作为动态语言,跟静态语言如c/c++有很大区别,其中的一个重要的特性就是Python的变量无需声明直接可用.同样,类的成员变量无需声明,直接可用.目的是为了动态语言跟灵活,在思路想到的时候 ...
- PHP实体层基础类
PHP实体层基础类 class BaseModel { private $tableName; private $fields=array(); function __construct() { $t ...
- 使用ssm整合是项目启动tomcat报错java.lang.IndexOutOfBoundsException
解决办法:删除.m2文件夹下的全部仓库,然后重启myeclipse,对项目进行maven project.问题解决. 在没有这样做时,除了tomcat启动会失败,项目还有会报如下错误: ①cvc-co ...
- SQLServer 2005 和自增长主键identity说再见——NEWSEQUENTIALID()
``code 在SQLServer2005环境下,表的主键应该怎样设计. 目前主要用到的主键方案共三种 自动增长主键 手动增长主键 UNIQUEIDENTIFIER主键 1.先说自动增长主键,它的优点 ...
- jqPaginator分页(ajax用法和form表单提交用法)
一般使用方法 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...