Skip to content

$cs.Sys_isUserLoggedOn

Checks whether a user is currently logged on to the desktop/console session. Takes no parameters.

$cs.Sys_isUserLoggedOn()

None.

Boolean. $true if a user is currently logged on, otherwise $false.

Skip a disruptive forced restart when a user is currently logged on:

Terminal window
if ($cs.Sys_isUserLoggedOn())
{
$cs.Job_WriteLog("A user is logged on, skipping forced restart")
}

Branch between running a step in the logged-on user’s context and a silent SYSTEM-only path:

Terminal window
if ($cs.Sys_isUserLoggedOn())
{
$cs.Job_WriteLog("User is logged on, running configuration script in user context")
Invoke-RunAsLoggedOnUser -command "powershell.exe" -arguments "-ExecutionPolicy Bypass -File `"$global:Packageroot\Configure-UserSettings.ps1`""
}
else
{
$cs.Job_WriteLog("No user logged on, skipping user-context configuration")
}

$cs.Sys_ExistProcess