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

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' *** 
  5.         ' *** ------------------------------------------------------------------------------
  6.         ' *** Filename:        SleepWakePC.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Assists with creating scheduled tasks that "Sleep" and "Wakeup"
  9.         ' ***                 a computer running Windows Disk Protection so that Critical Updates
  10.         ' ***                 can be applied.
  11.         ' *** ------------------------------------------------------------------------------
  12.         ' *** Version:        1.0
  13.         ' *** Notes:        
  14.         ' *** ------------------------------------------------------------------------------
  15.         ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  16.         ' *** ------------------------------------------------------------------------------
  17.         ' *** 
  18.     </comment>
  19.     <job>
  20.         <runtime>
  21.             <description>Sleep and/or Wake Up Computer</description>
  22.             <named name="Wake"    required="false"  many="false"  helpstring="Helps create a scheduled task that turns on a computer that is in Stand by mode." />
  23.             <named name="Sleep"    required="false"  many="false"  helpstring="Creates a scheduled task that puts a computer in stand by mode. Specify time in HH:MM (24-hour format)." />
  24.             <named name="User"    required="false"  many="false"  helpstring="Specifies the user account used by the scheduled task." />
  25.             <named name="Password"    required="false"  many="false"  helpstring="Specifies the password for the user account used by the scheduled task." />
  26.             <named name="Delete"    required="false"  many="false"  helpstring="Deletes scheduled tasks created using this tool." />
  27.             <!-- <example>Example: SleepWakePC.wsf /Wake /User:username /Password:password /Sleep:18:30</example>-->
  28.             <usage>
  29. SleepWakePC Tool
  30. Usage: SleepWakePC.wsf [/Wake] [/Sleep:hh:mm] [/User:username] [/Password:password] [/Delete]
  31. Options :
  32. Wake    : Helps create a scheduled task that turns on a computer that is in Stand by mode.
  33. Sleep    : Creates a scheduled task that puts a computer in stand by mode. Specify time in HH:MM (24-hour format).
  34. User     : Specifies the user account used by the scheduled task.
  35. Password: Specifies the password for the user account used by the scheduled task.
  36. Delete    : Deletes scheduled tasks created using this tool.
  37. Example : SleepWakePC.wsf /Wake /User:username /Password:password /Sleep:18:30
  38. </usage>        
  39.         </runtime>
  40.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  41.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  42.         <?job error="True" debug="False" ?>
  43.         <script language="VBScript" src="../include/Common.vbs"></script>
  44.         <script language="VBScript" src="../include/libWSF.vbs"></script>
  45.         <script language="VBScript" src="../include/clsDiskProtect.vbs"></script>
  46.         <script language="VBScript" src="../include/clsLogging.vbs"></script>
  47.         <script language="VBScript">
  48.         <![CDATA[
  49.             ' ~~~ 
  50.             ' ~~~ Force variables to be declared 
  51.             ' ~~~ 
  52.             Option Explicit
  53.             ' ~~~ Turn on error handling
  54.             On Error Resume Next
  55.             ' ~~~ 
  56.             ' ~~~ Declare variables and constants
  57.             ' ~~~ 
  58.             Dim oDiskProtect, iWDPcmdVer
  59.             Dim oScheduledJobs, oJob, sUsername, sPassword
  60.             Dim sAppDir, sTime, sDay, sCmd, sCmdWDP, bOK, bWDP
  61.             Dim sSleepTime
  62.         
  63.             ' ~~~ Call the Main sub
  64.             Call Main("")
  65.             
  66.             ' ~~~ Set the WDP.CMD tool version number for IsWDPOn.hta
  67.             iWDPcmdVer = 7
  68.             ' ~~~ Initialize and create objects
  69.             Set oDiskProtect = New DiskProtect
  70.             
  71.             sAppDir = RegRead(TOOLKITKEY & "TargetDir")
  72.             sDay    = oDiskProtect.CriticalUpdateDay
  73.             If (oDiskProtect.CriticalUpdateTime - 1) >= 10 then
  74.                 sTime    = oDiskProtect.CriticalUpdateTime - 1 & ":50:00"
  75.             Else
  76.                 sTime    = "0" & (oDiskProtect.CriticalUpdateTime - 1) & ":50:00"
  77.             End If
  78.             ' ~~~ ------------------------------------------------------------------------------
  79.             ' ~~~ Check script usage
  80.             ' ~~~ ------------------------------------------------------------------------------
  81.             ' ~~~ Assume usage is ok
  82.             bOK = True        
  83.             ' ~~~ Simple checks for incorrect usage
  84.             Select Case WScript.Arguments.Named.Count
  85.                 Case 0
  86.                     ' ~~~ Can not call with no parameters
  87.                     bOK = False
  88.             End Select
  89.             If Not(WScript.Arguments.Named.Exists("Wake")) and Not(WScript.Arguments.Named.Exists("Sleep")) and Not(WScript.Arguments.Named.Exists("Standby")) and Not(WScript.Arguments.Named.Exists("Delete")) and Not(WScript.Arguments.Named.Exists("DoNothing")) Then
  90.                 bOK = False
  91.             End If
  92.             ' ~~~ If incorrect usage display message and quit
  93.             If Not(bOK) Then
  94.                  WScript.Arguments.ShowUsage
  95.                  WScript.Quit
  96.             End If
  97.     
  98.             ' ~~~ ------------------------------------------------------------------------------
  99.             ' ~~~ Check for WDP Tasks
  100.             ' ~~~ ------------------------------------------------------------------------------
  101.     
  102.             sCmdWDP = "wscript """ & sAppDir & "scripts\CriticalUpdates.wsf" & Chr(34) & " /Update /PreventLogin /Restart"                
  103.             bWDP = False
  104.             ' ~~~ Use wmi to check for WDP tasks
  105.             Set oScheduledJobs = oWMIService.ExecQuery("Select * from Win32_ScheduledJob")
  106.             For Each oJob in oScheduledJobs
  107.                 If oJob.Command = sCmdWDP Then
  108.                     bWDP = True
  109.                 End If
  110.             Next
  111.             If Not(bWDP) and WScript.Arguments.Named.Exists("Wake") then
  112.                 WScript.echo("Windows Disk Protection is not running Critical Updates")
  113.                 WScript.echo("The 'Wake' switch requires Windows Disk Protection to be configured")
  114.                 WScript.echo(" ")
  115.             End If    
  116.             ' ~~~ ------------------------------------------------------------------------------
  117.             ' ~~~ Run the Tool
  118.             ' ~~~ ------------------------------------------------------------------------------
  119.             If WScript.Arguments.Named.Exists("DoNothing") Then
  120.                 Wscript.Quit
  121.             End If
  122.             If WScript.Arguments.Named.Exists("StandBy") Then
  123.                 Call oShell.Run(chr(34) & sAppdir & "bin\XPePM.exe" & chr(34) & " -standby", 0, True)
  124.             End If
  125.             
  126.             sUsername = ""
  127.             sPassword = " "
  128.             If WScript.Arguments.Named.Exists("User") Then
  129.                 sUserName = WScript.Arguments.Named("User")
  130.             End If
  131.             If WScript.Arguments.Named.Exists("Password") Then
  132.                 sPassword = WScript.Arguments.Named("Password")
  133.                 If IsNull(sPassword) then sPassword = " "
  134.             End If
  135.             If WScript.Arguments.Named.Exists("Wake") and bWDP Then
  136.                 If sUsername = "" Then
  137.                     Wscript.Echo "Error: Username and Password required."
  138.                     Wscript.Arguments.ShowUsage
  139.                     WScript.Quit
  140.                 End If
  141.                 Call CreateWakeUpTask
  142.             End If
  143.             If WScript.Arguments.Named.Exists("Sleep") Then
  144.                 sSleepTime = ""
  145.                 sSleepTime = Wscript.Arguments.Named("Sleep")
  146.                 If sSleepTime = "" Then
  147.                     Wscript.Echo "Error: SleepWakePC.wsf /Sleep - requires time of day"
  148.                     Wscript.Arguments.ShowUsage
  149.                     WScript.Quit
  150.                 End If
  151.                 If Len(sSleepTime) = 5 and IsNumeric(Left(sSleeptime,2)) and Left(sSleeptime,2) < "24" and Mid(sSleepTime,3,1) = ":" and IsNumeric(Mid(sSleeptime,4,2)) and Mid(sSleeptime,4,2) < "60" Then
  152.                     sSleepTime = sSleepTime & ":00"
  153.                     Call CreateSleepTask
  154.                 ElseIf Len(sSleepTime) = 4 and IsNumeric(Left(sSleeptime,1)) and Left(sSleeptime,1) < "24" and Mid(sSleepTime,2,1) = ":" and IsNumeric(Mid(sSleeptime,3,2)) and Mid(sSleeptime,3,2) < "60" Then
  155.                     sSleepTime = "0" & sSleepTime & ":00"
  156.                     Call CreateSleepTask
  157.                 Else
  158.                     Wscript.Echo "Error: Invalid time specified."
  159.                     Wscript.Arguments.ShowUsage
  160.                     WScript.Quit
  161.                 End If
  162.             End If
  163.             If WScript.Arguments.Named.Exists("Delete") Then
  164.                 Call DeleteWakeUpTask
  165.             End If
  166.             ' ~~~ Destroy objects
  167.             Call UnloadObjects()
  168.             Set oDiskProtect = Nothing
  169.             ' *** 
  170.             ' *** ------------------------------------------------------------------------------
  171.             ' *** Name:            CreateWakeUpTask
  172.             ' *** ------------------------------------------------------------------------------
  173.             ' *** Purpose:        Creates a Scheduled task based on the WDP Critical Updates
  174.             ' ***                 schedule that wakes up the PC in time for updates to occur.
  175.             ' *** ------------------------------------------------------------------------------
  176.             ' *** 
  177.             Sub CreateWakeUpTask
  178.             Dim sInterval
  179.             Select Case sDay
  180.                 Case 1
  181.                     sInterval = "/SC WEEKLY /D SUN"
  182.                 Case 2
  183.                     sInterval = "/SC WEEKLY /D MON"
  184.                 Case 3
  185.                     sInterval = "/SC WEEKLY /D TUE"
  186.                 Case 4
  187.                     sInterval = "/SC WEEKLY /D WED"
  188.                 Case 5
  189.                     sInterval = "/SC WEEKLY /D THU"
  190.                 Case 6
  191.                     sInterval = "/SC WEEKLY /D FRI"
  192.                 Case 7
  193.                     sInterval = "/SC WEEKLY /D SAT"
  194.                 Case Else
  195.                     sInterval = "/SC DAILY"
  196.             End Select
  197.                 ' ~~~ The Scheduled Task created really does nothing... AccessibilityTool.exe without switches does nothing
  198.                 ' ~~~ just a dummy task to wake up the computer
  199.                 If sPassword = " " or IsNull(sPassword) Then
  200.                     sCmd = chr(34) & sAppDir & "bin\schtasks.exe" & chr(34) & " /Create /RU " & sUsername & " /RP " & chr(34) & " " & chr(34) & " " & sInterval & " /TN SCTWakeUpPC /TR " & chr(34) & oShell.ExpandEnvironmentStrings("%SCTPath%") & "bin\AccessibilityTool.EXE" & chr(34) & " /ST " & stime
  201.                 Else 
  202.                     sCmd = chr(34) & sAppDir & "bin\schtasks.exe" & chr(34) & " /Create /RU " & sUsername & " /RP " & sPassword & " " & sInterval & " /TN SCTWakeUpPC /TR " & chr(34) & oShell.ExpandEnvironmentStrings("%SCTPath%") & "bin\AccessibilityTool.EXE" & chr(34) & " /ST " & stime
  203.                 End If
  204.                 CALL oShell.Run(sCmd, 0, True)
  205.                     msgbox ("You need to modify the new SCTWakeUpPC Scheduled Task so that it wakes up your computer.")
  206.                     msgbox ("When the Scheduled Tasks window opens, double-click the SCTWakeUpPC task, click the Settings tab, and click the " & chr(34) & "Wake the computer to run this task" & chr(34) & " checkbox.")
  207.                     Call oShell.Run("explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}", 1, True)
  208.                     Call RegWrite(TOOLKITKEY & "SCTWakePC", "Yes", "REG_SZ")
  209.                 If oDiskProtect.Enabled then
  210.                     ' ~~~ Commit windows disk protection unless in retain changes mode
  211.                     If oDiskProtect.BootCommand <> "NO_CMD" Then
  212.                         msgbox ("After modifying the Scheduled Task you will need to restart your computer.")
  213.                         Call oDiskProtect.Commit
  214.                     End If
  215.                 End If
  216.             End Sub
  217.             ' *** 
  218.             ' *** ------------------------------------------------------------------------------
  219.             ' *** Name:            CreateSleepTask
  220.             ' *** ------------------------------------------------------------------------------
  221.             ' *** Purpose:        Creates a Scheduled task that puts a computer to sleep at the specified time
  222.             ' *** ------------------------------------------------------------------------------
  223.             ' *** 
  224.             Sub CreateSleepTask
  225.             Dim bInteractive
  226.                 sCmd = "wscript " & chr(34) & sAppDir & "scripts\SleepWakePC.wsf" & chr(34) & " /Standby"
  227.                 Call oDiskProtect.DeletescheduleTask(sCmd)
  228.                 sTime =  Replace(sSleepTime,":","")
  229.                 sDay = "1248163264"
  230.                 bInteractive = False
  231.                 Call oDiskProtect.CreateScheduleTask(sCmd, sTime, sDay, bInteractive)
  232.                 Wscript.Echo
  233.                 Wscript.Echo "This computer will go into stand by every day at " & sSleepTime
  234.                 Wscript.Echo
  235.             End Sub
  236.             ' *** 
  237.             ' *** ------------------------------------------------------------------------------
  238.             ' *** Name:            DeleteWakeUpTask
  239.             ' *** ------------------------------------------------------------------------------
  240.             ' *** Purpose:        Deletes scheduled tasks created by this tool
  241.             ' *** ------------------------------------------------------------------------------
  242.             ' *** 
  243.             Sub DeleteWakeUpTask
  244.                 Call oShell.Run(chr(34) & sAppDir & "bin\schtasks.exe" & chr(34) & " /Delete /TN SCTWakeUpPC /F", 0, True)
  245.                 Call RegWrite(TOOLKITKEY & "SCTWakePC", "No", "REG_SZ")
  246.                 sCmd = "wscript " & chr(34) & sAppDir & "scripts\SleepWakePC.wsf" & chr(34) & " /Standby"
  247.                 Call oDiskProtect.DeletescheduleTask(sCmd)
  248.                 Wscript.Echo
  249.                 Wscript.Echo "All tasks created by this tool have been deleted..."
  250.                 Wscript.Echo
  251.             End Sub
  252.         ]]>
  253.         </script>
  254.     </job>
  255. </package>