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

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        clsDiskProtect.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    Disk Protection Class
  6. ' *** ------------------------------------------------------------------------------
  7. ' *** Version:        1.0
  8. ' *** Notes:        
  9. ' *** ------------------------------------------------------------------------------
  10. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  11. ' *** ------------------------------------------------------------------------------
  12. ' ***
  13.  
  14. ' ~~~ 
  15. ' ~~~ Force variables to be declared and turn off script error messages unless in DEBUG mode
  16. ' ~~~ 
  17. Option Explicit
  18.  
  19.  
  20. Class DiskProtect
  21.     ' ~~~ ------------------------------------------------------------------------------
  22.     ' ~~~ declare variables and constants
  23.     ' ~~~ ------------------------------------------------------------------------------
  24.     Dim oLog, bLogging, sCmd, sCmd1, sCmd2, sCmd3, sTempCmd, sArcName
  25.     Dim iDiskID, iPartID, iOverlayTime, iReturn
  26.     Dim bEnabled, bOverlayCreated
  27.     Dim bSetLevel, bCommit, bNoCMD, bEnable, bDisable
  28.     Dim ColOperatingSystems, oOS, oDisk, oDiskDrives,  oPartition 
  29.     Dim oDiskPartitions, oLogicalDisk, oLogicalDisks, sEscapedDeviceID
  30.  
  31.     ' ~~~ 
  32.     ' ~~~ public properties
  33.     ' ~~~ 
  34.     
  35.     ' ***
  36.     ' *** ------------------------------------------------------------------------------
  37.     ' *** Property:    Logging
  38.     ' *** ------------------------------------------------------------------------------
  39.     ' *** Purpose:    Turns on logging, property must be set to a logging object
  40.     ' *** ------------------------------------------------------------------------------
  41.     ' ***
  42.     Public Property Get Logging
  43.         Logging = bLogging
  44.     End Property 
  45.  
  46.     Public Property Let Logging(oObject)
  47.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  48.         If VarType(oObject) = vbObject Then
  49.             bLogging = True
  50.             Set oLog = oObject
  51.         End If
  52.     End Property
  53.  
  54.  
  55.     ' ***
  56.     ' *** ------------------------------------------------------------------------------
  57.     ' *** Property:    Enabled
  58.     ' *** ------------------------------------------------------------------------------
  59.     ' *** Purpose:    Returns whether disk protection is enabled or not
  60.     ' ***            Property is read only
  61.     ' *** ------------------------------------------------------------------------------
  62.     ' ***
  63.     Public Property Get Enabled
  64.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  65.     
  66.         ' ~~~ default value
  67.         Enabled = False
  68.     
  69.         ' ~~~ If the Overlay has not been created, it can not be enabled
  70.         If Not(OverlayCreated) Then Exit Property
  71.         
  72.         ' ~~~ overlay created proceed, create object
  73.  
  74.         If bEnabled Then Enabled = True
  75.         
  76.     End Property
  77.  
  78.     ' ***
  79.     ' *** ------------------------------------------------------------------------------
  80.     ' *** Property:    BootCommand
  81.     ' *** ------------------------------------------------------------------------------
  82.     ' *** Purpose:    Returns the EWF BootCommand
  83.     ' ***            Property is read only.
  84.     ' *** ------------------------------------------------------------------------------
  85.     ' ***
  86.     Public Property Get BootCommand
  87.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0            
  88.         ' ~~~ default value
  89.         BootCommand = ""
  90.     
  91.         ' ~~~ If the Overlay has not been created, it can not be enabled
  92.         If Not(OverlayCreated) Then Exit Property
  93.         
  94.         ' ~~~ overlay created proceed, create object
  95.  
  96.         If bSetLevel Then
  97.             BootCommand = "SET_LEVEL"
  98.         ElseIf bCommit Then
  99.             BootCommand = "COMMIT"
  100.         ElseIf bNoCMD Then
  101.             BootCommand = "NO_CMD"
  102.         ElseIf bEnable Then
  103.             BootCommand = "ENABLE"
  104.         ElseIf bDisable Then
  105.             BootCommand = "DISABLE"
  106.         End If
  107.  
  108.     End Property
  109.     
  110.     ' ***
  111.     ' *** ------------------------------------------------------------------------------
  112.     ' *** Property:    WindowsUpdateScript
  113.     ' *** ------------------------------------------------------------------------------
  114.     ' *** Purpose:    Location of script file used to install files from WindowsUpdate
  115.     ' *** Note:        This property has different Get and Let conditions. We never
  116.     ' ***            want to change the value the user has set for AUOptions
  117.     ' *** ------------------------------------------------------------------------------
  118.     ' ***
  119.     Public Property Get WindowsUpdateScript
  120.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  121.         If RegRead(TOOLKITKEY & "WindowsUpdateScript") = "" Then
  122.             WindowsUpdateScript = False            
  123.         Else
  124.             WindowsUpdateScript = True
  125.         End If
  126.  
  127.     End Property    
  128.  
  129.     Public Property Let WindowsUpdateScript(bOn)
  130.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  131.         If bOn Then
  132.             Call RegWrite(TOOLKITKEY & "WindowsUpdateScript", GetRootFolder & "\bin\windowsupdates.vbs", "REG_SZ")
  133.             Call RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\AUOptions", 4, "REG_DWORD")
  134.         Else
  135.             Call RegWrite(TOOLKITKEY & "WindowsUpdateScript", "", "REG_SZ")
  136.             Call RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\AUOptions", 1, "REG_DWORD")
  137.         End If
  138.     End Property
  139.     
  140.     ' ***
  141.     ' *** ------------------------------------------------------------------------------
  142.     ' *** Property:    AVUpdateScript
  143.     ' *** ------------------------------------------------------------------------------
  144.     ' *** Purpose:    Location of script file used to update anti-virus signatures
  145.     ' *** ------------------------------------------------------------------------------
  146.     ' ***
  147.     Public Property Get AVUpdateScript
  148.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  149.         AVUpdateScript = RegRead(TOOLKITKEY & "AVUpdateScript")
  150.     End Property    
  151.  
  152.     Public Property Let AVUpdateScript(sScript)
  153.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  154.         Call RegWrite(TOOLKITKEY & "AVUpdateScript", sScript, "REG_SZ")
  155.     End Property
  156.     ' ***
  157.     ' *** ------------------------------------------------------------------------------
  158.     ' *** Property:    OtherUpdateScript
  159.     ' *** ------------------------------------------------------------------------------
  160.     ' *** Purpose:    Location of script file used to install other updates
  161.     ' *** ------------------------------------------------------------------------------
  162.     ' ***
  163.     Public Property Get OtherUpdateScript
  164.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  165.         OtherUpdateScript = RegRead(TOOLKITKEY & "OtherUpdateScript")
  166.     End Property    
  167.  
  168.     Public Property Let OtherUpdateScript(sScript)
  169.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  170.         Call RegWrite(TOOLKITKEY & "OtherUpdateScript", sScript, "REG_SZ")
  171.     End Property
  172.     
  173.     ' ***
  174.     ' *** ------------------------------------------------------------------------------
  175.     ' *** Property:    CriticalUpdateDay
  176.     ' *** ------------------------------------------------------------------------------
  177.     ' *** Purpose:    Day(s) of the week that the critical update process is run
  178.     ' *** ------------------------------------------------------------------------------
  179.     ' ***
  180.     Public Property Get CriticalUpdateDay
  181.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  182.         Dim sDay
  183.         
  184.         ' ~~~ read value from registry, if not exist set as default
  185.         sDay = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ScheduledInstallDay")
  186.         If sDay = "" Then sDay = "0"
  187.         CriticalUpdateDay = sDay
  188.     End Property    
  189.  
  190.  
  191.     Public Property Let CriticalUpdateDay(iDay)
  192.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  193.         Call RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ScheduledInstallDay", iDay, "REG_DWORD")
  194.     End Property
  195.     
  196.     ' ***
  197.     ' *** ------------------------------------------------------------------------------
  198.     ' *** Property:    CriticalUpdateTime
  199.     ' *** ------------------------------------------------------------------------------
  200.     ' *** Purpose:    Time that the critical update process is run
  201.     ' *** ------------------------------------------------------------------------------
  202.     ' ***
  203.     Public Property Get CriticalUpdateTime
  204.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  205.             Dim sTime
  206.  
  207.         ' ~~~ read value from registry, if not exist set as default
  208.             sTime = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ScheduledInstallTime")
  209.         If sTime = "" Then sTime = "3"        
  210.             CriticalUpdateTime = sTime
  211.     End Property    
  212.  
  213.     Public Property Let CriticalUpdateTime(iTime)
  214.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  215.         Call RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ScheduledInstallTime", iTime, "REG_DWORD")
  216.     End Property
  217.  
  218.     ' ***
  219.     ' *** ------------------------------------------------------------------------------
  220.     ' *** Property:    OverlayCreated
  221.     ' *** ------------------------------------------------------------------------------
  222.     ' *** Purpose:    Returns the status of the disk overlay
  223.     ' ***            Property is read only
  224.     ' *** ------------------------------------------------------------------------------
  225.     ' ***
  226.     Public Property Get OverlayCreated
  227.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  228.         If bLogging Then oLog.Write "clsDiskProtect : OverlayCreated : Entry"
  229.  
  230.     OverlayCreated = False
  231.         
  232.         If bOverlayCreated then OverlayCreated = True
  233.  
  234.         If bLogging Then oLog.Write "clsDiskProtect : OverlayCreated : Exit"
  235.     End Property
  236.  
  237.     ' ***
  238.     ' *** ------------------------------------------------------------------------------
  239.     ' *** Property:    OverlaySize
  240.     ' *** ------------------------------------------------------------------------------
  241.     ' *** Purpose:    Determines the size of the overlay to create.
  242.     ' ***            Can only be set before overlay has been created.
  243.     ' *** ------------------------------------------------------------------------------
  244.     ' ***
  245.     Public Property Get OverlaySize
  246.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  247.         OverlaySize = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\EWF\FBA\OVSize")
  248.     End Property    
  249.  
  250.     Public Property Let OverlaySize(iSize)
  251.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  252.     ' ~~~ If Not(IsNumeric(iSize)) then iSize = 0    
  253.     If OverlayCreated Then
  254.             If bLogging Then oLog.Write "clsDiskProtect : OverlaySize() : Can not set overlay size. Overlay already created"
  255.         Else
  256.             If bLogging Then oLog.Write "clsDiskProtect : OverlaySize() : Overlay size set in registry"
  257.             Call RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\EWF\FBA\OVSize", iSize, "REG_DWORD")
  258.         End If
  259.     End Property
  260.  
  261.     ' ***
  262.     ' *** ------------------------------------------------------------------------------
  263.     ' *** Property:    ForceOverlaySize
  264.     ' *** ------------------------------------------------------------------------------
  265.     ' *** Purpose:    Enables advanced scenario for configuring the size and location of the overlay.
  266.     ' ***            Can only be set before overlay has been created.
  267.     ' *** ------------------------------------------------------------------------------
  268.     ' ***
  269.     Public Property Get ForceOverlaySize
  270.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  271.         ForceOverlaySize = RegRead(TOOLKITKEY & "SCTForceOverlay")
  272.         If ForceOverlaySize = "" or ForceOverlaySize < 0 Then ForceOverlaySize = 0
  273.     End Property    
  274.  
  275.     ' ~~~ 
  276.     ' ~~~ public methods
  277.     ' ~~~ 
  278.  
  279.     ' ***
  280.     ' *** ------------------------------------------------------------------------------
  281.     ' *** Name:        WDPState
  282.     ' *** ------------------------------------------------------------------------------
  283.     ' *** Purpose:    Gets WDP State... minimizes oFso.GetFile calls
  284.     ' *** ------------------------------------------------------------------------------
  285.     ' ***
  286.     Public Sub WDPState
  287.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  288.  
  289.         Dim iTryAgain
  290.         Dim sAppDir
  291.     
  292.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  293.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  294.  
  295.         bEnabled = False
  296.         bOverlayCreated = False
  297.         bSetLevel = False
  298.         bCommit = False
  299.         bNoCMD = False
  300.         bEnable = False
  301.         bDisable = False
  302.  
  303.         ' ~~~
  304.         ' ~~~ If the calling routine has not set a tool version number for the check, set it to zero.
  305.         ' ~~~ This version # is used to handle concurrency issues with multiple tools using this class at the same time.
  306.         ' ~~~
  307.         If IsEmpty(iWDPcmdVer) or IsNull(iWDPcmdVer) or NOT IsNumeric(iWDPcmdVer) Then iWDPcmdVer = 0
  308.  
  309.         ' ~~~ Need to capture potential errors from the Run line below, and ignore oFso errors from concurrent wdp.cmd runs
  310.         On Error Resume Next
  311.  
  312.         ' ~~~ Script blocking may cause a problem running WDP.cmd... if so, we want to do this loop again
  313.         iTryAgain = 0
  314.  
  315.         Do While (iTryAgain < 1)
  316.             err.Clear
  317.  
  318.             ' ~~~ Call WDP.cmd with a numeric parameter... this will create several files for this particular tool
  319.             Call oShell.Run(chr(34) & sAppDir & "bin\WDP.CMD" & chr(34) & iWDPcmdVer, 0, True)
  320.  
  321.             ' ~~~ If the above line returns an error, it may be because AntiSpyware has blocked WDP.CMD and Windows
  322.             ' ~~~ stopped waiting for the Run to return. If this happens, we should error and exit the Sub
  323.             If err.number <> 0 Then 
  324.                 iTryAgain = iTryAgain + 1
  325.                 MsgBox L_WDPblocked_TEXT, vbCritical, L_WDPblockedTitle_TEXT
  326.             Else
  327.                 iTryAgain = 1
  328.             End If
  329.         Loop
  330.  
  331.         If oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Enabled"     & iWDPcmdVer & ".wdp").size <> 0 Then bEnabled = True
  332.         If oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Overlay"     & iWDPcmdVer & ".wdp").size <> 0 Then bOverlayCreated = True
  333.  
  334.         ' ~~~ Now check what the restart action is
  335.         If     oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Undo"    & iWDPcmdVer & ".wdp").size <> 0 Then 
  336.             bSetLevel = True
  337.         ElseIf oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Commit"  & iWDPcmdVer & ".wdp").size <> 0 Then 
  338.             bCommit = True
  339.         ElseIf oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Retain"  & iWDPcmdVer & ".wdp").size <> 0 Then 
  340.             bNoCMD = True
  341.         ElseIf oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Enable"  & iWDPcmdVer & ".wdp").size <> 0 Then 
  342.             bEnable = True
  343.         ElseIf oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Disable" & iWDPcmdVer & ".wdp").size <> 0 Then 
  344.             bDisable = True
  345.         End If
  346.  
  347.         ' ~~~ If the debug flag isn't set, then delete these temporary files
  348.         If NOT DEBUG Then
  349.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Temp"    & iWDPcmdVer & ".wdp")
  350.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Enabled" & iWDPcmdVer & ".wdp")
  351.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Overlay" & iWDPcmdVer & ".wdp")
  352.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Undo"    & iWDPcmdVer & ".wdp")
  353.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Commit"  & iWDPcmdVer & ".wdp")
  354.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Retain"  & iWDPcmdVer & ".wdp")
  355.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Enable"  & iWDPcmdVer & ".wdp")
  356.             oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\Disable" & iWDPcmdVer & ".wdp")
  357.         End If
  358.     End Sub
  359.  
  360.     ' ***
  361.     ' *** ------------------------------------------------------------------------------
  362.     ' *** Name:        Enable
  363.     ' *** ------------------------------------------------------------------------------
  364.     ' *** Purpose:    Enable disk protection, returns true if successful
  365.     ' *** ------------------------------------------------------------------------------
  366.     ' ***
  367.     Public Sub Enable
  368.         Dim iPossibleOverlaySize
  369.         Dim sAppDir
  370.     
  371.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  372.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  373.  
  374.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  375.         ' ~~~ write log
  376.         If bLogging Then oLog.Write "clsDiskProtect : Enable() : Entry"
  377.         
  378.         ' ~~~ only enable if not already enabled
  379.         If Not(Enabled) Then
  380.             ' ~~~ if no valid overlay can be found; delete any invalid overlays and create a new one
  381.             If Not(OverlayCreated) Then
  382.                 ' ~~~ delete any existing overlays
  383.                 Call oShell.Run(chr(34) & sAppDir & "bin\etprep.exe" & chr(34) & " -delete", 0, True)
  384.  
  385.                 ' ~~~ create objects
  386.                 Set oDiskDrives = oWMIService.ExecQuery("Select * from Win32_DiskDrive")
  387.         
  388.                 ' ~~~ if the user has not overridden the overlay size, autocalculate it
  389.                 iPossibleOverlaySize = CalcOVSize
  390.                 If (OverlaySize=0 or OverlaySize > iPossibleOverlaySize) and (ForceOverlaySize=0) Then OverlaySize = iPossibleOverlaySize
  391.                 
  392.                 If ForceOverlaySize > 0 Then OverlaySize = ForceOverlaySize
  393.             
  394.                 ' ~~~ create the overlay
  395.                 If OverlaySize > 0 then
  396.                     ' ~~~ Copy EWF dlls to System32 so RunDll32.exe can fine them
  397.                     Call oFso.CopyFile(sAppDir & "bin\ewfinit.dll", oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\ewfinit.dll")
  398.                     Call oFso.CopyFile(sAppDir & "bin\ewfdll.dll", oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\ewfdll.dll")
  399.  
  400.                     ' ~~~ Creates the Overlay!
  401.                     Call oShell.Run("rundll32.exe ewfinit.dll", 0, True)
  402.                     Call oShell.Run("rundll32.exe ewfdll.dll,ConfigureEwf", 0, True)
  403.                     If bLogging Then oLog.Write "clsDiskProtect : Overlay Creation Dlls called"
  404.  
  405.                     ' ~~~ Delete EWF dlls from System32... they are only used to create Overlay
  406.                     Dim oEWFInitDLL, oEWFDllDLL     
  407.  
  408.                     ' ~~~ Remove all file attributes
  409.                     Set oEWFInitDLL = oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\ewfinit.dll")
  410.                     Set oEWFDllDLL     = oFso.GetFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\ewfdll.dll")
  411.                     oEWFInitDLL.Attributes = 0
  412.                     oEWFDllDLL.Attributes  = 0
  413.  
  414.                     ' ~~~ Delete EWF dlls from System32
  415.                     Call oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\ewfinit.dll")
  416.                     Call oFso.DeleteFile(oshell.ExpandEnvironmentStrings("%WinDir%") & "\system32\ewfdll.dll")
  417.  
  418.                     ' ~~~ ------------------------------------------------------------------------------
  419.                     ' ~~~ Records system install time
  420.                     ' ~~~ ------------------------------------------------------------------------------
  421.  
  422.                     Set colOperatingSystems = oWMIService.ExecQuery("Select * from Win32_OperatingSystem where Primary=true")
  423.  
  424.                     For Each oOS in colOperatingSystems
  425.                         iOverlayTime = oOS.LocalDateTime
  426.                     Next
  427.  
  428.                     Call RegWrite(TOOLKITKEY & "SCTOverlayTime", iOverlayTime, "REG_SZ")
  429.                     Call EWFService("restore")
  430.                 End If
  431.             Else
  432.                 Call EWFCommand("enable")
  433.                 Call EWFService("restore")
  434.             End If
  435.  
  436.             ' ~~~ if domain member then disable computer account password changes
  437.             If DomainMember Then Call DisablePasswordChange(1)
  438.         Else
  439.             ' ~~~ already enabled
  440.             If bLogging Then oLog.Write "clsDiskProtect : Disable() : Disk protection already enabled"
  441.         End If
  442.  
  443.         ' ~~~ write log
  444.         If bLogging Then oLog.Write "clsDiskProtect : Enable() : Exit"
  445.     End Sub
  446.  
  447.     ' ***
  448.     ' *** ------------------------------------------------------------------------------
  449.     ' *** Name:        Disable
  450.     ' *** ------------------------------------------------------------------------------
  451.     ' *** Purpose:    Disable disk protection, returns true if successful
  452.     ' *** ------------------------------------------------------------------------------
  453.     ' ***
  454.     Public Sub Disable
  455.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  456.         ' ~~~ write log
  457.         If bLogging Then oLog.Write "clsDiskProtect : Disable() : Entry"
  458.  
  459.         ' ~~~ only if enabled
  460.         If Enabled Then
  461.             ' ~~~ call ewfmgr to disable
  462.             Call EWFCommand("disable")
  463.             Call EWFService("nocmd")
  464.  
  465.             ' ~~~ if domain member then enable computer account password changes
  466.             If DomainMember Then Call DisablePasswordChange(0)
  467.         ElseIF BootCommand = "ENABLE" Then
  468.             ' ~~~ call ewfmgr to disable
  469.             Call EWFCommand("nocmd")
  470.             Call EWFService("nocmd")
  471.         Else
  472.             ' ~~~ not enabled
  473.             If bLogging Then oLog.Write "clsDiskProtect : Disable() : Disk protection not enabled"
  474.         End If
  475.  
  476.         ' ~~~ write log
  477.         If bLogging Then oLog.Write "clsDiskProtect : Disable() : Exit"
  478.     End Sub
  479.     
  480.     ' ***
  481.     ' *** ------------------------------------------------------------------------------
  482.     ' *** Name:        Commit
  483.     ' *** ------------------------------------------------------------------------------
  484.     ' *** Purpose:    Commits the changes made, leaving ewf in undo mode
  485.     ' *** ------------------------------------------------------------------------------
  486.     ' ***
  487.     Public Sub Commit
  488.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  489.  
  490.         Dim sAppDir
  491.     
  492.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  493.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  494.  
  495.         ' ~~~ write log
  496.         If bLogging Then oLog.Write "clsDiskProtect : Commit() : Entry"
  497.  
  498.         ' ~~~ only if enabled
  499.         If Enabled Then
  500.             Call EWFCommand("commit")
  501.             Call EWFService("restore")
  502.             
  503.             ' ~~~ if computer is in a domain, we need to update the computer password
  504.             If DomainMember Then
  505.                 If bLogging Then oLog.Write "clsDiskProtect : Commit() : Domain Member, reset computer account password"
  506.                 Call DisablePasswordChange(0)
  507.                 iReturn =  oShell.Run(chr(34) & sAppDir & "bin\netdom.exe" & chr(34) & " reset %computername% /domain:%UserDomain%", 0, True)
  508.                 If bLogging Then oLog.Write "clsDiskProtect : Commit() : NetDom returned : " & iReturn
  509.                 Call DisablePasswordChange(1)
  510.             End If
  511.         Else
  512.             ' ~~~ not enabled
  513.             If bLogging Then oLog.Write "clsDiskProtect : Commit() : Disk protection not enabled"
  514.         End If
  515.  
  516.         ' ~~~ write log        
  517.         If bLogging Then oLog.Write "clsDiskProtect : Commit() : Exit"
  518.     End Sub
  519.  
  520.     ' ***
  521.     ' *** ------------------------------------------------------------------------------
  522.     ' *** Name:        UndoChanges
  523.     ' *** ------------------------------------------------------------------------------
  524.     ' *** Purpose:    All changes are disgarded with every reboot
  525.     ' *** ------------------------------------------------------------------------------
  526.     ' ***
  527.     Public Sub UndoChanges
  528.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  529.         ' ~~~ write log
  530.         If bLogging Then oLog.Write "clsDiskProtect : UndoChanges() : Entry"
  531.  
  532.         ' ~~~ only if enabled
  533.         If Enabled Then
  534.             Call EWFCommand("restore")
  535.             Call EWFService("restore")
  536.         Else
  537.             ' ~~~ not enabled
  538.             If bLogging Then oLog.Write "clsDiskProtect : UndoChanges() : Disk protection not enabled"
  539.         End If
  540.  
  541.         ' ~~~~ write log        
  542.         If bLogging Then oLog.Write "clsDiskProtect : UndoChanges() : Exit"
  543.     End Sub
  544.  
  545.     ' ***
  546.     ' *** ------------------------------------------------------------------------------
  547.     ' *** Name:        RetainChanges(bOnce)
  548.     ' *** ------------------------------------------------------------------------------
  549.     ' *** Purpose:    Changes are retained through one or many reboots
  550.     ' *** ------------------------------------------------------------------------------
  551.     ' ***
  552.     Public Sub RetainChanges(bOnce)
  553.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  554.         ' ~~~ write log
  555.         If bLogging Then oLog.Write "clsDiskProtect : RetainChanges() : Entry"
  556.  
  557.         ' ~~~ only if enabled
  558.         If Enabled Then
  559.             If bOnce Then
  560.                 Call EWFCommand("nocmd")
  561.                 Call EWFService("restore")
  562.             Else        
  563.                 Call EWFCommand("nocmd")
  564.                 Call EWFService("nocmd")
  565.             End If
  566.         Else
  567.             ' ~~~ not enabled
  568.             If bLogging Then oLog.Write "clsDiskProtect : RetainChanges() : Disk protection not enabled"
  569.         End If
  570.  
  571.         ' ~~~ write log        
  572.         If bLogging Then oLog.Write "clsDiskProtect : RetainChanges() : Exit"
  573.     End Sub
  574.  
  575.     ' ***
  576.     ' *** ------------------------------------------------------------------------------
  577.     ' *** Name:        Reboot()
  578.     ' *** ------------------------------------------------------------------------------
  579.     ' *** Purpose:    Forces a reboot of the computer
  580.     ' *** ------------------------------------------------------------------------------
  581.     ' ***
  582.     Public Sub Reboot
  583.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  584.         Dim sAppDir
  585.     
  586.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  587.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  588.     
  589.         ' ~~~ write log
  590.         If bLogging Then oLog.Write "clsDiskProtect : Reboot() : Entry"
  591.  
  592.         ' ~~~ Restart using SCT ForceLogoff Tool
  593.         Call oShell.Run(chr(34) & sAppDir & "bin\ForceLogoff.exe" & chr(34) & " /Restart", 0, False)
  594.  
  595.         ' ~~~ write log    - we might not get here    
  596.         If bLogging Then oLog.Write "clsDiskProtect : Reboot() : Exit"
  597.     End Sub
  598.  
  599.     ' ***
  600.     ' *** ------------------------------------------------------------------------------
  601.     ' *** Name:        EnableCriticalUpdates()
  602.     ' *** ------------------------------------------------------------------------------
  603.     ' *** Purpose:    Enables the automated critical update process
  604.     ' *** ------------------------------------------------------------------------------
  605.     ' ***
  606.     Public Sub EnableCriticalUpdates()
  607.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  608.         Dim sTime, sFreq
  609.         Dim sAppDir
  610.     
  611.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  612.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  613.  
  614.         ' ~~~ write log
  615.         If bLogging Then oLog.Write "clsDiskProtect : EnableCriticalUpdates() : Entry"
  616.         
  617.         ' ~~~ delete any existing tasks
  618.         Call DeleteScheduleTask(sCmd1)
  619.         Call DeleteScheduleTask(sCmd2)
  620.         Call DeleteScheduleTask(sCmd3)
  621.         Call oShell.Run(chr(34) & sAppDir & "bin\schtasks.exe" & chr(34) & " /Delete /TN SCTWakeUpPC /F", 0, True)
  622.         
  623.         ' ~~~ recreate tasks, if scripts have been populated
  624.         If WindowsUpdateScript() or AVUpdateScript <> "" or OtherUpdateScript <> "" or DomainMember Then
  625.             ' ~~~ get time & freq in to variables
  626.             sTime = ConvertTimeAUtoAT(CriticalUpdateTime)
  627.             Call RegWrite(TOOLKITKEY & "SCTRestart", sTime, "REG_SZ")
  628.  
  629.             If sTime = "000000" Then
  630.                 If CriticalUpdateDay > 1 and CriticalUpdateDay < 8 Then
  631.                     sFreq = ConvertDayAUtoAT(CriticalUpdateDay-1)
  632.                 ElseIf CriticalUpdateDay = 1 Then
  633.                     sFreq = ConvertDayAUtoAT(7)
  634.                 Else
  635.                     sFreq = ConvertDayAUtoAT(CriticalUpdateDay)
  636.                 End If
  637.             Else
  638.                 sFreq = ConvertDayAUtoAT(CriticalUpdateDay)
  639.             End If    
  640.  
  641.             ' ~~~ create tasks
  642.             Call CreateScheduleTask(sCmd1, TimePlus(sTime, 55), sFreq, True)
  643.             Call CreateScheduleTask(sCmd2, TimePlus(sTime, 59), sFreq, True)
  644.  
  645.             sFreq = ConvertDayAUtoAT(CriticalUpdateDay)
  646.             Call CreateScheduleTask(sCmd3, sTime, sFreq, True)
  647.  
  648.             ' ~~~ disables automatic updates & security center
  649.             Call RegWrite("HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoUpdate",    1, "REG_DWORD")
  650.             Call RegWrite("HKLM\Software\Microsoft\Security Center\UpdatesDisableNotify", 1, "REG_DWORD")
  651.         End If
  652.  
  653.         ' ~~~ write log
  654.         If bLogging Then oLog.Write "clsDiskProtect : EnableCriticalUpdates() : Exit"
  655.     End Sub
  656.  
  657.     ' ***
  658.     ' *** ------------------------------------------------------------------------------
  659.     ' *** Name:        DisableCriticalUpdates()
  660.     ' *** ------------------------------------------------------------------------------
  661.     ' *** Purpose:    Disables the automated critical update process
  662.     ' *** ------------------------------------------------------------------------------
  663.     ' ***
  664.     Public Sub DisableCriticalUpdates()
  665.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  666.         ' ~~~ write log
  667.         If bLogging Then oLog.Write "clsDiskProtect : DisableCriticalUpdates() : Entry"
  668.  
  669.         Dim sAppDir
  670.     
  671.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  672.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  673.  
  674.         ' ~~~ delete tasks
  675.         Call DeleteScheduleTask(sCmd1)
  676.         Call DeleteScheduleTask(sCmd2)
  677.         Call DeleteScheduleTask(sCmd3)
  678.         Call oShell.Run(chr(34) & sAppDir & "bin\schtasks.exe" & chr(34) & " /Delete /TN SCTWakeUpPC /F", 0, True)
  679.  
  680.         ' ~~~ enable automatic updates & scrurity center
  681.         Call RegWrite("HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoUpdate",    0, "REG_DWORD")
  682.         Call RegWrite("HKLM\Software\Microsoft\Security Center\UpdatesDisableNotify", 0, "REG_DWORD")
  683.  
  684.         ' ~~~ write log
  685.         If bLogging Then oLog.Write "clsDiskProtect : DisableCriticalUpdates() : Exit"
  686.     End Sub
  687.  
  688.     ' ***
  689.     ' *** ------------------------------------------------------------------------------
  690.     ' *** Name:        CalcOVSize
  691.     ' *** ------------------------------------------------------------------------------
  692.     ' *** Purpose:    Return the size of the overlay to create in hex
  693.     ' *** ------------------------------------------------------------------------------
  694.     ' ***
  695.     Public Function CalcOVSize()
  696.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  697.         Dim iMaxUnallocated, iUnallocated, sPType, bFoundExtended, bUnformattedPartition, iPartitions
  698.         Dim iTempPart, iExtSize, iExtFree, iUsedSpace, iBootPartitionSize, iPartitionCount, iEnd, sWindowsDrive
  699.  
  700.         If bLogging Then oLog.Write "clsDiskProtect : CalcOVSize()"
  701.  
  702.         ' ~~~ Determines what drive letter contains %WinDir%
  703.         Set colOperatingSystems = oWMIService.ExecQuery("Select * from Win32_OperatingSystem where Primary=true")
  704.         For Each oOS in colOperatingSystems
  705.  
  706.             If oOS.SystemDevice = oOS.BootDevice then
  707.                 Call RegWrite(TOOLKITKEY & "SystemBootSame", "True", "REG_SZ")
  708.             Else
  709.                 Call RegWrite(TOOLKITKEY & "SystemBootSame", "False", "REG_SZ")
  710.             End If    
  711.  
  712.             sWindowsDrive = Left(oOS.WindowsDirectory,2)
  713.         Next
  714.  
  715.         ' ~~~ Determines what physical disk and physical partition contains %WinDir%
  716.         iDiskID = 0
  717.         iPartID = 1
  718.         Set oDiskDrives = oWMIService.ExecQuery("Select * from Win32_DiskDrive")
  719.         For Each oDisk in oDiskDrives
  720.             sEscapedDeviceID    = Replace(oDisk.DeviceID, "\", "\\", 1, -1, vbTextCompare)
  721.             Set oDiskPartitions = oWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & sEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
  722.             For Each oPartition in oDiskPartitions
  723.             iTempPart = Right(oPartition.DeviceID,1) + 1
  724.                 Set oLogicalDisks = oWMIService.ExecQuery("ASSOCIATORS OF" & "{Win32_DiskPartition.DeviceID=""" & oPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
  725.                 ' ~~~ Collection of logical drives defined on the disk
  726.                 For Each oLogicalDisk In oLogicalDisks
  727.                     If oLogicalDisk.Name = sWindowsDrive then
  728.                         If IsNumeric(Right(oDisk.Name, 1)) then
  729.                             iDiskID = Int(Right(oDisk.Name, 1))
  730.                             iPartID = iTempPart 
  731.                         End If
  732.                     End If
  733.                 Next
  734.             Next
  735.         Next    
  736.  
  737.         ' ~~~ REG_MULTI_SZ *not* supported by RegWrite method - DO NOT CHANGE!
  738.         sCMD = "REG ADD HKLM\SYSTEM\CurrentControlSet\Services\EWF\FBA /f /v PVDisk /t REG_MULTI_SZ /d " & iDiskID
  739.         Call oShell.Run(sCMD, 0, True)
  740.         sCMD = "REG ADD HKLM\SYSTEM\CurrentControlSet\Services\EWF\FBA /f /v PVPart /t REG_MULTI_SZ /d " & iPartID
  741.         Call oShell.Run(sCMD, 0, True)
  742.                         
  743.         CalcOVSize = 0
  744.         iBootPartitionSize = 0
  745.         iUnallocated = 0
  746.         iMaxUnallocated = 0
  747.         iExtFree = 0
  748.         iExtSize = 0
  749.         iUsedSpace = 0
  750.         iPartitionCount = 0
  751.         bFoundExtended = False
  752.  
  753.         ' ~~~ loop through all the disk drives
  754.         For Each oDisk in oDiskDrives
  755.  
  756.             If oDisk.Index = iDiskID Then
  757.                 iPartitions = oDisk.Partitions
  758.                 ' ~~~ new disk, reset the end pointer
  759.                 iEnd   = 0
  760.                 sPType = ""
  761.                                         
  762.                 ' ~~~ get partitions associated with this disk, we need to escape the device id for the query to work
  763.                 sEscapedDeviceID    = Replace(oDisk.DeviceID, "\", "\\", 1, -1, vbTextCompare)
  764.                 Set oDiskPartitions = oWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & sEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
  765.                 
  766.                 ' ~~~ loop through all the partitions on this disk
  767.                 For Each oPartition in oDiskPartitions
  768.  
  769.                     ' ~~~ Count partitions on disk    
  770.                     iPartitionCount = iPartitionCount + 1
  771.                     
  772.                     ' ~~~ Determines Size of Boot Partition
  773.                     If oPartition.BootPartition = True or iPartID = iPartitionCount Then
  774.                         iBootPartitionSize = Int(oPartition.size/1024)
  775.                     End If
  776.                     
  777.                     ' ~~~ Determines if System and Boot Partition are one and the same
  778.                     ' ~~~ ignore extended partitions
  779.                     If sPType <> "Extended w/Extended Int 13" and sPType <> "Extended Partition" Then
  780.                         If oPartition.Index <> 0 Then
  781.                             ' ~~~ calculate the unallocated space before this partition            
  782.                             iUnallocated = CDbl(oPartition.StartingOffset) - iEnd
  783.                             If iMaxUnallocated < iUnallocated Then iMaxUnallocated = iUnallocated
  784.                         End If
  785.                     Else
  786.                         
  787.                         bFoundExtended = True
  788.  
  789.                     End If
  790.  
  791.                     ' ~~~ Notes partition type (Primary or Extended)... do *NOT* move this up!
  792.                     ' ~~~ Moving this line up will affect functionality when last partition is extended. 
  793.                     sPType = oPartition.Type
  794.                     iEnd   = CDbl(oPartition.StartingOffset) + CDbl(oPartition.Size)
  795.                 Next
  796.  
  797.  
  798.                 ' ~~~ determines if last partition is an Extended Partition
  799.                 If sPType = "Extended w/Extended Int 13" or sPType = "Extended Partition" Then bFoundExtended = True 
  800.  
  801.                 ' ~~~ calculate the unallocated space after the last partition
  802.                 iUnallocated = CDbl(oDisk.Size) - iEnd
  803.                 If iMaxUnallocated < iUnallocated Then iMaxUnallocated = iUnallocated
  804.                 If iPartitionCount = 4 Then iMaxUnallocated = 0
  805.              End If
  806.         Next
  807.         ' ~~~ Calculate Free Space in Extended Partition
  808.         If bfoundExtended = True then
  809.         iPartitionCount = 0
  810.         bUnformattedPartition = False
  811.             For Each oPartition in oDiskPartitions
  812.                 iPartitionCount = iPartitionCount + 1
  813.                 ' ~~~ Enter only if the partition is extended partition
  814.                 If oPartition.type = "Extended w/Extended Int 13" or oPartition.type = "Extended Partition"  Then
  815.                     iPartitionCount = iPartitionCount - 1
  816.                     ' ~~~ store the total size of the extended partition
  817.                     iExtsize = oPartition.size
  818.                     ' ~~~ Use partition device id to find logical disk
  819.                     Set oLogicalDisks = oWMIService.ExecQuery("ASSOCIATORS OF" & "{Win32_DiskPartition.DeviceID=""" & oPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
  820.                     ' ~~~ Collection of logical drives in the extended partition
  821.                     For Each oLogicalDisk In oLogicalDisks
  822.                         iPartitionCount = iPartitionCount + 1
  823.                         If Not(IsNull(oLogicalDisk.size)) then
  824.                             iUsedSpace = iUsedSpace + oLogicalDisk.size
  825.                         Else
  826.                             bUnformattedPartition = True
  827.                         End If
  828.                     Next
  829.                 End If
  830.                 iExtFree = iExtsize - iUsedSpace
  831.             Next
  832.             If iPartitionCount < iPartitions or bUnformattedPartition then
  833.                 iMaxUnallocated = 0
  834.                 iExtFree = 0
  835.             End If             
  836.         End If
  837.         ' ~~~ Clean up
  838.         Set oDiskPartitions    = Nothing
  839.         Set oDiskDrives        = Nothing
  840.         ' ~~~ return the largest unallocated/Extended Free space
  841.         If iMaxUnallocated > iExtFree then
  842.             CalcOVSize = Int(iMaxUnallocated/1024)-1024
  843.         Else
  844.             CalcOVSize = Int(iExtFree/1024)-25600
  845.         End If    
  846.         ' ~~~ Set to 0 if size req not met
  847.         If (CalcOVSize < 1022976) or (IsNull(CalcOVSize)) then CalcOVSize = 0
  848.         ' ~~~ Ensures Overlay is not larger than Boot Partition, so as not to be wasteful
  849.         If (CalcOVSize > iBootPartitionSize) and (iBootPartitionSize <> 0) then CalcOVSize = iBootPartitionSize
  850.     End Function
  851.  
  852.     ' ***
  853.     ' *** ------------------------------------------------------------------------------
  854.     ' *** Name:        DefineATCommands
  855.     ' *** ------------------------------------------------------------------------------
  856.     ' *** Purpose:    Defines AT commands created for WDP
  857.     ' *** ------------------------------------------------------------------------------
  858.     ' ***
  859.     Public Function DefineATCommands()
  860.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  861.         Dim sAppDir
  862.     
  863.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  864.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  865.  
  866.         ' ~~~ define schedule task commands globally because they are used by two methods
  867.         sCmd1 = "wscript """ & sAppDir & "bin\banner.wsf" & Chr(34) & " /Restart"
  868.         sCmd2 = "wscript """ & sAppDir & "bin\banner.wsf"""
  869.         sCmd3 = "wscript """ & sAppDir & "scripts\CriticalUpdates.wsf" & Chr(34) & " /Update /PreventLogin /Restart"
  870.  
  871.     End Function
  872.  
  873.     ' ***
  874.     ' *** ------------------------------------------------------------------------------
  875.     ' *** Name:        CreateScheduleTask(sCmd, sTime, sDay, bInteractive)
  876.     ' *** ------------------------------------------------------------------------------
  877.     ' *** Purpose:    Schedule a task using AT
  878.     ' *** ------------------------------------------------------------------------------
  879.     ' ***
  880.     Public Function CreateScheduleTask(sCmd, sTime, sDay, bInteractive)
  881.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  882.         Dim sATCmd, ScheduleTask, sTimeZone, strComputer, oNewJob, errJobCreated, jobId
  883.         
  884.         ' ~~~ write log
  885.         If bLogging Then oLog.Write "clsDiskProtect : CreateScheduleTask() : Entry"
  886.  
  887.         ' ~~~ ------------------------------------------------------------------------------
  888.         ' ~~~ Records system install time
  889.         ' ~~~ ------------------------------------------------------------------------------
  890.  
  891.         Set colOperatingSystems = oWMIService.ExecQuery("Select * from Win32_OperatingSystem where Primary=true")
  892.  
  893.         For Each oOS in colOperatingSystems
  894.             sTimeZone = oOS.LocalDateTime
  895.         Next
  896.  
  897.         sTimeZone = Right(sTimeZone,4)
  898.                 
  899.         Set oNewJob = oWMIService.Get("Win32_ScheduledJob")
  900.         
  901.         Select Case sDay
  902.         Case 1
  903.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 1, , bInteractive, JobId) 
  904.         Case 2
  905.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 2, , bInteractive, JobId) 
  906.         Case 4
  907.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 4, , bInteractive, JobId) 
  908.         Case 8
  909.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 8, , bInteractive, JobId) 
  910.         Case 16
  911.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 16, , bInteractive, JobId) 
  912.         Case 32
  913.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 32, , bInteractive, JobId) 
  914.         Case 64
  915.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 64, , bInteractive, JobId) 
  916.         Case Else
  917.             errJobCreated = oNewJob.Create(sCmd, "********" & sTime & ".000000" & sTimeZone, True , 1 or 2 or 4 or 8 or 16 or 32 or 64, , bInteractive, JobId) 
  918.         End Select
  919.  
  920.         ' ~~~ return result    
  921.         If errJobCreated <> 0 Then
  922.             ScheduleTask = False
  923.         Else
  924.             ScheduleTask = True
  925.         End If
  926.         
  927.         ' ~~~ Destroy Objects    
  928.         Set oNewJob = nothing
  929.  
  930.         ' ~~~ write log
  931.         If bLogging Then oLog.Write "clsDiskProtect : CreateScheduleTask() : Exit"
  932.     End Function
  933.  
  934.     ' ***
  935.     ' *** ------------------------------------------------------------------------------
  936.     ' *** Name:        DeleteScheduleTask()
  937.     ' *** ------------------------------------------------------------------------------
  938.     ' *** Purpose:    Delete AT commands created for WDP
  939.     ' *** ------------------------------------------------------------------------------
  940.     ' ***
  941.     Public Sub DeleteScheduleTask(sTempCmd)
  942.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  943.         Dim oScheduledJobs, oJob
  944.         ' ~~~ write log
  945.         If bLogging Then oLog.Write "clsDiskProtect : DeleteScheduleTask() : Entry"
  946.  
  947.         ' ~~~ use wmi to delete task
  948.  
  949.         Set oScheduledJobs = oWMIService.ExecQuery("Select * from Win32_ScheduledJob")
  950.         For Each oJob in oScheduledJobs
  951.             If oJob.Command = sTempCmd Then oJob.Delete
  952.         Next
  953.         If bLogging Then oLog.Write "clsDiskProtect : DeleteScheduleTask() : Delete Tasks - " & sTempCmd
  954.  
  955.         ' ~~~ write log
  956.         If bLogging Then oLog.Write "clsDiskProtect : DeleteScheduleTask() : Exit"
  957.     End Sub
  958.  
  959.     ' ***
  960.     ' *** ------------------------------------------------------------------------------
  961.     ' *** Name:        SystemBootSame
  962.     ' *** ------------------------------------------------------------------------------
  963.     ' *** Purpose:    Returns true System and Boot Partition are one and the same
  964.     ' *** ------------------------------------------------------------------------------
  965.     ' ***
  966.     Public Function SystemBootSame()
  967.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  968.         If RegRead(TOOLKITKEY & "SystemBootSame") = "True" Then
  969.             SystemBootSame = True
  970.         Else
  971.             SystemBootSame = False
  972.         End If
  973.     End Function
  974.  
  975.     ' ***
  976.     ' *** ------------------------------------------------------------------------------
  977.     ' *** Name:        GetHibernation
  978.     ' *** ------------------------------------------------------------------------------
  979.     ' *** Purpose:    Returns true if hibernation is enabled or returns false
  980.     ' *** ------------------------------------------------------------------------------
  981.     ' ***
  982.     Public Function GetHibernation()
  983.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  984.         Dim systemDir
  985.         systemDir = oShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
  986.         systemDir = Left(systemDir,2)
  987.         If oFso.FileExists(systemDir & "\HIBERFIL.sys") Then
  988.             ' ~~~ if hiberfil.sys exists, hibernation is enabled
  989.             GetHibernation = True
  990.         Else
  991.             ' ~~~ if hiberfil.sys does not exist, hibernation is not enabled
  992.             GetHibernation = False
  993.         End If
  994.     End Function
  995.  
  996.     ' *** 
  997.     ' *** ------------------------------------------------------------------------------
  998.     ' *** Name:            GetStashUpperFilterKey
  999.     ' *** ------------------------------------------------------------------------------
  1000.     ' *** Purpose:        Reads in UpperFilter key... record it in TOOLKITKEY
  1001.     ' *** ------------------------------------------------------------------------------
  1002.     ' *** 
  1003.     Public Sub GetStashUpperFilterKey
  1004.         ' ~~~ Read and record UpperFilters key in SCT registry
  1005.         sUpperFilter = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Class\{71A27CDD-812A-11D0-BEC7-08002BE2092F}\UpperFilters")
  1006.         Call RegWrite(TOOLKITKEY & "WDPUpperFilterKey", sUpperFilter, "REG_SZ")
  1007.     End Sub
  1008.  
  1009.     ' *** 
  1010.     ' *** ------------------------------------------------------------------------------
  1011.     ' *** Name:            WriteUpperFilterKey
  1012.     ' *** ------------------------------------------------------------------------------
  1013.     ' *** Purpose:        Writes to UpperFilter key... updates SCTInstallTime
  1014.     ' *** ------------------------------------------------------------------------------
  1015.     ' *** 
  1016.     Public Sub WriteUpperFilterKey
  1017.         ' ~~~ Read and record UpperFilters key in SCT registry
  1018.         Call RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{71A27CDD-812A-11D0-BEC7-08002BE2092F}\UpperFilters", arrUpperFilters, "REG_MULTI_SZ")
  1019.         Call RegWrite(TOOLKITKEY & "SCTInstallTime", iLocalDateTime, "REG_SZ")
  1020.     End Sub
  1021.  
  1022.     ' *** 
  1023.     ' *** ------------------------------------------------------------------------------
  1024.     ' *** Name:            UpperFilterCheck(sList)
  1025.     ' *** ------------------------------------------------------------------------------
  1026.     ' *** Purpose:        Checks the UpperFilter registry key for incompatible filters
  1027.     ' *** ------------------------------------------------------------------------------
  1028.     ' *** 
  1029.     Public Function UpperFilterCheck(sList)
  1030.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1031.  
  1032.         Dim  sUpperFilterName
  1033.     
  1034.         Dim oXml, ufXml, oProduct, oProdChildNode
  1035.  
  1036.         Select Case sList
  1037.  
  1038.             Case "BlackList"
  1039.  
  1040.                 ufXml = GetRootFolder & "\xml\UpperFilterCheckBlack.xml"
  1041.                 Set oXml = CreateObject("MSXML2.DomDocument")
  1042.                 Call oXml.Load(ufXml)    
  1043.  
  1044.                 bBlackList = False
  1045.  
  1046.                 If oXml.parseError.errorCode = 0 Then
  1047.                     ' ~~~ Loop through each of the UpperFilters 
  1048.                     For Each oProduct in oXml.getElementsByTagName("Product")
  1049.                         ' ~~~ Get the values of each product
  1050.                         For Each oProdChildNode in oProduct.ChildNodes
  1051.                             Select Case oProdChildNode.NodeName 
  1052.                                 Case "Name"
  1053.                                     sUpperFilterName = oProdChildNode.Text
  1054.                             End Select
  1055.                             If InStr(UCase(sUpperFilter), ","&UCase(sUpperFilterName)&",") > 0 Then
  1056.                                 bBlackList = True
  1057.                             End If
  1058.                         Next
  1059.                     Next
  1060.                 End If
  1061.  
  1062.             Case "WhiteList"    
  1063.  
  1064.                 ufXml = GetRootFolder & "\xml\UpperFilterCheckWhite.xml"
  1065.                 Set oXml = CreateObject("MSXML2.DomDocument")
  1066.                 Call oXml.Load(ufXml)
  1067.  
  1068.                 If oXml.parseError.errorCode = 0 Then
  1069.  
  1070.                     ' ~~~ Loop through each of the UpperFilters 
  1071.                     bWhiteList = False
  1072.  
  1073.                     arrTempArray = Split(sUpperFilter, ",")
  1074.  
  1075.                     For i = LBound(arrTempArray) to UBound(arrTempArray)
  1076.                         For Each oProduct in oXml.getElementsByTagName("Product")
  1077.                             ' ~~~ Get the values of each product
  1078.                             For Each oProdChildNode in oProduct.ChildNodes
  1079.                                 Select Case oProdChildNode.NodeName 
  1080.                                     Case "Name"
  1081.                                         sUpperFilterName = oProdChildNode.Text
  1082.                                 End Select
  1083.                                 If arrTempArray(i+1) <> "" Then
  1084.                                     If (UCase(sUpperFilterName) = UCase(arrTempArray(i+1))) Then
  1085.                                         bWhiteList = True
  1086.                                         Exit For
  1087.                                     Else
  1088.                                         bWhiteList = False
  1089.                                     End If
  1090.                                 End If
  1091.                             Next
  1092.                         
  1093.  
  1094.                             If Not(bWhiteList) Then Exit For    
  1095.                         Next
  1096.                         If Not(bWhiteList) Then Exit For
  1097.                     Next
  1098.                 End If
  1099.         End Select
  1100.     End Function
  1101.  
  1102.     ' ~~~ 
  1103.     ' ~~~ private methods
  1104.     ' ~~~ 
  1105.  
  1106.     ' ***
  1107.     ' *** ------------------------------------------------------------------------------
  1108.     ' *** Name:        Class_Initialize
  1109.     ' *** ------------------------------------------------------------------------------
  1110.     ' *** Purpose:    Used internally by the class when it is created.
  1111.     ' ***            Declared as private because it must not be called directly.
  1112.     ' *** ------------------------------------------------------------------------------
  1113.     ' ***
  1114.     Private Sub Class_Initialize
  1115.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1116.         ' ~~~ set default values for properties
  1117.         bLogging = False
  1118.  
  1119.         Call WDPState
  1120.         Call DefineATCommands
  1121.  
  1122.     End Sub
  1123.  
  1124.     ' ***
  1125.     ' *** ------------------------------------------------------------------------------
  1126.     ' *** Name:        Class_Terminate
  1127.     ' *** ------------------------------------------------------------------------------
  1128.     ' *** Purpose:    Used internally by the class when it is destroyed.
  1129.     ' ***            Declared as private because it must not be called directly.
  1130.     ' *** ------------------------------------------------------------------------------
  1131.     ' ***
  1132.     Private Sub Class_Terminate
  1133.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1134.     End Sub
  1135.  
  1136.     ' ***
  1137.     ' *** ------------------------------------------------------------------------------
  1138.     ' *** Name:        EWFCommand(sCmd)
  1139.     ' *** ------------------------------------------------------------------------------
  1140.     ' *** Purpose:    Runs the specified EWF Command
  1141.     ' *** ------------------------------------------------------------------------------
  1142.     ' ***
  1143.     Private Sub EWFCommand(sCmd)
  1144.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1145.         Dim sAppDir
  1146.     
  1147.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  1148.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  1149.  
  1150.         If bLogging Then oLog.Write "clsDiskProtect : EWFCommand(" & sCmd & ")"
  1151.         Call oShell.Run(chr(34) & sAppDir & "bin\ewfmgr.exe" & chr(34) & " " & Left(oshell.ExpandEnvironmentStrings("%WinDir%"),2) & " -" & sCmd, 0,True)
  1152.     End Sub
  1153.  
  1154.     ' ***
  1155.     ' *** ------------------------------------------------------------------------------
  1156.     ' *** Name:        EWFService(sCmd)
  1157.     ' *** ------------------------------------------------------------------------------
  1158.     ' *** Purpose:    Sets the service to run the EWF command on next reboot
  1159.     ' *** ------------------------------------------------------------------------------
  1160.     ' ***
  1161.     Private Sub EWFService(sCmd)
  1162.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1163.         Dim sAppDir
  1164.     
  1165.         ' ~~~ Do not attempt to use GetRootFolder here... called from WSF file.
  1166.         sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  1167.  
  1168.         If bLogging Then oLog.Write "clsDiskProtect : EWFService(" & sCmd & ")"
  1169.         Call RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\WDPOperations\Parameters\Application", chr(34) & sAppDir & "bin\ewfmgr.exe" & chr(34) & " " & Left(oshell.ExpandEnvironmentStrings("%WinDir%"),2) & " -" & sCmd, "REG_SZ")
  1170.     End Sub
  1171.     
  1172.     ' ***
  1173.     ' *** ------------------------------------------------------------------------------
  1174.     ' *** Name:        DisablePasswordChange(iDisable)
  1175.     ' *** ------------------------------------------------------------------------------
  1176.     ' *** Purpose:    Enables or disables computer domain account passwords
  1177.     ' ***            iDisable = Integer, 1 = disabled, 0 = enabled
  1178.     ' *** ------------------------------------------------------------------------------
  1179.     ' ***
  1180.     Private Sub DisablePasswordChange(iDisable)
  1181.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1182.         If bLogging Then oLog.Write "clsDiskProtect : DisablePasswordChange(" & iDisable & ")"
  1183.         Call RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\DisablePasswordChange", iDisable, "REG_DWORD")
  1184.     End Sub
  1185.  
  1186.     ' ***
  1187.     ' *** ------------------------------------------------------------------------------
  1188.     ' *** Name:        ConvertDayAUtoAT
  1189.     ' *** ------------------------------------------------------------------------------
  1190.     ' *** Purpose:    Converts an Automatic Updates day of the week to something that the
  1191.     ' ***            AT command will understand
  1192.     ' *** ------------------------------------------------------------------------------
  1193.     ' ***
  1194.     Private Function ConvertDayAUtoAT(iD)
  1195.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1196.         Select Case iD
  1197.             Case 2
  1198.                 ConvertDayAUtoAT = "1"
  1199.             Case 3
  1200.                 ConvertDayAUtoAT = "2"
  1201.             Case 4
  1202.                 ConvertDayAUtoAT = "4"
  1203.             Case 5
  1204.                 ConvertDayAUtoAT = "8"
  1205.             Case 6
  1206.                 ConvertDayAUtoAT = "16"
  1207.             Case 7
  1208.                 ConvertDayAUtoAT = "32"
  1209.             Case 1
  1210.                 ConvertDayAUtoAT = "64"
  1211.             Case Else
  1212.                 ConvertDayAUtoAT = "1248163264"
  1213.         End Select
  1214.     End Function
  1215.  
  1216.     ' ***
  1217.     ' *** ------------------------------------------------------------------------------
  1218.     ' *** Name:        ConvertTimeAUtoAT
  1219.     ' *** ------------------------------------------------------------------------------
  1220.     ' *** Purpose:    Converts an Automatic Updates time to something that the
  1221.     ' ***            AT command will understand
  1222.     ' *** ------------------------------------------------------------------------------
  1223.     ' ***
  1224.     Private Function ConvertTimeAUtoAT(iT)
  1225.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1226.         Select Case iT
  1227.             Case 1
  1228.                 ConvertTimeAUtoAT = "010000"
  1229.             Case 2
  1230.                 ConvertTimeAUtoAT = "020000"
  1231.             Case 3
  1232.                 ConvertTimeAUtoAT = "030000"
  1233.             Case 4
  1234.                 ConvertTimeAUtoAT = "040000"
  1235.             Case 5
  1236.                 ConvertTimeAUtoAT = "050000"
  1237.             Case 6
  1238.                 ConvertTimeAUtoAT = "060000"
  1239.             Case 7
  1240.                 ConvertTimeAUtoAT = "070000"
  1241.             Case 8
  1242.                 ConvertTimeAUtoAT = "080000"
  1243.             Case 9
  1244.                 ConvertTimeAUtoAT = "090000"
  1245.             Case 10
  1246.                 ConvertTimeAUtoAT = "100000"
  1247.             Case 11
  1248.                 ConvertTimeAUtoAT = "110000"
  1249.             Case 12
  1250.                 ConvertTimeAUtoAT = "120000"
  1251.             Case 13
  1252.                 ConvertTimeAUtoAT = "130000"
  1253.             Case 14
  1254.                 ConvertTimeAUtoAT = "140000"
  1255.             Case 15
  1256.                 ConvertTimeAUtoAT = "150000"
  1257.             Case 16
  1258.                 ConvertTimeAUtoAT = "160000"
  1259.             Case 17
  1260.                 ConvertTimeAUtoAT = "170000"
  1261.             Case 18
  1262.                 ConvertTimeAUtoAT = "180000"
  1263.             Case 19
  1264.                 ConvertTimeAUtoAT = "190000"
  1265.             Case 20
  1266.                 ConvertTimeAUtoAT = "200000"
  1267.             Case 21
  1268.                 ConvertTimeAUtoAT = "210000"
  1269.             Case 22
  1270.                 ConvertTimeAUtoAT = "220000"
  1271.             Case 23
  1272.                 ConvertTimeAUtoAT = "230000"
  1273.             Case Else
  1274.                 ConvertTimeAUtoAT = "000000"
  1275.         End Select
  1276.     End Function
  1277.     
  1278.     ' ***
  1279.     ' *** ------------------------------------------------------------------------------
  1280.     ' *** Name:        TimePlus(sTime, iMins)
  1281.     ' *** ------------------------------------------------------------------------------
  1282.     ' *** Purpose:    Calculates the proper WDP AT command times
  1283.     ' *** ------------------------------------------------------------------------------
  1284.     ' ***
  1285.     Private Function TimePlus(sTime, iMins)
  1286.         If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  1287.         
  1288.         Dim sTempTime
  1289.  
  1290.         ' ~~~ Handles 12:00 AM (sTime = 000000)
  1291.         If Left(sTime,2) > 0 Then
  1292.             sTempTime = Right(sTime,5) - 10000
  1293.  
  1294.             ' ~~~ Handles 10:00 AM & 8:00 PM (sTime = 100000 or 200000)
  1295.             If sTempTime < 0 Then
  1296.                 If Left(sTime,1) = 1 Then
  1297.                     TimePlus = "09" & iMins & Right(sTime, 2)
  1298.                 ElseIf Left(sTime,1) = 2 Then  
  1299.                     TimePlus = "19" & iMins & Right(sTime, 2)
  1300.                 End If
  1301.             Else    
  1302.                 TimePlus = Left(sTime, 1) & Left(sTempTime,1) & iMins & Right(sTime, 2)
  1303.             End If
  1304.         Else
  1305.             TimePlus = "23" & iMins & Right(sTime, 2) 
  1306.         End If
  1307.     End Function
  1308.  
  1309. End Class
  1310.