惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
博客园_首页
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
N
News | PayPal Newsroom
S
Security Archives - TechRepublic
量子位
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
Cisco Blogs
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
Scott Helme
Scott Helme
S
Securelist
Security Latest
Security Latest
爱范儿
爱范儿
TaoSecurity Blog
TaoSecurity Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
美团技术团队
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
月光博客
月光博客
T
Tailwind CSS Blog
Cloudbric
Cloudbric
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
D
DataBreaches.Net
博客园 - 【当耐特】
有赞技术团队
有赞技术团队

博客园 - K3

什么是URL,URI或URN? 软件设计思想的一些文章 (持续补充中) Mac OS X 上Lua的安装方法 Objective C - 4 - 下载图片并且加载到View Objective C - 3 - 实现一个计算器 Objective C - 2 - 随机数,可变字符串,字符串,SubString Objective C - 1 - 实现一个MessageBox.Show MySQL 存储过程,游标,临时表创建 How to compose namespaces? Hide/Show running Console Calculate drive total/free/available space C# list installed softwares How to: Modify a Project System So That Projects Load in Multiple Versions of Visual Studio PS:WINRAR制作32位安装程序和64位安装程序选项 使用WINRAR来制作安装程序 impersonate a user VBScript - CUD registry key and value mysql script for dynamic running sql script XmlElement可以避免由XmlSerializer多余生成的代码
List connected users–similar to task manager
K3 · 2014-03-18 · via 博客园 - K3
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 = 0; 
               Int32 retVal = WTSEnumerateSessions(serverHandle, 0, 1, ref SessionInfoPtr, ref sessionCount); 
               Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO)); 
               Int32 currentSession = (int)SessionInfoPtr; 
               uint bytes = 0;

               if (retVal != 0) 
               { 
                   for (int i = 0; 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); 
           }

       }

   }