home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: logoff.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: Forces logoff at a certain time and provides notifications.
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared
- ' ~~~
- Option Explicit
-
- ' ~~~ Turn on error handling
- On Error Resume Next
-
- ' ~~~
- ' ~~~ Declare global variables and constants
- ' ~~~
- Dim oShell, OpSys, OpSysSet, sSessionLength, sLogOffRestart, sBinDir, q, iRestart
- Const TOOLKITKEY = "HKLM\Software\Microsoft\Shared Computer Toolkit\"
- Const TOOLKITKEY2 = "HKCU\Software\Microsoft\Shared Computer Toolkit\"
-
- q = Chr(34)
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create objects
- ' ~~~ ------------------------------------------------------------------------------
- Set oShell = CreateObject("WScript.Shell")
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Get values from registry
- ' ~~~ ------------------------------------------------------------------------------
- sBinDir = oShell.RegRead(TOOLKITKEY & "TargetDir") & "bin"
-
- sSessionLength = "Failed"
- sSessionLength = oShell.RegRead(TOOLKITKEY2 & "LogoffAfter")
- sLogOffRestart = "LogOff"
- Err.Clear
- iRestart = oShell.RegRead(TOOLKITKEY2 & "ForceRestart")
- If Err.Number = 0 AND iRestart Then
- sLogOffRestart = "Restart"
- End If
-
- If sSessionLength = "Failed" Then
- ' ~~~ If no LogoffAfter registry key, don't do automatic logoff
- WScript.Quit(0)
- Else
- ' ~~~ If LogoffAfter set to less than 5 minutes, set it to five minutes
- If sSessionLength < 5 Then sSessionLength = 5
- End If
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Start toast process so user knows session length
- ' ~~~ ------------------------------------------------------------------------------
- Call oShell.Run(q & sBinDir & "\toast.vbs" & q & sSessionLength & " 0", 0, False)
-
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Start two toast processes - for 5 minute warning and 1 minute warning
- ' ~~~ ------------------------------------------------------------------------------
- Call oShell.Run(q & sBinDir & "\toast.vbs" & q & " 5 " & (sSessionLength - 5), 0, False)
- Call oShell.Run(q & sBinDir & "\toast.vbs" & q & " 1 " & (sSessionLength - 1), 0, False)
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Use wmi to logoff after time passes
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Sleep(sSessionLength * 60000)
-
- Call oShell.Run(q & sBinDir & "\ForceLogoff.exe" & q & " /" & sLogOffRestart, 1, False)
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Done!
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Quit(0)
-