ANAVEM
Languagefr
Windows Security Event Viewer displaying Event ID 4647 user logoff events on a security monitoring dashboard
Event ID 4647InformationMicrosoft-Windows-Security-AuditingWindows

Windows Event ID 4647 – Microsoft-Windows-Security-Auditing: User Initiated Logoff

Event ID 4647 records when a user initiates a logoff from a Windows session. This security audit event tracks user-initiated disconnections for compliance and security monitoring purposes.

Emanuel DE ALMEIDAEmanuel DE ALMEIDA
18 March 20269 min read 0
Event ID 4647Microsoft-Windows-Security-Auditing 5 methods 9 min
Event Reference

What This Event Means

Event ID 4647 is generated by the Windows Security Auditing subsystem when a user explicitly initiates a logoff action. This event is part of the logon/logoff audit category and requires the "Audit Logoff" policy to be enabled. The event captures the exact moment when a user decides to end their session, providing a clear audit trail of user-initiated session terminations.

The event contains critical information including the user's Security Identifier (SID), account name, domain, logon ID, and logon type. This data helps administrators correlate logoff events with corresponding logon events (4624) to calculate session duration and analyze user behavior patterns. The logon ID field is particularly important as it links the logoff event to the specific logon session that's being terminated.

Windows generates this event through the Local Security Authority (LSA) when the ExitWindowsEx API is called with the EWX_LOGOFF flag, or when users select logoff options through the Windows interface. The event timing is precise, occurring before the actual session cleanup begins, ensuring that all session-related information is still available for logging. This makes Event ID 4647 more reliable than other session termination events for tracking intentional user actions versus system-initiated disconnections.

Applies to

Windows 10Windows 11Windows Server 2019/2022/2025
Analysis

Possible Causes

  • User clicking "Sign out" from the Start menu or user account menu
  • User selecting "Log off" from Ctrl+Alt+Del security screen
  • Applications calling ExitWindowsEx API with EWX_LOGOFF flag
  • Remote Desktop users disconnecting through proper logoff procedures
  • Terminal Services users ending sessions through logoff commands
  • Scheduled tasks or scripts executing logoff operations
  • Group Policy enforced logoffs due to time restrictions
  • Smart card removal triggering automatic logoff (when configured)
Resolution Methods

Troubleshooting Steps

01

Review Event Details in Event Viewer

Start by examining the event details to understand the logoff context and user information.

  1. Open Event Viewer by pressing Win + R, typing eventvwr.msc, and pressing Enter
  2. Navigate to Windows LogsSecurity
  3. Filter for Event ID 4647 by right-clicking the Security log and selecting Filter Current Log
  4. Enter 4647 in the Event IDs field and click OK
  5. Double-click on a 4647 event to view detailed information including:
    • Subject: User account that initiated the logoff
    • Logon ID: Unique identifier linking to the original logon event
    • Logon Type: Method used for the original logon (2=Interactive, 3=Network, 10=RemoteInteractive)
  6. Note the timestamp and correlate with any security incidents or user reports
Pro tip: Use the Logon ID to find the corresponding Event ID 4624 (logon) to calculate total session duration.
02

Query Events with PowerShell

Use PowerShell to efficiently query and analyze Event ID 4647 occurrences across specific timeframes.

  1. Open PowerShell as Administrator
  2. Query recent logoff events with basic filtering:
    Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4647} -MaxEvents 50 | Format-Table TimeCreated, Id, LevelDisplayName, Message -Wrap
  3. Filter events for specific users or timeframes:
    # Filter by specific user
    $Events = Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4647; StartTime=(Get-Date).AddDays(-7)}
    $Events | Where-Object {$_.Message -like "*username*"} | Format-List TimeCreated, Message
  4. Extract detailed information from event properties:
    # Parse event details
    $LogoffEvents = Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4647} -MaxEvents 20
    foreach ($Event in $LogoffEvents) {
        $EventXML = [xml]$Event.ToXml()
        $SubjectUserName = $EventXML.Event.EventData.Data | Where-Object {$_.Name -eq 'SubjectUserName'} | Select-Object -ExpandProperty '#text'
        $LogonId = $EventXML.Event.EventData.Data | Where-Object {$_.Name -eq 'SubjectLogonId'} | Select-Object -ExpandProperty '#text'
        Write-Output "Time: $($Event.TimeCreated) | User: $SubjectUserName | Logon ID: $LogonId"
    }
  5. Export results for further analysis:
    Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4647; StartTime=(Get-Date).AddDays(-30)} | Export-Csv -Path "C:\Temp\Logoff_Events.csv" -NoTypeInformation
03

Correlate Logon and Logoff Events

Match Event ID 4647 with corresponding logon events to analyze session patterns and identify anomalies.

  1. Create a PowerShell script to correlate logon (4624) and logoff (4647) events:
    # Get logon and logoff events from the last 24 hours
    $StartTime = (Get-Date).AddDays(-1)
    $LogonEvents = Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4624; StartTime=$StartTime}
    $LogoffEvents = Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4647; StartTime=$StartTime}
    
    # Create correlation table
    $SessionData = @()
    foreach ($LogoffEvent in $LogoffEvents) {
        $LogoffXML = [xml]$LogoffEvent.ToXml()
        $LogonId = $LogoffXML.Event.EventData.Data | Where-Object {$_.Name -eq 'SubjectLogonId'} | Select-Object -ExpandProperty '#text'
        $UserName = $LogoffXML.Event.EventData.Data | Where-Object {$_.Name -eq 'SubjectUserName'} | Select-Object -ExpandProperty '#text'
        
        # Find matching logon event
        $MatchingLogon = $LogonEvents | Where-Object {
            $LogonXML = [xml]$_.ToXml()
            $LogonLogonId = $LogonXML.Event.EventData.Data | Where-Object {$_.Name -eq 'SubjectLogonId'} | Select-Object -ExpandProperty '#text'
            $LogonLogonId -eq $LogonId
        } | Select-Object -First 1
        
        if ($MatchingLogon) {
            $SessionDuration = $LogoffEvent.TimeCreated - $MatchingLogon.TimeCreated
            $SessionData += [PSCustomObject]@{
                User = $UserName
                LogonTime = $MatchingLogon.TimeCreated
                LogoffTime = $LogoffEvent.TimeCreated
                Duration = $SessionDuration.ToString()
                LogonId = $LogonId
            }
        }
    }
    
    $SessionData | Format-Table -AutoSize
  2. Identify unusual session patterns such as very short or very long sessions
  3. Look for logoff events without corresponding logon events, which might indicate log tampering
04

Configure Advanced Audit Policies

Ensure proper audit policy configuration to capture all relevant logoff events and optimize logging settings.

  1. Check current audit policy settings:
    auditpol /get /category:"Logon/Logoff"
  2. Enable detailed logon/logoff auditing if not already configured:
    # Enable logoff auditing
    auditpol /set /subcategory:"Logoff" /success:enable /failure:enable
    
    # Verify the setting
    auditpol /get /subcategory:"Logoff"
  3. Configure Group Policy for enterprise environments:
    • Open Group Policy Management Console
    • Navigate to Computer ConfigurationPoliciesWindows SettingsSecurity SettingsAdvanced Audit Policy Configuration
    • Expand Audit PoliciesLogon/Logoff
    • Configure Audit Logoff to Success and Failure
  4. Set Security log size to accommodate increased logging:
    # Increase Security log size to 100MB
    wevtutil sl Security /ms:104857600
  5. Configure log retention policy in registry:
    # Set log retention (1 = overwrite as needed, 0 = overwrite events older than X days)
    Set-ItemProperty -Path "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Security" -Name "Retention" -Value 0
    Set-ItemProperty -Path "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Security" -Name "AutoBackupLogFiles" -Value 1
Warning: Enabling comprehensive audit logging can significantly increase log volume. Monitor disk space and configure appropriate log rotation policies.
05

Implement Automated Monitoring and Alerting

Set up automated monitoring for Event ID 4647 to detect unusual logoff patterns or security incidents.

  1. Create a PowerShell script for continuous monitoring:
    # Monitor-LogoffEvents.ps1
    param(
        [int]$CheckIntervalMinutes = 5,
        [string]$LogPath = "C:\Logs\LogoffMonitoring.log"
    )
    
    $LastCheck = (Get-Date).AddMinutes(-$CheckIntervalMinutes)
    
    while ($true) {
        $NewLogoffs = Get-WinEvent -FilterHashtable @{
            LogName='Security'
            Id=4647
            StartTime=$LastCheck
        } -ErrorAction SilentlyContinue
        
        foreach ($Event in $NewLogoffs) {
            $EventXML = [xml]$Event.ToXml()
            $UserName = $EventXML.Event.EventData.Data | Where-Object {$_.Name -eq 'SubjectUserName'} | Select-Object -ExpandProperty '#text'
            $Domain = $EventXML.Event.EventData.Data | Where-Object {$_.Name -eq 'SubjectDomainName'} | Select-Object -ExpandProperty '#text'
            
            $LogEntry = "$(Get-Date): User logoff detected - $Domain\$UserName at $($Event.TimeCreated)"
            Add-Content -Path $LogPath -Value $LogEntry
            
            # Add alerting logic here (email, SIEM integration, etc.)
            # Example: Send alert for after-hours logoffs
            $Hour = $Event.TimeCreated.Hour
            if ($Hour -lt 6 -or $Hour -gt 22) {
                Write-Warning "After-hours logoff detected: $Domain\$UserName"
            }
        }
        
        $LastCheck = Get-Date
        Start-Sleep -Seconds ($CheckIntervalMinutes * 60)
    }
  2. Schedule the monitoring script as a Windows service or scheduled task
  3. Configure Windows Event Forwarding (WEF) for centralized logging:
    • Set up a Windows Event Collector server
    • Configure source computers to forward Event ID 4647
    • Create custom views and subscriptions for logoff events
  4. Integrate with SIEM solutions using Windows Event Log forwarding or agents
  5. Set up custom Event Viewer tasks to trigger on Event ID 4647:
    • In Event Viewer, right-click on a 4647 event
    • Select Attach Task To This Event
    • Configure automated responses such as running scripts or sending notifications

Overview

Event ID 4647 fires whenever a user initiates a logoff from their Windows session. This security audit event is part of Windows' comprehensive logon/logoff tracking system and appears in the Security log when audit policies are properly configured. Unlike Event ID 4634 which records all session terminations including system-initiated ones, Event ID 4647 specifically captures user-initiated logoffs through the Start menu, Ctrl+Alt+Del, or programmatic logoff calls.

This event is crucial for security monitoring, compliance auditing, and user activity tracking. It provides detailed information about who logged off, when, and from which session. The event fires immediately when a user clicks "Sign out" or when applications call the ExitWindowsEx API with specific flags. System administrators rely on this event to track user behavior, investigate security incidents, and maintain audit trails for regulatory compliance.

The event appears in environments where logon/logoff auditing is enabled through Group Policy. It's particularly valuable in enterprise environments where tracking user sessions is mandatory for security policies or compliance frameworks like SOX, HIPAA, or PCI-DSS.

Frequently Asked Questions

What's the difference between Event ID 4647 and Event ID 4634?+
Event ID 4647 specifically records user-initiated logoffs when someone actively chooses to sign out, while Event ID 4634 captures all session terminations including system-initiated ones like timeouts, disconnections, or forced logoffs. Event 4647 provides more precise tracking of intentional user actions, making it valuable for behavioral analysis and security monitoring. Event 4634 is broader and includes automatic session cleanup events.
Why am I not seeing Event ID 4647 in my Security log?+
Event ID 4647 requires the 'Audit Logoff' policy to be enabled. Check your audit policy settings using 'auditpol /get /subcategory:"Logoff"' command. If it shows 'No Auditing', enable it with 'auditpol /set /subcategory:"Logoff" /success:enable'. In domain environments, ensure Group Policy is configured to audit logoff events. Also verify that the Security log isn't full and has sufficient space to record new events.
Can Event ID 4647 help detect security breaches or unauthorized access?+
Yes, Event ID 4647 is valuable for security analysis when combined with logon events. Unusual patterns like logoffs at odd hours, very short session durations, or logoffs from unexpected locations can indicate compromised accounts or unauthorized access. Correlating 4647 with 4624 (logon) events helps identify suspicious user behavior, automated attacks, or account takeovers. However, it should be part of a comprehensive security monitoring strategy, not relied upon alone.
How can I calculate user session duration using Event ID 4647?+
Match Event ID 4647 (logoff) with the corresponding Event ID 4624 (logon) using the Logon ID field present in both events. The Logon ID uniquely identifies each session, allowing you to correlate the start and end times. Subtract the logon timestamp from the logoff timestamp to get session duration. This is useful for analyzing user productivity, detecting anomalous short sessions that might indicate automated attacks, or identifying users who forget to log off.
What information is contained in Event ID 4647 and how do I extract it?+
Event ID 4647 contains the Subject (user account details including SID, username, and domain), Logon ID (unique session identifier), and Logon Type (method used for original logon). Extract this data using PowerShell by converting the event to XML and parsing the EventData section. Key fields include SubjectUserName, SubjectDomainName, SubjectUserSid, SubjectLogonId, and LogonType. This information helps identify who logged off, when, and from what type of session (interactive, remote, network, etc.).
Documentation

References (2)

Emanuel DE ALMEIDA
Written by

Emanuel DE ALMEIDA

Senior IT Journalist & Cloud Architect

Microsoft MCSA-certified Cloud Architect | Fortinet-focused. I modernize cloud, hybrid & on-prem infrastructure for reliability, security, performance and cost control - sharing field-tested ops & troubleshooting.

Related Windows Events

Windows Security Event Viewer displaying Event ID 4625 authentication failure logs on a security monitoring dashboard
Event 4625
Microsoft-Windows-Security-Auditing
Windows EventInformation

Windows Event ID 4625 – Microsoft-Windows-Security-Auditing: An Account Failed to Log On

Event ID 4625 records failed logon attempts in Windows Security logs. Critical for detecting unauthorized access attempts, brute force attacks, and troubleshooting authentication issues across domain and local accounts.

March 1812 min
Windows Event ID 4771 – Microsoft-Windows-Security-Auditing: Kerberos Pre-authentication Failed
Event 4771
Microsoft-Windows-Security-Auditing
Windows EventWarning

Windows Event ID 4771 – Microsoft-Windows-Security-Auditing: Kerberos Pre-authentication Failed

Event ID 4771 indicates a Kerberos pre-authentication failure, typically caused by incorrect passwords, expired accounts, or time synchronization issues between client and domain controller.

March 1812 min
Windows Security Event Viewer displaying authentication events on a SOC monitoring dashboard
Event 4648
Microsoft-Windows-Security-Auditing
Windows EventInformation

Windows Event ID 4648 – Microsoft-Windows-Security-Auditing: Logon Attempted Using Explicit Credentials

Event ID 4648 fires when a user or process attempts authentication using explicit credentials different from their current logon session, commonly seen with RunAs, network authentication, or service account operations.

March 1812 min
Windows Event Viewer displaying security audit logs with Event ID 4634 logoff events on a SOC monitoring dashboard
Event 4634
Microsoft-Windows-Security-Auditing
Windows EventInformation

Windows Event ID 4634 – Microsoft-Windows-Security-Auditing: An Account Was Logged Off

Event ID 4634 records when a user account logs off from a Windows system. This security audit event tracks logoff activities for compliance and security monitoring purposes.

March 1812 min

Discussion

Share your thoughts and insights

You must be logged in to comment.

Loading comments...