home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileScripts009 < prev    next >
Encoding:
Extensible Markup Language  |  2005-09-02  |  23.4 KB  |  310 lines

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' *** 
  5.         ' *** ------------------------------------------------------------------------------
  6.         ' *** Filename:        CriticalUpdates.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Downloads Critical Updates and Commits Windows Disk Protection
  9.         ' *** ------------------------------------------------------------------------------
  10.         ' *** Version:        1.0
  11.         ' *** Notes:        
  12.         ' *** ------------------------------------------------------------------------------
  13.         ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  14.         ' *** ------------------------------------------------------------------------------
  15.         ' ***
  16.     </comment>
  17.     <job>
  18.         <runtime>
  19.             <description>Critical Updates</description>
  20.             <named name="Update"                required="false"  many="false"  helpstring="Downloads and installs Critical Updates" />    
  21.             <named name="Restart"                required="false"  many="false"  helpstring="Restart the computer after the Critical Updates process" />
  22.             <named name="EnableLogin"            required="false"  many="false"  helpstring="Use only if Critical Updates fails to enable accounts" />    
  23.             <example>Example: CriticalUpdates.wsf /Update /Restart</example>
  24.         </runtime>
  25.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  26.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  27.         <?job error="True" debug="False" ?>
  28.         <script language="VBScript" src="../include/Common.vbs"></script>
  29.         <script language="VBScript" src="../include/libWSF.vbs"></script>
  30.         <script language="VBScript" src="../include/clsDiskProtect.vbs"></script>
  31.         <script language="VBScript" src="../include/clsLogging.vbs"></script>
  32.         <script language="VBScript">
  33.         <![CDATA[
  34.             ' ~~~ 
  35.             ' ~~~ Force variables to be declared 
  36.             ' ~~~ 
  37.             Option Explicit
  38.             ' ~~~ Do Not Call Main here... we do not need all those checks in this script 
  39.             Call InitialiseAllObjects()
  40.             If IsAdministrator(False) = False Then
  41.                 ' ~~~ Should be an administrator to use this tool
  42.                 QuitScript()
  43.             End If
  44.             
  45.             ' ~~~ 
  46.             ' ~~~ Declare variables and constants
  47.             ' ~~~ 
  48.             Dim oDiskProtect, iWDPcmdver, iCriticalUpdateMins, oLog
  49.             Dim sAppDir, sCmd1, sCmd2, sCmd3, bOK
  50.             Dim colItems, oItem, sInstaller, oUser
  51.             Dim colOperatingSystems, oOS, iLastBootUpTime, iLocalDateTime, iFirstTaskTime
  52.             ' ~~~ ------------------------------------------------------------------------------
  53.             ' ~~~ Logging
  54.             ' ~~~ ------------------------------------------------------------------------------
  55.             ' ~~~ Create logging object
  56.             Set oLog = New Logging
  57.             ' ~~~ Initiate logging
  58.             Call oLog.Open(GetRootFolder & "\log\CriticalUpdates.wsf.log")
  59.             Call oLog.Write("CriticalUpdates.wsf : Started")
  60.             ' ~~~ Set the WDP.CMD tool version number for CriticalUpdates.wsf
  61.             iWDPcmdVer = 8
  62.             ' ~~~ Create objects
  63.             Set oDiskProtect = New DiskProtect
  64.             sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  65.             If Not(oDiskProtect.Enabled) Then
  66.                 ' ~~~ ------------------------------------------------------------------------------
  67.                 ' ~~~ Delete any WDP AT commands left behind
  68.                 ' ~~~ ------------------------------------------------------------------------------
  69.                 Call oDiskProtect.DefineATCommands
  70.                 sCmd1 = oDiskProtect.sCmd1
  71.                 sCmd2 = oDiskProtect.sCmd2
  72.                 sCmd3 = oDiskProtect.sCmd3
  73.                 Call oDiskProtect.DeleteScheduleTask(sCmd1)
  74.                 Call oDiskProtect.DeleteScheduleTask(sCmd2)
  75.                 Call oDiskProtect.DeleteScheduleTask(sCmd3)
  76.                 Call oShell.Run(chr(34) & sAppDir & "bin\schtasks.exe" & chr(34) & " /Delete /TN SCTWakeUpPC /F", 0, True)
  77.                 ' ~~~ Prevents computer from restarting if no WDP and AT command runs.
  78.                 If WScript.Arguments.Named.Exists("PreventLogin") Then
  79.                     QuitScript()
  80.                 End If
  81.             End If
  82.             ' ~~~ ------------------------------------------------------------------------------
  83.             ' ~~~ Check script usage
  84.             ' ~~~ ------------------------------------------------------------------------------
  85.             ' ~~~ Assume usage is ok
  86.             bOK = True        
  87.             ' ~~~ Simple checks for incorrect usage
  88.             Select Case WScript.Arguments.Named.Count
  89.                 Case 0
  90.                     ' ~~~ Can not call with no parameters
  91.                     bOK = False
  92.             End Select    
  93.             ' ~~~ If incorrect usage display message and quit
  94.             If Not(bOK) Then
  95.                  WScript.Arguments.ShowUsage
  96.                  QuitScript()
  97.             End If
  98.             ' ~~~ Disable Login - Do not run with this switch from command line!
  99.             If WScript.Arguments.Named.Exists("PreventLogin") Then
  100.                 If WScript.Arguments.Named.Exists("Update") Then
  101.                     Call oShell.Run(chr(34) & sAppDir & "bin\ForceLogoff.exe" & chr(34) & " /Logoff", 0, True)
  102.                     Call PreventLogin
  103.                     Call oLog.Write("CriticalUpdates.wsf : PreventLogin called... users cannot log in")
  104.                 Else
  105.                      WScript.Arguments.ShowUsage
  106.                      QuitScript()
  107.                 End If        
  108.             End If
  109.             If WScript.Arguments.Named.Exists("EnableLogin") Then
  110.                 If WScript.Arguments.Named.Exists("Update") or WScript.Arguments.Named.Exists("PreventLogin") Then
  111.                      WScript.Arguments.ShowUsage
  112.                      QuitScript()
  113.                 Else
  114.                      Call AllowLogin
  115.                     Call oLog.Write("CriticalUpdates.wsf : EnableLogin - AllowLogin called... users can now log in")
  116.                      QuitScript()
  117.                 End If        
  118.             End If
  119.             ' ~~~ Run scripts
  120.             If WScript.Arguments.Named.Exists("Update") Then
  121.                 Call ReadRegRun(TOOLKITKEY & "AVUpdateScript")
  122.                 Call oLog.Write("CriticalUpdates.wsf : specified AVUpdate script started: " & RegRead(TOOLKITKEY & "AVUpdateScript"))
  123.                 Call ReadRegRun(TOOLKITKEY & "OtherUpdateScript")
  124.                 Call oLog.Write("CriticalUpdates.wsf : specified OtherUpdate script started: " & RegRead(TOOLKITKEY & "OtherUpdateScript"))
  125.                 Call ReadRegRun(TOOLKITKEY & "WindowsUpdateScript")
  126.                 Call oLog.Write("CriticalUpdates.wsf : specified WindowsUpdate script started: " & RegRead(TOOLKITKEY & "WindowsUpdateScript"))
  127.                 Call oLog.Write("CriticalUpdates.wsf : Update scripts completed")
  128.             End If
  129.             ' ~~~ PreventLogin should only ever be run non-interactively, from the WDP AT scheduled task
  130.             If WScript.Arguments.Named.Exists("PreventLogin") Then
  131.                 ' ~~~ Gets time of last restart and first task    
  132.                 Set colOperatingSystems = oWMIService.ExecQuery _
  133.                     ("Select * from Win32_OperatingSystem")
  134.                 For Each oOS in colOperatingSystems
  135.                     iLastBootUpTime = oOS.LastBootUpTime
  136.                     iLocalDateTime = oOS.LocalDateTime
  137.                 Next
  138.     
  139.                 iFirstTaskTime = Left(iLocalDateTime,8) & RegRead(TOOLKITKEY & "SCTRestart") & ".000000" & Right(iLocalDateTime,4)
  140.     
  141.                 If iFirstTaskTime > iLastBootUpTime Then 
  142.                     ' ~~~ Commit windows disk protection unless in retain changes mode
  143.                     If oDiskprotect.Enabled and (oDiskProtect.BootCommand <> "NO_CMD") Then
  144.                         Call oDiskProtect.Commit
  145.                         Call oLog.Write("CriticalUpdates.wsf : WDP Commit issued for next restart")
  146.                     End If
  147.                 End If
  148.                 ' ~~~ Pause while concurrent updates may be applied
  149.                 iCriticalUpdateMins = 0
  150.                 iCriticalUpdateMins = CInt(RegRead(TOOLKITKEY & "CriticalUpdateMins"))
  151.                 Call oLog.Write("CriticalUpdates.wsf : Waiting for " & iCriticalUpdateMins & " minutes before shutting down computer")
  152.                 WScript.Sleep(iCriticalUpdateMins * 60 * 1000)
  153.                 ' ~~~ Allow local users to log in again
  154.                 Call AllowLogin
  155.                 Call oLog.Write("CriticalUpdates.wsf : AllowLogin called... users can now log in")
  156.             Else
  157.                 ' ~~~ Commit windows disk protection unless in retain changes mode when not run from WDP AT task
  158.                 If oDiskprotect.Enabled and (oDiskProtect.BootCommand <> "NO_CMD") Then
  159.                     Call oDiskProtect.Commit
  160.                     Call oLog.Write("CriticalUpdates.wsf : WDP Commit issued for next restart")
  161.                     Wscript.echo "Windows Disk Protection has been set to save changes with the next restart."
  162.                 End If
  163.             End If
  164.             ' ~~~ Restart the computer (or shut down the computer if SleepWakePC has been used)
  165.             If WScript.Arguments.Named.Exists("Restart") Then
  166.                 ' ~~~ If run non-interactively and the PC is configured by SleepWakePC, then shut down the computer to conserve power.
  167.                 If WScript.Arguments.Named.Exists("PreventLogin") and RegRead(TOOLKITKEY & "SCTWakePC") = "Yes" Then
  168.                     Call oLog.Write("CriticalUpdates.wsf : XPePM shutting down computer")
  169.                     Call oShell.Run(chr(34) & sAppDir & "bin\XPePM.exe" & chr(34) & "  -shutdown", 0, True)
  170.                 Else
  171.                     Call oLog.Write("CriticalUpdates.wsf : Calling restart method... computer will restart")
  172.                     Call oShell.Run(chr(34) & sAppDir & "bin\ForceLogoff.exe" & chr(34) & " /Restart", 0, True)
  173.                 End If
  174.             Else
  175.                 Wscript.echo "Please restart your machine to ensure all Critical Updates are completely installed."
  176.             End If
  177.             ' ~~~ Destroy objects
  178.             Set oDiskProtect = Nothing
  179.             UnLoadObjects()
  180.             ' ~~~ All done!
  181.              QuitScript()
  182.             ' *** 
  183.             ' *** ------------------------------------------------------------------------------
  184.             ' *** Name:        ReadRegRun
  185.             ' *** ------------------------------------------------------------------------------
  186.             ' *** Purpose:        Reads a reg key and runs the script it points to
  187.             ' *** ------------------------------------------------------------------------------
  188.             ' *** 
  189.             Sub ReadRegRun(sRegKey)
  190.                 Dim sScript
  191.                 ' ~~~ Read script to run from registry... 
  192.                 sScript = oShell.RegRead(sRegKey)                
  193.                 
  194.                 ' ~~~ If regvalue is blank exit
  195.                 If sScript="" Then Exit Sub
  196.                 ' ~~~ If it is a script, run it with cscript
  197.                 If (UCase(Right(sScript,3)) = "VBS") or (UCase(Right(sScript,3)) = "WSF") Then
  198.                     sScript = "cscript """ & sScript & """"
  199.                 Else
  200.                     sScript = """" & sScript & """"
  201.                 End If
  202.                 ' ~~~ Run script
  203.                 Call oShell.Run(sScript, 0, True)
  204.             End Sub
  205.             ' *** 
  206.             ' *** ------------------------------------------------------------------------------
  207.             ' *** Name:        PreventLogin
  208.             ' *** ------------------------------------------------------------------------------
  209.             ' *** Purpose:        Disables interactive logins during Critical Updates
  210.             ' *** ------------------------------------------------------------------------------
  211.             ' *** 
  212.             Sub PreventLogin
  213.             ' ~~~ Turn on error handling
  214.             On Error Resume Next
  215.             sInstaller = RegRead(TOOLKITKEY & "SCTInstaller")
  216.             
  217.             Set colItems = oWMIService.ExecQuery _
  218.                 ("Select * from Win32_UserAccount Where LocalAccount = True")
  219.  
  220.             For Each oItem in colItems 
  221.             If oItem.SIDType = 1 and Not(Right(oItem.SID,4) ="-500") and Not(oItem.Name = sInstaller) and oItem.Status = "OK" then
  222.                 Set oUser = GetObject("WinNT://./" & oItem.Name)
  223.                 oUser.Description = "SCTDisabled"
  224.                 oUser.AccountDisabled = True
  225.                 oUser.setinfo
  226.             End If
  227.             Next
  228.             ' ~~~ Destroy objects
  229.             Set colItems = Nothing
  230.             set oUser = Nothing
  231.             End Sub
  232.             ' *** 
  233.             ' *** ------------------------------------------------------------------------------
  234.             ' *** Name:        AllowLogin
  235.             ' *** ------------------------------------------------------------------------------
  236.             ' *** Purpose:        Allows interactive logins after Critical Updates
  237.             ' *** ------------------------------------------------------------------------------
  238.             ' *** 
  239.             Sub AllowLogin
  240.             ' ~~~ Turn on error handling
  241.             On Error Resume Next
  242.             
  243.             Set colItems = oWMIService.ExecQuery _
  244.                 ("Select * from Win32_UserAccount Where LocalAccount = True")
  245.  
  246.             For Each oItem in colItems 
  247.             If oItem.Description = "SCTDisabled" then
  248.                 Set oUser = GetObject("WinNT://./" & oItem.Name)
  249.                 oUser.Description = ""
  250.                 oUser.AccountDisabled = False
  251.                 oUser.setinfo
  252.             End If
  253.             Next
  254.             ' ~~~ Destroy objects
  255.             Set colItems = Nothing
  256.             Set oUser = Nothing
  257.             End Sub
  258.         ]]>
  259.         </script>
  260.     </job>
  261. </package>