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

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' *** 
  5.         ' *** ------------------------------------------------------------------------------
  6.         ' *** Filename:        DiskProtect.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Command line interface to Disk Protection tool
  9.         ' ***             This file parses command line parameters and calls functions
  10.         ' ***             that are defined in clsDiskProtect.vbs
  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>Disk Protection Tool</description>
  22.             <named name="Status"            required="false"  many="false"  helpstring="Displays the status of disk protection" />
  23.             <named name="On"            required="false"  many="false"  helpstring="Enables disk protection" />
  24.             <named name="Off"            required="false"  many="false"  helpstring="Disables disk protection" />
  25.             <named name="Save"            required="false"  many="false"  helpstring="Saves all changes to the protected drive on next restart" />
  26.             <named name="Clear"        required="false"  many="false"  helpstring="All changes are cleared with every restart" />
  27.             <named name="Retain"        required="false"  many="false"  helpstring="All changes are retained on restart" />
  28.             <named name="Once"                required="false"  many="false"  helpstring="Used with the Retain option to keep changes for one restart" />
  29.             <named name="Restart"            required="false"  many="false"  helpstring="Used with any option; forces the computer to restart" />
  30.             <named name="MU"                required="false"  many="false"  helpstring="Install Microsoft Updates during critical update process" />
  31.             <named name="NoMU"                required="false"  many="false"  helpstring="Disable Microsoft Updates during critical update process" />
  32.             <named name="AV"                required="false"  many="false"  helpstring="Specifies a script that allows antivirus updates" />
  33.             <named name="Other"                required="false"  many="false"  helpstring="Specifies a script that allows other customized updates" />
  34.             <named name="Time"                required="false"  many="false"  helpstring="Critical update process time (specify hour between 0 and 23)" />
  35.             <named name="Day"                required="false"  many="false"  helpstring="The days of the week to run the critical update process" />
  36.             
  37.             <example>Example: DiskProtect.wsf /On /MU /AV:"full path to script file" /Time:22</example>
  38.         </runtime>
  39.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  40.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  41.         
  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.             ' ~~~ 
  54.             ' ~~~ Declare variables and constants
  55.             ' ~~~ 
  56.             Dim bOK, bResult, bReboot, oDiskProtect, oLog, iWDPcmdVer
  57.             Dim oOS, colOperatingSystems, iInstallTime, iOverlayTime, iLastBootUpTime, sComputer
  58.             Dim sUpperFilter,iLocalDateTime
  59.             Dim bBlackList, bWhiteList
  60.             Dim arrTempArray, i, arrUpperFilters()
  61.             Call Main("DiskProtect.hta")
  62.             ' ~~~ Create the disk protection object
  63.             Set oDiskProtect = New DiskProtect
  64.             ' ~~~ ------------------------------------------------------------------------------
  65.             ' ~~~ Logging
  66.             ' ~~~ ------------------------------------------------------------------------------
  67.             ' ~~~ Create logging object
  68.             Set oLog = New Logging
  69.             ' ~~~ Initiate logging
  70.             Call oLog.Open(GetRootFolder & "\log\diskprotect.wsf.log")
  71.             Call oLog.Write("DiskProtection.wsf : Started")
  72.             
  73.             ' ~~~ ------------------------------------------------------------------------------
  74.             ' ~~~ Check reboot key before trying to run tool
  75.             ' ~~~ ------------------------------------------------------------------------------
  76.             Set colOperatingSystems = oWMIService.ExecQuery _
  77.                 ("Select * from Win32_OperatingSystem")
  78.             For Each oOS in colOperatingSystems
  79.                 iLastBootUpTime = oOS.LastBootUpTime
  80.                 iLocalDateTime = oOS.LocalDateTime
  81.             Next
  82.             iInstallTime = RegRead(TOOLKITKEY & "SCTInstallTime")
  83.             iOverlayTime = RegRead(TOOLKITKEY & "SCTOverlayTime")
  84.             On Error Goto 0
  85.             ' ~~~ Check UpperFilter registry key to ensure no other Disk Protection Software is installed
  86.             ' ~~~ Read and record UpperFilters key in SCT registry
  87.             oDiskProtect.GetStashUpperFilterKey()
  88.             On Error Resume Next
  89.             ' ~~~ Check only if Ewf not in UpperFilter
  90.             If (InStr(UCase(sUpperFilter),","&"EWF"&",") < 1) or IsNull(sUpperFilter) Then
  91.                 ' ~~~ Set to Ewf if NUll
  92.                 If IsNull(sUpperFilter) Then
  93.                     ReDim Preserve arrUpperFilters(0)
  94.                     arrUpperFilters(0) = "Ewf"
  95.                     ' ~~~ Writes to UpperFilters key
  96.                     oDiskProtect.WriteUpperFilterKey()
  97.                     ' ~~~ Read and record UpperFilters key in SCT registry
  98.                     oDiskProtect.GetStashUpperFilterKey()
  99.                     Call oLog.Write("DiskProtection.wsf : UpperFilter set to Ewf")
  100.                     WScript.Echo
  101.                     WScript.Echo "You must restart this computer before you can run Windows Disk Protection."
  102.                     QuitScript()
  103.                 Else
  104.                     ' ~~~ Black List Check
  105.                     Call oDiskProtect.UpperFilterCheck("BlackList")
  106.                     If bBlackList Then
  107.                         ' ~~~ Warn of Blacklist hit... Exit!
  108.                         Call oLog.Write("DiskProtection.wsf : BlackList hit... Other Disk Protection Software installed. Quit")
  109.                         WScript.Echo
  110.                         WScript.Echo "You must uninstall any other disk protection software before configuring"
  111.                         WScript.Echo "Windows Disk Protection. Windows Disk Protection will not work if you have"
  112.                         WScript.Echo "other disk protection software installed on the same computer."
  113.                         QuitScript()
  114.                     Else
  115.                         ' ~~~ White List Check
  116.                         Call oDiskProtect.UpperFilterCheck("WhiteList")
  117.                         If bWhiteList Then
  118.                             ' ~~~ Proceed with setting UpperFilters
  119.                             arrTempArray = Split(sUpperFilter, ",")
  120.                             For i = LBound(arrTempArray) to UBound(arrTempArray)
  121.                                 ReDim Preserve arrUpperFilters(i)  
  122.                                 arrUpperFilters(i) = arrTempArray(i+1)
  123.                             Next
  124.                             ReDim Preserve arrUpperFilters(i-2)
  125.                             arrUpperFilters(i-2) = "Ewf"
  126.                             ' ~~~ Writes to UpperFilters key
  127.                             oDiskProtect.WriteUpperFilterKey()
  128.         
  129.                             ' ~~~ Read and record UpperFilters key in SCT registry
  130.                             oDiskProtect.GetStashUpperFilterKey()
  131.                             ' ~~~ Registry modified... prompt for Restart
  132.                             Call oLog.Write("DiskProtection.wsf : UpperFilter set to WhiteList + Ewf")
  133.                             WScript.Echo
  134.                             WScript.Echo "You must restart this computer before you can run Windows Disk Protection."
  135.                             QuitScript()
  136.                         Else
  137.                             ' ~~~ Proceed with setting Gray UpperFilters
  138.                             arrTempArray = Split(sUpperFilter, ",")
  139.                             For i = LBound(arrTempArray) to UBound(arrTempArray)
  140.                                  ReDim Preserve arrUpperFilters(i)  
  141.                                 arrUpperFilters(i) = arrTempArray(i+1)
  142.                             Next
  143.                             ReDim Preserve arrUpperFilters(i-2)
  144.                             arrUpperFilters(i-2) = "Ewf"
  145.         
  146.                             ' ~~~ Writes to UpperFilters key
  147.                             oDiskProtect.WriteUpperFilterKey()
  148.                             ' ~~~ Read and record UpperFilters key in SCT registry
  149.                             oDiskProtect.GetStashUpperFilterKey()
  150.                             ' ~~~ Registry modified... prompt for Restart
  151.                             Call oLog.Write("DiskProtection.wsf : UpperFilter set to GrayList + Ewf")
  152.                             WScript.Echo
  153.                             WScript.Echo "This computer has multiple UpperFilters configured. Windows Disk Protection"
  154.                             WScript.Echo "might not be compatible with all UpperFilters. Please contact Product Support"
  155.                             WScript.Echo "if Windows Disk Protection causes your computer to malfunction."
  156.                             WScript.Echo
  157.                             WScript.Echo "You must restart this computer before you can run Windows Disk Protection."
  158.                             QuitScript()
  159.                         End If
  160.                     End If
  161.         
  162.                 End If
  163.             On Error Goto 0
  164.             End If    
  165.             If iInstallTime > iLastBootUpTime Then
  166.                 Call oLog.Write("DiskProtection.wsf : Computer has not been restarted since install. Quit")
  167.                 WScript.Echo
  168.                 WScript.Echo "You must restart this computer before you can run Windows Disk Protection."
  169.                 QuitScript()
  170.             End If
  171.             If iOverlayTime > iLastBootUpTime Then
  172.                 Call oLog.Write("DiskProtection.wsf : Computer has not been restarted since install. Quit")
  173.                 WScript.Echo
  174.                 WScript.Echo "Windows Disk Protection has been turned On. The computer must be restarted before you can run Windows Disk Protection."
  175.                 QuitScript()
  176.             End If
  177.             ' ~~~ ------------------------------------------------------------------------------
  178.             ' ~~~ Check script usage
  179.             ' ~~~ ------------------------------------------------------------------------------
  180.             ' ~~~ Assume usage is ok
  181.             bOK = True        
  182.             ' ~~~ Simple checks for incorrect usage
  183.             Select Case WScript.Arguments.Named.Count
  184.                 Case 0
  185.                     ' ~~~ Can not call with no parameters
  186.                     bOK = False
  187.                 Case 1
  188.                     ' ~~~ Once can not be used on its own
  189.                     If WScript.Arguments.Named.Exists("Once") Then bOk = False
  190.             End Select    
  191.             
  192.             ' ~~~ Call the Validations sub to validate the inputs
  193.             Call Validations()
  194.             
  195.             ' ~~~ If incorrect usage display message and quit
  196.             If Not(bOK) Then
  197.                 Call oLog.Write("DiskProtection.wsf : Incorrect usage detected")
  198.                  WScript.Arguments.ShowUsage
  199.                  QuitScript()
  200.             End If
  201.             ' ~~~ ------------------------------------------------------------------------------
  202.             ' ~~~ Now do disk protection
  203.             ' ~~~ ------------------------------------------------------------------------------
  204.             ' ~~~ Default to no reboot required
  205.             bReboot = False
  206.             bOK = False
  207.             ' ~~~ Set the WDP.cmd version # for the DiskProtect class            
  208.             iWDPcmdVer = 2
  209.             ' ~~~ Bind to the logging object
  210.             oDiskProtect.Logging = oLog
  211.             If Not(oDiskProtect.OverlayCreated) and oDiskProtect.CalcOVSize = 0 and oDiskProtect.ForceOverlaySize = 0 Then
  212.                 WScript.Echo "This computer does not currently support Windows Disk Protection.To resolve this problem refer to Tool kit's documentation." 
  213.                 Set oDiskProtect = Nothing
  214.                 QuitScript()
  215.             End If
  216.             ' ~~~ Perform disk protection enable action
  217.             If WScript.Arguments.Named.Exists("On") Then
  218.                 bOK = True
  219.                 If NOT (WScript.Arguments.Named.Exists("Off")) Then
  220.                     Call oLog.Write("DiskProtection.wsf : Enable")
  221.                     If oDiskProtect.GetHibernation() = True Then
  222.                         WScript.Echo "Hibernation is currently Enabled. Hibernation will not work when Windows Disk Protection is turned On."
  223.                     End If
  224.                     Call oDiskProtect.Enable
  225.                     WScript.Echo "Disk Protection has been turned On."
  226.                     bReboot = True
  227.                 Else
  228.                     WScript.Echo "Please enter On or Off. Both options cannot be used at the same time."
  229.                     WScript.Arguments.ShowUsage
  230.                      QuitScript()
  231.                 End If
  232.             End If
  233.             ' ~~~ Perform disk protection disable action
  234.             If WScript.Arguments.Named.Exists("Off") Then
  235.                 bOK = True
  236.                 If NOT (WScript.Arguments.Named.Exists("On")) Then
  237.                     Call oLog.Write("DiskProtection.wsf : Disable")
  238.                     Call oDiskProtect.Disable
  239.                     WScript.Echo "Disk Protection has been turned Off."
  240.                     bReboot = True
  241.                 End If
  242.             End If
  243.             ' ~~~ Perform disk protection status action
  244.             If WScript.Arguments.Named.Exists("Status") Then
  245.                 Call oLog.Write("DiskProtection.wsf : Status")
  246.                 If oDiskProtect.Enabled Then
  247.                     WScript.Echo "Windows Disk Protection is On"
  248.                 Else
  249.                     WScript.Echo "Windows Disk Protection is Off"
  250.                 End If
  251.                 bOK = True
  252.             End If
  253.             ' ~~~ Perform disk protection undo changes action
  254.             If WScript.Arguments.Named.Exists("Clear") Then
  255.                 bOK = True
  256.                 If oDiskProtect.Enabled = True Then
  257.                     Call oLog.Write("DiskProtection.wsf : UndoChanges")
  258.                     Call oDiskProtect.UndoChanges
  259.                     WScript.Echo "Windows Disk Protection is On. All changes will be cleared with every restart"
  260.                 Else
  261.                     WScript.Echo "Restart the computer to clear changes."                    
  262.                 End If
  263.             End If
  264.             ' ~~~ Perform disk protection retain changes action
  265.             If WScript.Arguments.Named.Exists("Retain") Then
  266.                 bOK = True
  267.                 If oDiskProtect.Enabled = True Then
  268.                     Call oLog.Write("DiskProtection.wsf : RetainChanges")
  269.                     Call oDiskProtect.RetainChanges(WScript.Arguments.Named.Exists("Once"))
  270.                     If WScript.Arguments.Named.Exists("Once") Then
  271.                         WScript.Echo "Windows Disk Protection is On. Changes will be retained for one restart."                
  272.                     Else
  273.                         WScript.Echo "Windows Disk Protection is On. Changes will be retained after computer restarts."
  274.                     End If                    
  275.                 End If
  276.             End If
  277.             ' ~~~ Set the scheduled update task time
  278.             If WScript.Arguments.Named("Time") <> "" and IsNumeric(WScript.Arguments.Named("Time")) and WScript.Arguments.Named("Time") < "24" Then
  279.                 oDiskProtect.CriticalUpdateTime = WScript.Arguments.Named("Time")
  280.                 WScript.Echo "Windows Disk Protection critical update time set."
  281.                 bOK = True
  282.             End If
  283.             ' ~~~ Set the scheduled update task day of week
  284.             If WScript.Arguments.Named("Day") <> "" Then
  285.                 oDiskProtect.CriticalUpdateDay = WScript.Arguments.Named("Day")
  286.                 WScript.Echo "Windows Disk Protection critical update frequency set."
  287.                 bOK = True
  288.             End If
  289.             ' ~~~ Set the anti-virus script name
  290.             If WScript.Arguments.Named("AV") <> "" Then
  291.                 oDiskProtect.AVUpdateScript = WScript.Arguments.Named("AV")
  292.                 WScript.Echo "Windows Disk Protection anti-virus script name set."
  293.                 bOK = True
  294.             End If
  295.             ' ~~~ Turn on Microsoft Updates
  296.             If WScript.Arguments.Named.Exists("MU") Then
  297.                 oDiskProtect.WindowsUpdateScript = True
  298.                 WScript.Echo "Windows Disk Protection Microsoft Updates processing has been turned On."
  299.                 bOK = True
  300.             End If
  301.             ' ~~~ Turn off Microsoft Updates
  302.             If WScript.Arguments.Named.Exists("NOMU") Then
  303.                 oDiskProtect.WindowsUpdateScript = False
  304.                 WScript.Echo "Windows Disk Protection Microsoft Updates processing has been turned Off."
  305.                 bOK = True
  306.             End If
  307.             ' ~~~ Set the other script name
  308.             If WScript.Arguments.Named("Other") <> "" Then
  309.                 oDiskProtect.OtherUpdateScript = WScript.Arguments.Named("Other")
  310.                 WScript.Echo "Windows Disk Protection other script name set."
  311.                 bOK = True
  312.             End If
  313.             If WScript.Arguments.Named.Exists("On") Then Call oDiskProtect.EnableCriticalUpdates()
  314.             If WScript.Arguments.Named.Exists("Off") Then Call oDiskProtect.DisableCriticalUpdates()
  315.             ' ~~~ Perform disk protection commit action
  316.             If WScript.Arguments.Named.Exists("Save") Then
  317.                 bOK = True
  318.                 If oDiskProtect.Enabled = True Then
  319.                     Call oDiskProtect.EnableCriticalUpdates()
  320.                     Call oLog.Write("DiskProtection.wsf : Commit")
  321.                     Call oDiskProtect.Commit
  322.                     WScript.Echo "Windows Disk Protection is On. Changes will be saved on the next restart."
  323.                     bReboot = True
  324.                 Else
  325.                     WScript.Echo "Windows Disk Protection is Off. Save requires Windows Disk Protection to be On."                    
  326.                 End If
  327.             End If
  328.             ' ~~~ Force reboot if requested
  329.             If WScript.Arguments.Named.Exists("Restart") Then
  330.                 Call oLog.Write("DiskProtection.wsf : Restart")
  331.                 Call oDiskProtect.Reboot
  332.                 bOK = True
  333.             Else
  334.                 If bReboot Then WScript.Echo "Restart the computer for changes to take effect"
  335.             End If
  336.             If Not(bOK) Then
  337.                 Call oLog.Write("DiskProtection.wsf : Incorrect usage detected")
  338.                 WScript.Echo "Incorrect usage. See Disk Protection Tool options below."
  339.                 WScript.Echo
  340.                  WScript.Arguments.ShowUsage
  341.                  QuitScript()
  342.             End If
  343.             ' ***
  344.             ' *** --------------------------------------------------------------------------------
  345.             ' *** Name:         Validations()
  346.             ' *** --------------------------------------------------------------------------------
  347.             ' *** Purpose:        Validate the inputs 
  348.             ' *** --------------------------------------------------------------------------------
  349.             ' ***
  350.             Sub Validations()
  351.                 If WScript.Arguments.Named("AV") <> "" Then
  352.                     If NOT oFso.FileExists ( WScript.Arguments.Named("AV") ) Then
  353.                         WScript.Echo "The specified anti-virus script does not exist."
  354.                         WScript.Echo "Enter a valid anti-virus script."
  355.                         QuitScript()
  356.                     End If
  357.                 End If
  358.                 If WScript.Arguments.Named("Other") <> "" Then
  359.                     If NOT oFso.FileExists ( WScript.Arguments.Named("Other") ) Then
  360.                         WScript.Echo "The specified script does not exist."
  361.                         WScript.Echo "Enter a valid script."
  362.                         QuitScript()
  363.                     End If
  364.                 End If
  365.             End Sub
  366.             
  367.             
  368.             
  369.             ' ~~~ ------------------------------------------------------------------------------
  370.             ' ~~~ Tidy up
  371.             ' ~~~ ------------------------------------------------------------------------------
  372.             ' ~~~ Close log
  373.             Call oLog.Close
  374.             ' ~~~ Destroy objects
  375.             Set oDiskProtect = nothing
  376.             Set oLog = nothing
  377.             UnLoadObjects()
  378.         ]]>
  379.         </script>
  380.     </job>
  381. </package>