Tuesday, July 15, 2014

Call PowerShell from CMD.exe and a application-prelaunch script that logs the user off when the application is exited.

        > "%TEMP%\proc_logoff.ps1" echo Start-Sleep -s 60
       >> "%TEMP%\proc_logoff.ps1" echo $localSession = Get-ChildItem 'HKCU:\Volatile Environment' -name
       >> "%TEMP%\proc_logoff.ps1" echo $process = get-process ^| where {$_.sessionID -eq $localSession} ^| where {$_.processName -eq "MetaVision"}
       >> "%TEMP%\proc_logoff.ps1" echo if ($process -eq $null) {logoff.exe}
       >> "%TEMP%\proc_logoff.ps1" echo $process.waitforexit()
       >> "%TEMP%\proc_logoff.ps1" echo logoff.exe
powershell.exe -ExecutionPolicy Unrestricted -WindowStyle Hidden -File "%TEMP%\proc_logoff.ps1" 

I should comment this later, for now, this is the whole script.

No comments:

Post a Comment