Thursday, April 21, 2011

Logoff Idle Windows Sessions via Screen Saver

I wrote this in KiXtart and compiled with AdminScript Editor. To see the actual code just run the EXE with a "/SHOWCODE" switch.

The EXE and SCR are the same thing (one does not need the other). A little known fact about Windows....if you rename an EXE to SCR, you can still launch it like an EXE but also launch it through the Screen Saver settings.


Download ZIP
Note: The password to the ZIP is "screensaver" (all lower case - no quotes).

Since I wrote it in KiXtart, the actual base code is this simple call....

$OKCancel = MessageBox("Your Windows Session has been idle for too long and you are about to be logged off!@CRLF@CRLFIf you do not wish to be logged of, Please select CANCEL Now!  Otherwise, your Windows Session will be logged off in less than 1 minute.", "Logging Off Your Session!", 262193, 60)

If Not $OKCancel = 2
$Nul = LogOff(1)
EndIf

Essentially, this is popping a message box to the end user warning them they will be logged out in 1 minute unless they click CANCEL. If you use the "/SHOWCODE" switch, all of the rest of the stuff is the code for the "/SHOWCODE" switch to work.


Screen Saver Logoff Message

To implement:

  1. Put the SCREENSAVER LOGOFF.SCR in the SYSTEM32 folder on the base Windows image (rename the file if you need to).

  2. In a GPO, enforce this as the screen saver and set the timeout desired.

  3. Apply the GPO however desired (Group, Machine, Users, etc.).


Since I was just asked for this, I figured I would post here as I just tested this on Win7 and 2008 R2 and it works on those OSs as well.