This script is used to shutdown the computer while performing several task.

Download Shutdown (vbs file)

  1. ' ********************************************************
  2. ' FILE: ShutdownScript.vbs
  3. ' VERSION: 1.1
  4. ' CREATED: 3/21/2004
  5. ' UPDATED:   6/28/2004
  6. ' AUTHOR:    Scott Greenberg
  7. ' COMPANY:   SG Technology
  8. ' WEBSITE: http://gogogadgetscott.info
  9. ' DECRIPTION:
  10. ' COMMENT: N/A
  11. ' Copyright© 2004. SG Technology. All rights reserved.
  12. ' *********************************************************
  13. Set SH = CreateObject ("WScript.Shell")
  14. Set FS = CreateObject ("Scripting.FileSystemObject")
  15. CreateSC
  16. RemoveRegKey "AIM"
  17. RemoveRegKey "TkBellExe"
  18. RemoveRegKey "NvCplDaemon"
  19. RemoveRegKey "StarSkin"
  20. ShutdownOutlook
  21. 'EmptyBin
  22. Shutdown
  23. Set Shell = Nothing
  24. Set SH = Nothing
  25. Set FS = Nothing
  26. WScript.Quit
  27. Function ScriptPath
  28.   sPath = WScript.ScriptFullName
  29.   ScriptPath = Left (sPath,InStrRev (sPath,"\"))
  30. End Function
  31. '==========================================================
  32. ' Create desktop shortcut To script
  33. '==========================================================
  34. Sub CreateSC()
  35.   sDesktop = SH.SpecialFolders("Desktop")
  36.   Set oSC = SH.CreateShortcut(sDesktop & "\ShutdownScript.lnk")
  37.   oSC.TargetPath = WScript.ScriptFullName
  38.   oSC.WindowStyle = 1
  39.   oSC.Hotkey = "CTRL+ALT+D"
  40.   oSC.IconLocation = "shell32.dll, 27"
  41.   'oSC.IconLocation = "explorer.exe, 0"
  42.   oSC.Description = "Shutdown Computer Script"
  43.   oSC.WorkingDirectory = sDesktop
  44.   oSC.Save
  45. End Sub
  46. '==========================================================
  47. ' Backup Windows registry
  48. '==========================================================
  49. Sub BackupReg()
  50.   ' Needs Fix For windows XP
  51.   Const FILE_BackupReg = "backupreg.bat"
  52.   Set fBat = FS.CreateTextFile(FILE_BackupReg, True )
  53.   fBat.WriteLine "cd\windows"
  54.   fBat.WriteLine "attrib -s -h -r *.dat"
  55.   fBat.WriteLine "copy user.dat user.sav"
  56.   fBat.WriteLine "copy system.dat system.sav"
  57.   Set fBat = Nothing
  58.   SH.Run FILE_BackupReg, 0, True
  59. End Sub
  60. '==========================================================
  61. ' Remove unwanted startup registry key from machine And user
  62. '==========================================================
  63. Sub RemoveRegKey(sKey)
  64.   sKey = "\Software\Microsoft\Windows\CurrentVersion\Run\" & sKey
  65.   On Error Resume Next
  66.   SH.RegDelete "HKCU" & sKey
  67.   SH.RegDelete "HKLM" & sKey
  68. End Sub
  69. '==========================================================
  70. ' Empty the recycle bin
  71. '==========================================================
  72. Sub EmptyBin()
  73.   Set fEBin = FS.CreateTextFile(ScriptPath & "Tmp_EBin.vbs",2)
  74.   fEBin.writeline "Set FS = CreateObject (""Scripting.FileSystemObject"")"
  75.   fEBin.writeline "Set Shell = CreateObject (""Shell.Application"")"
  76.   fEBin.writeline "Set oFolder = FS.GetFolder(""C:\RECYCLER"")"
  77.   fEBin.writeline "If (Not oFolder Is Nothing ) Then "
  78.   fEBin.writeline "   For Each oFldr In oFolder.SubFolders"
  79.   fEBin.writeline " Set oNS = Shell.NameSpace(oFldr.Path)"
  80.   fEBin.writeline " If (Not oFolder Is Nothing ) Then "
  81.   fEBin.writeline "   oNS.Self.InvokeVerb(""Empty Recycle &Bin"")"
  82.   fEBin.writeline "   Set oNS = Nothing "
  83.   fEBin.writeline "   Exit For "
  84.   fEBin.writeline " End If "
  85.   fEBin.writeline " Next "
  86.   fEBin.writeline " Set oFolder = Nothing "
  87.   fEBin.writeline "End If "
  88.   fEBin.writeline "Set FS = Nothing "
  89.   fEBin.writeline "Set Shell = Nothing "
  90.   fEBin.close
  91.   iReturn = SH.Run("""" & ScriptPath & "Tmp_EBin.vbs""", 1, False )
  92.   WScript.Sleep 650
  93.   iReturn = SH.AppActivate("Confirm Multiple File Delete")
  94.   If iReturn = False Then
  95.     iReturn = SH.AppActivate("Confirm File Delete")
  96.   End If
  97.   If iReturn = True Then
  98.     SH.SendKeys("{ENTER}")
  99.   End If
  100.   ' Delete temp file
  101.   FS.DeleteFile ScriptPath & "Tmp_EBin.vbs"
  102. End Sub
  103. '==========================================================
  104. ' Shutdown Microsoft Outlook, only needed For Outlook XP,
  105. ' As other versions will close properly at a windows
  106. ' invoked Shellutdown
  107. '==========================================================
  108. Sub ShutdownOutlook()
  109.   Set olApp = CreateObject ("Outlook.Application")
  110.   olApp.Quit()
  111.   Set olApp = Nothing
  112. End Sub
  113. '==========================================================
  114. ' Shutdown computer
  115. '==========================================================
  116. Sub Shutdown()
  117.   SH.Run "shutdown -s -t 1", 0, True
  118. End Sub

Download Shutdown (vbs file)