Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (2024)

In this article, we’ll describe how to get and audit the RDP connection logs in Windows. The RDP connection logs allow RDS terminal servers administrators to get information about which users logged on to the server when a specific RDP user logged on and ended up the session, and from which device (DNS name or IP address) the user logged on.

Contents:

  • RDP Connection Events in Windows Event Viewer
  • Getting Remote Desktop Login History with PowerShell
  • Outgoing RDP Connection Logs in Windows

The article is applicable when analyzing RDP logs for both Windows Server 2022/2019/2016/2012R2 and to desktop editions (Windows 11, 10, and 8.1).

RDP Connection Events in Windows Event Viewer

When a user connects to a Remote Desktop-enabled or RDS host, information about these events is stored in the Event Viewer logs (eventvwr.msc). Consider the main stages of RDP connection and related events in the Event Viewer, which may be of interest to the administrator

  1. Network Connection;
  2. Authentication;
  3. Logon;
  4. Session Disconnect/Reconnect;
  5. Logoff.

Network Connection – establishing a network connection to a server from the user’s RDP client. It is the event with the EventID 1149 (Remote Desktop Services: User authentication succeeded). If this event is found, it doesn’t mean that user authentication has been successful. This log is located in “Applications and Services Logs -> Microsoft -> Windows -> Terminal-Services-RemoteConnectionManager > Operational”. Enable the log filter for this event (right-click the log -> Filter Current Log -> EventId 1149).

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (1)

You can list all RDP connection attempts with PowerShell:

$RDPAuths = Get-WinEvent -LogName 'Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational' -FilterXPath '<QueryList><Query Id="0"><Select>*[System[EventID=1149]]</Select></Query></QueryList>'
[xml[]]$xml=$RDPAuths|Foreach{$_.ToXml()}
$EventData = Foreach ($event in $xml.Event)
{ New-Object PSObject -Property @{
TimeCreated = (Get-Date ($event.System.TimeCreated.SystemTime) -Format 'yyyy-MM-dd hh:mm:ss K')
User = $event.UserData.EventXML.Param1
Domain = $event.UserData.EventXML.Param2
Client = $event.UserData.EventXML.Param3
}
} $EventData | FT

Then you will get an event list with the history of all RDP connections to this server. The logs provide a username, a domain (in this case the Network Level Authentication is used; if NLA is disabled, the event description looks differently), and the IP address of the user’s computer.

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (3)

Authentication shows whether an RDP user has been successfully authenticated on the server or not. The log is located under Windows -> Security. So, you may be interested in the events with the EventID 4624 (An account was successfully logged on) or 4625 (An account failed to log on).

Please, pay attention to the LogonType value in the event description.

  • LogonType = 10 or 3 — if the Remote Desktop service has been used to create a new session during log on;
  • LogonType = 7, means that a user has reconnected to the existing RDP session;
  • LogonType = 5 – RDP connection to the server console (in the mstsc.exe /admin mode).

You can use RDP authentication failure events to protect against RDP brute force attacks. You can automatically block attacker IPs at the Windows Defender Firewall using a simple PowerShell script.

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (4)

In this case, the user name is contained in the event description in the Account Name field, the computer name in the Workstation Name, and the user IP in the Source Network Address.

Please, note the value of the LogonID field. This is a unique user RDP session identifier that helps track the user’s further activity. However, if an RDP session is disconnected and a user reconnects to it, the user will be assigned a new LogonID (although the RDP session remains the same).

You can get a list of successful RDP authentication events (EventID 4624) using this PowerShell command:

Get-EventLog security -after (Get-date -hour 0 -minute 0 -second 0) | ?{$_.eventid -eq 4624 -and $_.Message -match 'logon type:\s+(10)\s'} | Out-GridView

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (5)

Logon refers to an RDP login to Windows. EventID 21 – this event appears after a user has been successfully authenticated (Remote Desktop Services: Session logon succeeded). This events are located in the “Applications and Services Logs -> Microsoft -> Windows -> TerminalServices-LocalSessionManager -> Operational”. As you can see, here you can find the ID of a user RDP session — Session ID.

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (6)

EventID – 21 (Remote Desktop Services: Shell start notification received) indicates that the Explorer shell has been successfully started (the Windows desktopappears in the user’s RDP session).

Session Disconnect/Reconnect – session disconnection and reconnection events have different IDs depending on what caused the user disconnection (disconnection due to inactivity set in timeouts for RDP sessions, Disconnect option has been selected by the user in the session, RDP session ended by another user or an administrator, etc.). You can find these events in the Event Viewer under “Applications and Services Logs -> Microsoft -> Windows -> TerminalServices-LocalSessionManager -> Operational”. Let’s consider the RDP Event IDs that might be useful:

  • EventID – 24 (Remote Desktop Services: Session has been disconnected) –a user has disconnected from the RDP session;
  • EventID – 25 (Remote Desktop Services: Session reconnection succeeded) – a user has reconnected to the existing RDP session on the server;
  • EventID – 39 (Session <A> has been disconnected by session <B>) – a user has disconnected from the RDP session by selecting the corresponding menu option (instead of just closing the RDP client window). If the session IDs are different, a user has been disconnected by another user (or administrator);
  • EventID – 40 (Session <A> has been disconnected, reason code <B>). Here you must check the disconnection reason code in the event description. For example:
    • reason code 0 (No additional information is available) means that a user has just closed the RDP client window;
    • reason code 5 (The client’s connection was replaced by another connection) means that a user has reconnected to the previous RDP session;
    • reason code 11 (User activity has initiated the disconnect) a user has clicked the Disconnect button in the start menu.

EventID 4778 in Windows -> Security log (A session was reconnected to a Window Station). A user has reconnected to an RDP session (a user is assigned a new LogonID).

EventID 4779 in “Windows -> Security” log (A session was disconnected from a Window Station). A user has been disconnected from an RDP session.

Logoff refers to the end of a user session. It is logged as the event with the EventID 23 (Remote Desktop Services: Session logoff succeeded) under “Applications and Services Logs -> Microsoft -> Windows -> TerminalServices-LocalSessionManager -> Operational”.

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (7)

At the same time the EventID 4634(An account was logged off) appears in the Security log.

The EventID 9009 (The Desktop Window Manager has exited with code <X>) in the System log means that a user has initiated logoff from the RDP session with both the window and the graphic shell of the user have been terminated.

EventID 4647 — User-initiated logoff

Getting Remote Desktop Login History with PowerShell

Here is a short PowerShell script that lists the history of all RDP connections for the current day from the terminal RDS server event logs. The resulting table shows the connection time, the client’s IP address (DNS computername), and the remote user name (if necessary, you can include other LogonTypes in the report).

Get-EventLog -LogName Security -after (Get-date -hour 0 -minute 0 -second 0)| ?{(4624,4778) -contains $_.EventID -and $_.Message -match 'logon type:\s+(10)\s'}| %{
(new-object -Type PSObject -Property @{
TimeGenerated = $_.TimeGenerated
ClientIP = $_.Message -replace '(?smi).*Source Network Address:\s+([^\s]+)\s+.*','$1'
UserName = $_.Message -replace '(?smi).*\s\sAccount Name:\s+([^\s]+)\s+.*','$1'
UserDomain = $_.Message -replace '(?smi).*\s\sAccount Domain:\s+([^\s]+)\s+.*','$1'
LogonType = $_.Message -replace '(?smi).*Logon Type:\s+([^\s]+)\s+.*','$1'
})
} | sort TimeGenerated -Descending | Select TimeGenerated, ClientIP `
, @{N='Username';E={'{0}\{1}' -f $_.UserDomain,$_.UserName}} `
, @{N='LogType';E={
switch ($_.LogonType) {
2 {'Interactive - local logon'}
3 {'Network connection to shared folder)'}
4 {'Batch'}
5 {'Service'}
7 {'Unlock (after screensaver)'}
8 {'NetworkCleartext'}
9 {'NewCredentials (local impersonation process under existing connection)'}
10 {'RDP'}
11 {'CachedInteractive'}
default {"LogType Not Recognised: $($_.LogonType)"}
}
}}

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (8)

This method allows you to collect and parse RDP connection logs on a standalone RDSH server. If you have multiple servers in the RDS farm, you can query each of them with this script, or get logs from a management server with the Remote Desktop Connection Broker role.

You can export RDP connection logs from the Event Viewer to a CSV file (for further analysis in an Excel spreadsheet). You can export the log from the Event Viewer GUI (assuming Event Viewer logs are not cleared) or via the command prompt:

WEVTUtil query-events Security > c:\ps\rdp_security_log.txt

Or with PowerShell:

get-winevent -logname "Microsoft-Windows-TerminalServices-LocalSessionManager/Operational" | Export-Csv c:\ps\rdp_connection_log.txt -Encoding UTF8

If your users connect to corporate RDS hosts through the Remote Desktop Gateway, you can check the user connection logs in the Microsoft-Windows-TerminalServices-Gateway log by the EventID 302. For example, the following PowerShell script will display the specified user’s connection history through RD Gateway:

$rdpusername="b.smith"
$properties = @(
@{n='User';e={$_.Properties[0].Value}},
@{n='Source IP Adress';e={$_.Properties[1].Value}},
@{n='TimeStamp';e={$_.TimeCreated}}
@{n='Target RDP host';e={$_.Properties[3].Value}}
)
(Get-WinEvent -FilterHashTable @{LogName='Microsoft-Windows-TerminalServices-Gateway/Operational';ID='302'} | Select-Object $properties) -match $rdpusername

You can check the following RD Gateway user connection events in the Microsoft-Windows-TerminalServices-Gateway event log:

  • 300 — The user NAME, on client computer DEVICE, met resource authorization policy requirements and was therefore authorized to connect to resource RDPHOST;
  • 302 — The user NAME, on client computer DEVICE, connected to resource RDPHOST;
  • 303 — The user NAME, on client computer DEVICE, disconnected from the following network resource: RDPHOST. Before the user disconnected, the client transferred X bytes and received X bytes. The client session duration was X seconds.

You can display the list of current remote sessions on your RDS host with the command:

qwinsta
The command returns the session ID, the USERNAME, and the session state (Active/Disconnect). This command is useful when you need to get the user’s RDP session ID when using shadow Remote Desktop connections.

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (10)

You can display the list of the running processes in the specific RDP session (the session ID is specified):

qprocess /id:5

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (11)

Outgoing RDP Connection Logs in Windows

You can also view outgoing RDP connection logs on the client side. They are available in the following event log: Application and Services Logs -> Microsoft -> Windows -> TerminalServices-ClientActiveXCore -> Microsoft-Windows-TerminalServices-RDPClient -> Operational.

For example, EventID 1102 occurs when a user connects to a remote Windows Server RDS host or a Windows 10/11 computer with RDP enabled (desktop Windows editions also support multiple simultaneous RDP connections).

The client has initiated a multi-transport connection to the server 192.168.13.201.

The following RDP script will display the history of RDP client connections on the current computer:

$properties = @(
@{n='TimeStamp';e={$_.TimeCreated}}
@{n='LocalUser';e={$_.UserID}}
@{n='Target RDP host';e={$_.Properties[1].Value}}
)
Get-WinEvent -FilterHashTable @{LogName='Microsoft-Windows-TerminalServices-RDPClient/Operational';ID='1102'} | Select-Object $properties

The script returns the SIDs of the users who initiated RDP connections on this computer, as well as the DNS names/IP addresses of the Remote Desktop hosts that the users connected to. You can convert SIDs to usernames as follows.

Also, you can check the RDP connection history in the user’s registry.

About RDP Connection Logs in Windows

As an enthusiast with demonstrable expertise in Windows RDP connection logs, I can provide comprehensive information on how to obtain and audit RDP connection logs in Windows. The process involves using the Windows Event Viewer and PowerShell to gather information about user logins, session events, and disconnections. The logs allow administrators to track user activities, including login times, IP addresses, and session IDs.

RDP Connection Events in Windows Event Viewer

When a user connects to a Remote Desktop-enabled or RDS host, information about these events is stored in the Event Viewer logs. These events include Network Connection, Authentication, Logon, Session Disconnect/Reconnect, and Logoff. Each event is associated with specific EventIDs and can be found in different locations within the Event Viewer.

Network Connection: This event is recorded with EventID 1149 and is located in "Applications and Services Logs -> Microsoft -> Windows -> Terminal-Services-RemoteConnectionManager > Operational" [[SOURCE 1]].

Authentication: Authentication events are located under Windows -> Security and can be identified by EventIDs 4624 (successful login) or 4625 (failed login). The LogonType value in the event description provides additional information about the type of login [[SOURCE 1]].

Logon: EventID 21 indicates a successful session logon, and EventID 21 indicates the successful start of the Explorer shell [[SOURCE 1]].

Session Disconnect/Reconnect: Events related to session disconnection and reconnection have different IDs and can be found in the Event Viewer under "Applications and Services Logs -> Microsoft -> Windows -> TerminalServices-LocalSessionManager -> Operational" [[SOURCE 1]].

Logoff: The end of a user session is logged as EventID 23 under "Applications and Services Logs -> Microsoft -> Windows -> TerminalServices-LocalSessionManager -> Operational" [[SOURCE 1]].

Getting Remote Desktop Login History with PowerShell

PowerShell can be used to list all RDP connection attempts and gather detailed information about successful RDP authentication events. Additionally, PowerShell scripts can be utilized to export RDP connection logs from the Event Viewer to a CSV file for further analysis [[SOURCE 1]].

Outgoing RDP Connection Logs in Windows

Outgoing RDP connection logs on the client side can also be viewed using the Event Viewer. These logs provide information about RDP client connections, including the timestamp, local user, and target RDP host [[SOURCE 1]].

In addition to the Event Viewer, PowerShell scripts can be employed to display the history of RDP client connections on the current computer, providing details about the users who initiated RDP connections and the Remote Desktop hosts they connected to [[SOURCE 1]].

Overall, the process of obtaining and auditing RDP connection logs in Windows involves leveraging the Event Viewer and PowerShell to gather comprehensive information about user logins, session events, and disconnections.

If you have any specific questions or need further details about any aspect of RDP connection logs in Windows, feel free to ask!

Tracking and Analyzing Remote Desktop Connection Logs in Windows | Windows OS Hub (2024)

FAQs

How do I view remote desktop connection logs? ›

Every time a user successfully connects remotely, an event log will be recorded in the Event Viewer. To view this remote desktop activity log, go to the Event Viewer. Under Applications and Services Logs -> Microsoft -> Windows -> Terminal-Services-RemoteConnectionManager > Operational.

How do I track a remote desktop connection? ›

Howto check RDP Windows Server connection logs
  1. Navigate here: Applications and Services Logs > Microsoft > Windows > TerminalServices-RemoteConnectionManager > Operational. ...
  2. The Event ID of Remote Desktop Services is 1149. ...
  3. Then you will get an event list with the history of all RDP connections to this server.
Dec 28, 2022

Can you see Remote Desktop Connection history? ›

You can view the remote-control history of a specific computer. To view the history of all computers, follow the steps given below: Navigate to Admin > Tools > Action Log Viewer. In the Select Module Type section, check the Remote Control checkbox.

How do I view Windows connection logs? ›

To find these logs, search for the Event Viewer. Alternatively, from the Control Panel, choose Administrative Tools and then Event Viewer. Within Event Viewer, navigate to each log: System: Expand Windows Logs; System will be listed underneath.

Where is the Remote Desktop Connection in Windows? ›

When you're ready, select Start > Settings > System > Remote Desktop, and turn on Enable Remote Desktop.

How do I see who is remotely logged into my computer? ›

On a Windows computer, go to the Control Panel > System and Security > Administrative Tool > Event Viewer. Then, on the left side, select Security and review all login events. On a Mac, you need third-party software to review login attempts or remote sessions.

How can I track my computer activity? ›

Windows Event Viewer is a dedicated system app for Windows users that allows you to track computer usage. You can find it on every Windows computer. You can find it either by clicking on the Windows key and searching it in apps or accessing it in local files (in Administrative Tools).

How can I track my computer activity history? ›

Use Windows Event Viewer to Check Computer Events
  1. Press the Windows key on your keyboard – the Windows symbol is found in the bottom-left corner of most keyboards, between the CTRL and ALT keys.
  2. Type Event – this will highlight Event Viewer in the search box.
  3. Press the Enter key to launch Event Viewer.

Which directory are log files stored? ›

In general, log files are often stored in a subdirectory within the application's installation directory or in a system directory such as /var/log on Linux or macOS.

Where are the Remote Desktop Connection files stored? ›

Default. rdp is stored for each user as a hidden file in the user's Documents folder. User created . rdp files are saved by default in the user's Documents folder, but can be saved anywhere.

How to see who is logged into a remote computer using CMD? ›

Step 1- Open the Command Line Interface by running "cmd" in the run dialog box (Win + R). Step 2- Type query user and press Enter. It will list all users that are currently logged on your computer.

Where are recent RDP sessions stored? ›

Windows also stores recent remote desktop connections in Jump Lists. If you type mstsc in the Windows search box or right-click on the client in the taskbar, you will see the history of previous RDP connections in the Recent list.

Where is allow log on through Remote Desktop Services? ›

The Remote Logon is governed by the “Allow Logon through Terminal Services” group policy. This is under Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment. By default, the Administrators and Remote Desktop Users groups are given remote logon rights.

Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 5917

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.