A lightweight C# console application for enumerating and displaying all user sessions on Windows Server, including session GUIDs.
- Complete Session Enumeration: Lists all active sessions on the Windows server
- Detailed Session Information: Displays Session ID, Station Name, Connection State, Username, and Domain
- Session GUID Retrieval: Extracts the unique GUID identifier for each session from the Windows registry
- Connection State Detection: Shows whether sessions are Active, Disconnected, Idle, etc.
- Clean Console Output: Easy-to-read formatted output for quick session analysis
- Windows Server (2012 R2 or later) or Windows Client (Windows 10/11)
- .NET Framework 4.7.2+
- Administrator privileges (required for accessing session information and registry)
- Clone or download the repository
- Open the solution in Visual Studio 2019 or later
- Build the solution (Ctrl+Shift+B)
- The executable will be located in
bin\Debugorbin\Release
msbuild SessionView.csproj /p:Configuration=Release
csc /out:SessionView.exe /platform:anycpu Program.cs
- Run as Administrator: This toold needs elevated token
- The application will automatically enumerate all sessions and display the information
=== Windows Server Session Enumerator ===
Found 3 session(s)
Session 1:
Session ID: 0
Station Name: Services
State: WTSDisconnected
Username: (No user logged in)
Session GUID: (Not available)
Session 2:
Session ID: 1
Station Name: Console
State: WTSActive
Username: Administrator
Domain: MYSERVER
Session GUID: {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}
Session 3:
Session ID: 2
Station Name: RDP-Tcp#1
State: WTSDisconnected
Username: JohnDoe
Domain: COMPANY
Session GUID: {B2C3D4E5-F6A7-8901-BCDE-F12345678901}
Press any key to exit...
The application can display the following connection states:
- WTSActive: User is actively using the session
- WTSConnected: Session is connected
- WTSDisconnected: Session is disconnected but still running
- WTSIdle: Session is idle
- WTSListen: Session is listening for connections
- WTSReset: Session is being reset
- WTSDown: Session is down
- WTSInit: Session is initializing
- WTS API (wtsapi32.dll): For enumerating sessions and querying session information
- Windows Registry API (advapi32.dll): For retrieving session GUIDs from the registry
Session GUIDs are stored at:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Remote\Terminal Services\Session\{SessionId}\SessionGuid
- Session 0 (Services session) typically does not have a GUID
- Requires administrator privileges to access session information
- Some sessions may not have all information available depending on their state
- Ensure you're running the application as Administrator
- Check that you have proper permissions on the server
- This is normal for certain system sessions (like Session 0)
- Some disconnected sessions may not retain their GUID in the registry
- Verify you're running on a Windows Server with Terminal Services enabled
- Check that the Remote Desktop Services role is installed
- System Administration: Monitor active and disconnected user sessions
- Remote Desktop Management: Track RDP connections and their states
- Security Auditing: Identify user sessions and their unique identifiers
- Session Management Scripts: Integrate with automation tools for session cleanup
- Troubleshooting: Diagnose session-related issues on Terminal Servers
This project is provided as-is for educational and administrative purposes.
Feel free to submit issues, fork the repository, and create pull requests for any improvements.