Windows
View all Worklets
WindowsWindows

Windows - Security - Force Log Off Current User

Force terminates the active logged-in user session on Windows endpoints immediately

Worklet Details

What the user session terminator does

This Automox Worklet™ force logs off the currently logged-in user and terminates their active session on Windows endpoints. The Worklet uses PowerShell to detect the logged-in user, force disconnect their session, and validate that the session has been fully terminated.

The Worklet employs Win32_ComputerSystem and Win32_OperatingSystem classes to manage session termination. During remediation, it invokes the Win32Shutdown method with forced logout flag (4) to immediately disconnect the user without notifications to running applications.

After initiating the logout, the Worklet enters a verification loop that monitors endpoint session status for up to three minutes, checking every five seconds to confirm the user has been disconnected. This confirms the logout command executed successfully before reporting completion.

Why force log off user sessions

Forcing user session termination is essential for security, compliance, and operational efficiency. Organizations use session termination to enforce access control policies, disconnect users during security incidents, or revoke access when users leave departments or organizations.

Session termination also supports maintenance windows, software deployments, and system updates that require endpoints to be in a disconnected state. This prevents data loss from unsaved work and ensures critical updates can proceed without user interference or approval delays.

For IT operations teams managing large endpoint fleets, automated session termination eliminates manual intervention and maintains consistent enforcement across all Windows workstations and servers. This is particularly valuable for organizations with distributed teams or high turnover rates.

How user session termination works

  1. Evaluation phase: Queries the endpoint using Get-CimInstance to identify the currently logged-in user by parsing the Win32_ComputerSystem UserName property. If a user is detected, the endpoint is flagged for remediation. If no user is logged in, the endpoint is marked compliant and the Worklet exits.

  2. Remediation phase: Invokes Win32Shutdown method with forced logout flag (4) to immediately disconnect the logged-in user without application notifications. The Worklet then loops for up to three minutes checking endpoint session status every five seconds. Once the session is confirmed disconnected, or if three minutes elapse, the Worklet reports success or failure to the Automox Activity Log.

Session termination requirements

  • Windows endpoints: Workstations or servers (Windows 7 and later)

  • PowerShell 3.0 or later

  • Administrator privileges to invoke Win32_OperatingSystem methods

  • No special configuration required; the Worklet operates with default Windows API access

Expected session disconnection state

After the Worklet completes remediation, the targeted endpoint enters a logged-off state. All user sessions are terminated, applications close immediately without notification, and the endpoint displays the Windows login screen. The Automox Activity Log contains detailed output confirming the username that was logged off and the timestamp of the successful disconnection.

If the Worklet times out after three minutes of verification, it reports failure to the Activity Log. This may occur if the user account is protected by special permissions or if the endpoint is unresponsive. System administrators can then investigate further or manually disconnect the session using remote administration tools.

How to validate force log off current user changes

  1. Run this Worklet on a pilot Windows endpoint and review evaluation output for force log off current user.

  2. Confirm Automox activity logs show successful completion and exit code 0.

  3. Verify endpoint state using checks aligned to evaluation script logic, such as Get-CimInstance, Select-Object, Write-Output.

  4. Validate remediation effects from script operations such as Get-CimInstance, Select-Object, Write-Output, then rerun evaluation for compliance.

View in app
evalutation image
remediation image

Consider Worklets your easy button

What's a Worklet?

A Worklet is an automation script, written in Bash or PowerShell, designed for seamless execution on endpoints – at scale – within the Automox platform. Worklet automation scripts perform configuration, remediation, and the installation or removal of applications and settings across Windows, macOS, and Linux.

do more with worklets