home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileBin019 < prev    next >
Encoding:
Text (UTF-16)  |  2005-09-02  |  6.7 KB  |  80 lines

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        logoff.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    Forces logoff at a certain time and provides notifications.
  6. ' *** ------------------------------------------------------------------------------
  7. ' *** Version:        1.0
  8. ' *** ------------------------------------------------------------------------------
  9. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  10. ' *** ------------------------------------------------------------------------------
  11. ' *** 
  12.  
  13. ' ~~~ 
  14. ' ~~~ Force variables to be declared 
  15. ' ~~~ 
  16. Option Explicit
  17.  
  18. ' ~~~ Turn on error handling
  19. On Error Resume Next
  20.  
  21. ' ~~~ 
  22. ' ~~~ Declare global variables and constants
  23. ' ~~~ 
  24. Dim oShell, OpSys, OpSysSet, sSessionLength, sLogOffRestart, sBinDir, q, iRestart
  25. Const TOOLKITKEY  = "HKLM\Software\Microsoft\Shared Computer Toolkit\"
  26. Const TOOLKITKEY2 = "HKCU\Software\Microsoft\Shared Computer Toolkit\"
  27.  
  28. q = Chr(34)
  29.  
  30. ' ~~~ ------------------------------------------------------------------------------
  31. ' ~~~ Create objects
  32. ' ~~~ ------------------------------------------------------------------------------
  33. Set oShell = CreateObject("WScript.Shell")
  34.  
  35. ' ~~~ ------------------------------------------------------------------------------
  36. ' ~~~ Get values from registry
  37. ' ~~~ ------------------------------------------------------------------------------
  38. sBinDir        = oShell.RegRead(TOOLKITKEY & "TargetDir") & "bin"
  39.  
  40. sSessionLength = "Failed"
  41. sSessionLength = oShell.RegRead(TOOLKITKEY2 & "LogoffAfter")
  42. sLogOffRestart = "LogOff"
  43. Err.Clear
  44. iRestart = oShell.RegRead(TOOLKITKEY2 & "ForceRestart") 
  45. If Err.Number = 0 AND iRestart Then
  46.     sLogOffRestart = "Restart"
  47. End If
  48.  
  49. If sSessionLength = "Failed" Then 
  50.     ' ~~~ If no LogoffAfter registry key, don't do automatic logoff
  51.     WScript.Quit(0)
  52. Else
  53.     ' ~~~ If LogoffAfter set to less than 5 minutes, set it to five minutes
  54.     If sSessionLength < 5 Then sSessionLength = 5
  55. End If
  56.  
  57. ' ~~~ ------------------------------------------------------------------------------
  58. ' ~~~ Start toast process so user knows session length
  59. ' ~~~ ------------------------------------------------------------------------------
  60. Call oShell.Run(q & sBinDir & "\toast.vbs" & q & sSessionLength & " 0", 0, False)
  61.  
  62.  
  63. ' ~~~ ------------------------------------------------------------------------------
  64. ' ~~~ Start two toast processes - for 5 minute warning and 1 minute warning
  65. ' ~~~ ------------------------------------------------------------------------------
  66. Call oShell.Run(q & sBinDir & "\toast.vbs" & q & " 5 " & (sSessionLength - 5), 0, False)
  67. Call oShell.Run(q & sBinDir & "\toast.vbs" & q & " 1 " & (sSessionLength - 1), 0, False)
  68.  
  69. ' ~~~ ------------------------------------------------------------------------------
  70. ' ~~~ Use wmi to logoff after time passes
  71. ' ~~~ ------------------------------------------------------------------------------
  72. WScript.Sleep(sSessionLength * 60000)
  73.  
  74. Call oShell.Run(q & sBinDir & "\ForceLogoff.exe" & q & " /" & sLogOffRestart, 1, False)
  75.  
  76. ' ~~~ ------------------------------------------------------------------------------
  77. ' ~~~ Done!
  78. ' ~~~ ------------------------------------------------------------------------------
  79. WScript.Quit(0)
  80.