home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / WindowsServerTrial / server.iso / sources / boot.wim / 1 / Windows / System32 / manage-bde.wsf < prev    next >
Text File  |  2008-01-05  |  128KB  |  4,025 lines

  1. <package>
  2.     <job id="manage-bde">
  3.         <script language="VBScript" id="language-resourcer">
  4.  
  5. '------------------------------------------------------------------------------'
  6. '-------------Language resourcer-----------------------------------------------'
  7. '------------------------------------------------------------------------------'
  8. Option Explicit
  9. '-------------Language Localizer-------------'
  10. '- The language resourcer localizes the script
  11. '- According to the current language
  12. '- INI files are contained in the hex(language)
  13. '- Directory
  14. '- The class is instantiated for a particular
  15. '- file and language.
  16.     
  17. Class LanguageResourcer
  18.     Private Values
  19.     Private m_sPrefix
  20.  
  21.     ' Get the overridden UI language.
  22.     Function GetLangID()
  23.         Dim args, lang
  24.  
  25.         Set args = WScript.Arguments.Named
  26.         If args.Exists("lang") Then
  27.             lang = args.Item("lang")
  28.             GetLangID = CInt(lang)
  29.         Else
  30.             GetLangID = GetUILanguage()
  31.         End If
  32.     End Function
  33.  
  34.     Sub Class_Initialize
  35.         Set Values = CreateObject("Scripting.Dictionary")
  36.         Values.CompareMode = VBTextCompare
  37.         m_sPrefix  = Empty
  38.     End Sub
  39.  
  40.     'Initialize the Resourcer for a particular script
  41.     'We then look up the script and fill the dictionary
  42.     'with strings for this script.
  43.     Function Initialize( sScriptName , sPrefix)
  44.  
  45.         Const ForReading = 1, TristateUseDefault = -2
  46.         Dim lang, value, ini
  47.         Dim fso
  48.         Set fso    = CreateObject("Scripting.FileSystemObject")
  49.         
  50.         lang = GetLangID()
  51.         m_sPrefix = sPrefix
  52.  
  53.         '-We assume that the ini file is in (script_dir)/locale/script.ini
  54.         ini = fso.GetParentFolderName(WScript.ScriptFullName) & "\" _
  55.             & ToHex(lang) & "\" & fso.GetBaseName(sScriptName) &  ".ini"
  56.  
  57.         '-If it isn't there, we'll attempt to fall back to (script_dir)/script.ini
  58.         If Not fso.FileExists(ini) Then
  59.           ini = fso.GetParentFolderName(WScript.ScriptFullName) & "\" _
  60.              & fso.GetBaseName(sScriptName) &  ".ini"
  61.         End If 
  62.         
  63.         '-If that isn't there (script_dir)/script.ini.en contains english strings
  64.         If Not fso.FileExists(ini) Then
  65.           ini = fso.GetParentFolderName(WScript.ScriptFullName) & "\" _
  66.              & fso.GetBaseName(sScriptName) &  ".ini.en"
  67.         End If  
  68.  
  69.  
  70.         If fso.FileExists(ini) Then
  71.             Dim stream, file
  72.  
  73.             Debug.WriteLine "Using resource file " & ini
  74.  
  75.             Set file = fso.GetFile(ini)
  76.             Set stream = file.OpenAsTextStream(ForReading, TristateUseDefault)
  77.             ReadResources( stream )
  78.         Else
  79.  
  80.             WScript.StdErr.WriteLine "ERROR:Could not locate resource file " & ini
  81.             WScript.Quit -1
  82.         End If
  83.  
  84.     End Function
  85.  
  86.     ' Get a localized resource for 'resourceID' if available;
  87.     ' otherwise, get the neutral resource.
  88.     Function Localize(resourceID)
  89.         If Values.Exists(resourceID) Then
  90.             Localize = Values.Item(resourceID)
  91.         Else
  92.             WScript.StdOut.WriteLine "Localization-Warning: "&resourceID&" not found"
  93.             Localize = Empty
  94.         End If
  95.     End Function
  96.  
  97.     'Read all the resource IDs and place them in the dictionary
  98.     Function ReadResources(stream)
  99.         Const ERROR_FILE_NOT_FOUND = 2
  100.         Dim ln, arr, key, value,pref_arr
  101.         Dim bLineContinuation
  102.  
  103.         bLineContinuation = False
  104.  
  105.         If Not IsObject(stream) Then Err.Raise ERROR_FILE_NOT_FOUND
  106.  
  107.         Do Until stream.AtEndOfStream
  108.             ln = stream.ReadLine
  109.  
  110.             If bLineContinuation Then
  111.                 value = value & vbCrLf & ln
  112.                 If IsTerminated(value) Then
  113.                     AddString key,value
  114.                     bLineContinuation = False
  115.                 End If
  116.             End If
  117.  
  118.             arr = Split(ln, "=", 2, 1)
  119.  
  120.             If UBound(arr, 1) = 1 Then
  121.                 If bLineContinuation Then
  122.                     WScript.Quit -1
  123.                 End If
  124.  
  125.                 ' Trim the key and the value first before trimming quotes
  126.                 key = Trim(arr(0))
  127.                 value = Trim(arr(1))
  128.                 
  129.                 If Not IsTerminated(value) then
  130.                     bLineContinuation = True 'Tell engine to add to this line
  131.                 Else
  132.                     AddString key,value
  133.                 End If
  134.                 
  135.             End If
  136.         Loop
  137.  
  138.         stream.Close
  139.     End Function
  140.  
  141.     Private Function AddString(key,value)
  142.         Dim sKey,sValue,pref_arr
  143.  
  144.         sValue = Trim(value)
  145.         sValue = StripQuotes(Trim(sValue))
  146.         sValue = Replace(sValue,"\""","""")
  147.         sValue = Replace(sValue,"\n",VbCrLf)
  148.         sKey = key
  149.  
  150.         If Not(IsEmpty(m_sPrefix)) Then
  151.             pref_arr = Split(sKey,".",2,1)
  152.  
  153.             If UBound(pref_arr,1) = 1 Then
  154.                 If m_sPrefix = pref_arr(0) Then
  155.                     sKey = pref_arr(1)
  156.                 Else
  157.                     sKey = Empty
  158.                 End If
  159.             Else
  160.                 sKey = Empty
  161.             End If
  162.         End If
  163.  
  164.         If Not IsEmpty(sKey) Then
  165.  
  166.             If Values.Exists(sKey) Then
  167.                 WScript.StdOut.WriteLine "ResourceID " & sKey & "Is listed twice"
  168.             Else
  169.                 Values.Add sKey,sValue
  170.             End If
  171.         End If
  172.     End Function
  173.  
  174.     Function IsTerminated(s)
  175.         If Len(s) > 1 Then
  176.  
  177.             If InStr(Len(s), s, """", vbTextCompare) = Len(s) _
  178.                 And Not InStr(Len(s)-1, s, "\""", vbTextCompare) = Len(s)-1 Then
  179.                 IsTerminated = True
  180.             Else
  181.                 IsTerminated = False
  182.             End If
  183.         Else
  184.             IsTerminated = False
  185.         End If
  186.     End Function
  187.  
  188.     Function StripQuotes(s)
  189.         Dim c
  190.         c = """"
  191.  
  192.         If Len(s) > 2 Then
  193.             If InStr(1, s, c, vbTextCompare) > 0 Then
  194.                 s = Mid(s, InStr(1, s, """", vbTextCompare) + 1)
  195.             End If
  196.             
  197.             If Len(s) > 0 Then 
  198.                 If InStr(Len(s), s, c, vbTextCompare) = Len(s) Then
  199.                     s = Mid(s, 1, Len(s) - 1)
  200.                 End If
  201.             End If
  202.         End If
  203.  
  204.         StripQuotes = s
  205.     End Function
  206.  
  207.     ' Get a 4-digit hexadecimal number
  208.     Function ToHex(n)
  209.         Dim s : s = Hex(n)
  210.         ToHex = String(4 - Len(s), "0") & s
  211.     End Function
  212.  
  213. End Class
  214.  
  215. '- The global object GLR
  216. '- is initially instantiated and represents the main
  217. '- script which is being run
  218. '- instantiate a more local LanguageResourcer with a
  219. '- custom script name for included files.
  220. Dim GLR
  221. Set GLR = new LanguageResourcer
  222. GLR.Initialize WScript.ScriptName,Empty
  223.  
  224. </script>
  225.  
  226. <!------------------------------------------------------>
  227. <!-------- Parsing Library ----------------------------->
  228. <!------------------------------------------------------>
  229.  
  230. <script language="VBScript" id="parser">
  231. Option Explicit
  232.  
  233.  
  234.  
  235. 'These constants are used to indicate how
  236. 'the parameter should be parsed
  237. 'func indicates to call a function
  238. 'to parse the data
  239. Const kARG_STR    = 0
  240. Const kARG_FUNC   = 1
  241. Const kARG_BOOL   = 2
  242.  
  243. 'Indicates what kind of command line parameter it is
  244. 'CMD = command, only one of these may be used
  245. 'PRM = regular parameter, no special processing done
  246. Const kPARAM_CMD    = 1
  247. Const kPARAM_PRM    = 2
  248. Const kPARAM_FREE   = 3
  249.  
  250. 'Which list of parameters to place the parameter in
  251. 'Advanced, common, and shared respectively
  252. Const kUSAGE_ADV    = 0
  253. Const kUSAGE_CMN    = 1
  254. Const kUSAGE_SHR    = 2
  255.  
  256. '- How many characters to wrap each line at
  257. Const kLINE_WRAP    = 79
  258.  
  259. Class ParseInfo
  260.     Private m_sArg
  261.     Private m_tDoFail
  262.  
  263.     Public Property Get Argument()
  264.         Argument = m_sArg
  265.     End Property
  266.  
  267.     Public Property Let Argument(InVal)
  268.         m_sArg = InVal
  269.     End Property
  270.  
  271.     Public Property Let DoFail(tInVal)
  272.         m_tDoFail = tInVal
  273.     End Property
  274.  
  275.     Public Function FailOnError()
  276.         FailOnError = m_tDoFail
  277.     End Function
  278. End Class
  279.  
  280. Class BdeArgElem
  281.     Private m_nType
  282.     Private m_sName,m_aShortNames
  283.     Private m_vVal
  284.     Private m_bRequired
  285.     Private m_bArgAccepted
  286.     Private m_nParamType
  287.     Private m_Val
  288.     Private m_sDescription
  289.     Private m_sShortDescription
  290.     Private m_sInlineUsage
  291.     Private m_nUsageType
  292.     Private m_bSet
  293.  
  294.     Private Sub class_initialize
  295.         m_bRequired = False
  296.         m_sDescription = GLR.Localize("parse.no_desc")
  297.         m_sShortDescription = Empty
  298.         m_sInlineUsage = "-arg val"
  299.         m_bSet = False
  300.     End Sub
  301.  
  302.     Public Property Let ShortDescription(InVal)
  303.         m_sShortDescription = InVal
  304.     End Property
  305.  
  306.     Public Function InlineUsage()
  307.         InlineUsage = m_sInlineUsage
  308.     End Function
  309.     
  310.     Public Function Description()
  311.         Description = m_sDescription
  312.     End Function
  313.  
  314.     Public Property Get ShortDescription()
  315.         If IsEmpty(m_sShortDescription) Then
  316.             ShortDescription = m_sDescription
  317.         Else
  318.             ShortDescription = m_sShortDescription
  319.         End If
  320.     End Property
  321.             
  322.     Public Function Init(nParamType, sName,sShortName,nType, vVal,vDefault,bRequired, bArgAccepted)
  323.         m_nParamType = nParamType
  324.         m_sName = LCase(sName)
  325.         m_aShortNames = Split(LCase(sShortName),",")
  326.         m_nType = nType
  327.         m_bRequired = bRequired
  328.         m_bArgAccepted = bArgAccepted
  329.         m_Val = vDefault
  330.         If( IsObject(vVal) ) Then
  331.             Set m_vVal = vVal
  332.         Else 
  333.             m_vVal = vVal
  334.         End If
  335.     End Function
  336.  
  337.     Public Function SetUsage(nUsage,sInlineUsage, sDescription)
  338.         m_sInlineUsage = sInlineUsage
  339.         m_sDescription = sDescription
  340.         m_nUsageType   = nUsage
  341.     End Function
  342.  
  343.     Public Function Parse(sArg)
  344.         Parse = ParsePrivate(sArg,True)
  345.     End Function
  346.  
  347.     Public Function ParseNoFail(sArg)
  348.         ParseNoFail = ParsePrivate(sArg,False)
  349.     End Function
  350.     
  351.     Private Function ParsePrivate(sArg,tDoFail)
  352.         Dim sVal,oParseObj
  353.  
  354.         Set oParseObj = new ParseInfo
  355.         oParseObj.Argument = sArg
  356.         oParseObj.DoFail = tDoFail
  357.  
  358.         If m_bSet Then
  359.             InvalidSyntax(DisplayName())
  360.         End If
  361.  
  362.         If m_nType <> kARG_FUNC And m_bArgAccepted And IsEmpty(sArg) And IsEmpty(m_Val) Then
  363.             Fail VBsprintf(GLR.Localize("parse.required_missing"),Array(m_sName))
  364.         End If
  365.  
  366.         Select Case m_nType
  367.             Case kARG_STR
  368.                 sVal = sArg
  369.             Case kARG_FUNC
  370.                 sVal = ((m_vVal)(oParseObj))
  371.             Case kARG_BOOL
  372.                 If sArg Then
  373.                     sVal = True
  374.                 Else
  375.                     sVal = False
  376.                 End If
  377.             Case Else
  378.                 Fail GLR.Localize("parse.bad_elm_type")
  379.         End Select
  380.  
  381.         'Null for sVal indicates that the value was not accepted.
  382.         If Not(IsNull(sVal)) Then
  383.             m_Val = sVal
  384.             ParsePrivate = True
  385.             m_bSet = True
  386.         Else
  387.             ParsePrivate = False
  388.         End If
  389.     End Function
  390.  
  391.     Public function PubName()
  392.         PubName = m_sName
  393.     End function 
  394.  
  395.     Public Function DisplayName()
  396.         select case m_nParamType
  397.             Case kPARAM_FREE
  398.                 DisplayName = m_sName
  399.             Case Else
  400.                 DisplayName = "-" & m_sName
  401.         End Select
  402.     End Function
  403.  
  404.     Public function Synonyms()
  405.         Synonyms = m_aShortNames
  406.     End function
  407.  
  408.     Public function IsRequired()
  409.         IsRequired = m_bRequired
  410.     End function
  411.  
  412.     Public function AcceptsArg()
  413.         AcceptsArg = m_bArgAccepted
  414.     End function
  415.  
  416.     Public function ParamType()
  417.         ParamType = m_nParamType
  418.     End function
  419.  
  420.     Public function Value()
  421.         Value = m_Val
  422.     End Function
  423.  
  424.     Public Function UsageType()
  425.         UsageType = m_nUsageType
  426.     End Function 
  427.  
  428.     Public Function IsSet()
  429.         IsSet = m_bSet
  430.     End Function
  431. End Class
  432.  
  433. Const kPARAM_SPACES = 12
  434.  
  435. Class BDE_Args
  436.  
  437.     Private m_dArgs,m_,m_dCommands,m_dSynonyms
  438.     Private m_dRequired,m_dAll
  439.     Private m_bCommandFound
  440.     Private m_rContinuationFunction,m_vContinuationArg
  441.     private m_sPreamble,m_sDescription,m_nPreambleIndent
  442.     private m_sShortDescription
  443.     Private m_aExamples
  444.     Private m_sPrologue
  445.     Private m_aArgs
  446.     Private m_aFreeArgs
  447.  
  448. '-Set up the Argument List
  449. '- Fills in the gScriptArgs Object as a dictionary of arguments
  450. '----------------------------'
  451. Public Function ClearCommands
  452.     Dim sElem,i
  453.  
  454.     If Not(IsEmpty(m_dCommands)) Then
  455.         For Each sElem In m_dCommands.Keys()
  456.             m_dAll.remove(sElem)
  457.             For i=0 to UBound(m_aArgs)
  458.                 If m_aArgs(i) = sElem Then
  459.                     m_aArgs(i) = Empty
  460.                 End If
  461.             Next
  462.         Next
  463.     End If 
  464.  
  465.     Set m_dCommands       = Nothing
  466.     m_sShortDescription   = Empty
  467.     Set m_dCommands       = CreateObject("Scripting.Dictionary")
  468.     m_bCommandFound       = True
  469.     m_aExamples           = Array()
  470. End Function
  471.  
  472. Public Sub AddExample(sExample)
  473.     m_aExamples = PushArray(m_aExamples,sExample)
  474. End Sub
  475.  
  476. Private Sub Class_Initialize
  477.     Set m_dArgs         = CreateObject("Scripting.Dictionary")
  478.     Set m_dRequired     = CreateObject("Scripting.Dictionary")
  479.     Set m_dSynonyms     = CreateObject("Scripting.Dictionary")
  480.     Set m_dAll          = CreateObject("Scripting.Dictionary")
  481.     m_rContinuationFunction = Empty
  482.     m_vContinuationArg = Empty
  483.     m_sPreamble = ""
  484.     m_sDescription = GLR.Localize("parse.no_desc")
  485.     m_sPrologue = ""
  486.     m_nPreambleIndent = 4
  487.     m_aArgs = Array()
  488.     m_aFreeArgs = Array()
  489.     m_aExamples = Array()
  490.  
  491.     ClearCommands()
  492. End Sub
  493.  
  494. Public Sub FailUsage(sMsg)
  495.     WScript.StdOut.WriteLine sMsg
  496.     Usage()
  497.     WScript.Quit -1
  498. End Sub 
  499.  
  500.  
  501. 'Set up a function 
  502. Public Sub SetContinuation( rFunction , vArg)
  503.     Set m_rContinuationFunction = rFunction
  504.     m_vContinuationArg          = vArg
  505. End Sub
  506.  
  507. Function GetUnUsedParameterArray()
  508.     Dim aParameters,sArgName,oArg
  509.     aParameters = Array()
  510.  
  511.     For Each sArgName In m_aArgs
  512.         If m_dAll.Exists(sArgName) Then 
  513.  
  514.             Set oArg = m_dAll.Item(sArgName)
  515.             If Not(oArg.IsSet()) Then
  516.  
  517.                 aParameters = PushArray(aParameters,oArg.DisplayName())
  518.             End If
  519.         End If
  520.     Next
  521.  
  522.     GetUnUsedParameterArray = aParameters
  523. End Function
  524.  
  525. Private Sub PrintList(nUsage,sHeader)
  526.     Dim oArg,bMsgPrinted,sArgName
  527.     bMsgPrinted = False
  528.  
  529.     For Each sArgName In m_aArgs
  530.         If m_dAll.Exists(sArgName) Then 
  531.             Set oArg = m_dAll.Item(sArgName)
  532.             If oArg.UsageType() = nUsage Then
  533.  
  534.                 If Not(bMsgPrinted) And Not(IsEmpty(sHeader)) Then
  535.                     WScript.StdOut.WriteLine(sHeader)
  536.                     bMsgPrinted = True
  537.                 End If
  538.  
  539.                 FormatParam oArg.InlineUsage(),oArg.Description()
  540.             End If
  541.         End If
  542.     Next
  543. End Sub
  544.  
  545. Private Sub PrintListShort(nUsage,sHeader)
  546.     Dim oArg,bMsgPrinted,sArgName
  547.     bMsgPrinted = False
  548.  
  549.     For Each sArgName In m_aArgs
  550.         If m_dAll.Exists(sArgName) Then 
  551.             Set oArg = m_dAll.Item(sArgName)
  552.             If oArg.UsageType() = nUsage Then
  553.  
  554.                 If Not(bMsgPrinted) And Not(IsEmpty(sHeader)) Then
  555.                     WScript.StdOut.WriteLine(sHeader)
  556.                     bMsgPrinted = True
  557.                 End If
  558.  
  559.                 FormatParam oArg.InlineUsage(),oArg.ShortDescription
  560.             End If
  561.         End If
  562.     Next
  563. End Sub
  564.  
  565. Public Sub Usage()
  566.     Dim sUsage,oArg,sTemp,nLen
  567.     Dim bCMNprinted,bADVprinted,bSHRprinted,i
  568.     bCMNprinted = False
  569.     bADVprinted = False
  570.     bSHRprinted = False
  571.  
  572.     FormatLine m_nPreambleIndent,VBsprintf(m_sPreamble,Empty)
  573.  
  574.     WScript.Stdout.WriteLine("")
  575.  
  576.     WScript.Stdout.WriteLine GLR.Localize("parse.desc_str")
  577.  
  578.     FormatLine 4,VBsprintf(Space(4) & m_sDescription,Empty)
  579.  
  580.     WScript.StdOut.WriteLine("")
  581.     
  582.     PrintList kUSAGE_CMN, GLR.Localize("parse.short_param")
  583.     PrintList kUSAGE_ADV, Empty
  584.     PrintList kUSAGE_SHR, Empty
  585.  
  586.     If UBound(m_aExamples) > -1 Then
  587.         WScript.StdOut.WriteLine(GLR.Localize("parse.examples"))
  588.         For i = 0 to UBound(m_aExamples)
  589.             WScript.StdOut.WriteLine Space(4) & m_aExamples(i)
  590.         Next
  591.     End If
  592.     
  593.     If Len(m_sPrologue) > 0 Then
  594.         FormatLine 4,m_sPrologue
  595.     End If
  596.     
  597. End Sub
  598.  
  599. Public Property Get ShortDescription
  600.     If IsEmpty(m_sShortDescription) Then
  601.         ShortDescription = m_sDescription
  602.     Else
  603.         ShortDescription = m_sShortDescription
  604.     End If
  605. End Property
  606.  
  607. Public Property Let ShortDescription(sVal)
  608.     m_sShortDescription = sVal
  609. End Property
  610.  
  611. Public Sub ShortUsage()
  612.     Dim sUsage,oArg,sTemp,nLen
  613.     Dim bCMNprinted,bADVprinted,bSHRprinted,i
  614.     bCMNprinted = False
  615.     bADVprinted = False
  616.     bSHRprinted = False
  617.  
  618.     FormatLine m_nPreambleIndent,VBsprintf(m_sPreamble,Empty)
  619.  
  620.     WScript.StdOut.WriteLine("")
  621.  
  622.     WScript.Stdout.WriteLine GLR.Localize("parse.desc_str")
  623.  
  624.     FormatLine 4,VBsprintf(Space(4) & ShortDescription,Empty)
  625.     WScript.StdOut.WriteLine("")
  626.     
  627.     PrintListShort kUSAGE_CMN, GLR.Localize("parse.short_param")
  628.     PrintListShort kUSAGE_ADV, Empty
  629.     PrintListShort kUSAGE_SHR, Empty
  630.  
  631.     If UBound(m_aExamples) > -1 Then
  632.         WScript.StdOut.WriteLine(GLR.Localize("parse.examples"))
  633.         For i = 0 to Min(2,UBound(m_aExamples))
  634.             WScript.StdOut.WriteLine Space(4) & m_aExamples(i)
  635.         Next
  636.     End If
  637.     
  638. End Sub
  639.  
  640. Public Sub SetPrologue(sStr)
  641.     m_sPrologue = sStr
  642. End Sub
  643.  
  644. Public Sub FormatParam(sUsage,sDescription)
  645.     Dim nSpaces : nSpaces = 0
  646.     Dim sOutput
  647.     
  648.     nSpaces = kPARAM_SPACES - Len(sUsage)
  649.     If nSpaces < 1 Then
  650.         WScript.StdOut.WriteLine(Space(4) & sUsage)
  651.         nSpaces = kPARAM_SPACES + 4
  652.         sOutput = Space(nSpaces) & sDescription
  653.     Else
  654.         sOutput = Space(4) & sUsage & Space(nSpaces) & sDescription
  655.     End If
  656.     
  657.     FormatLine kPARAM_SPACES+4,sOutput
  658. End Sub
  659.  
  660. Public Function IsSeparatorChar(ch)
  661.     Select Case ch
  662.         Case ","
  663.             IsSeparatorChar = True
  664.         Case " "
  665.             IsSeparatorChar = True
  666.         Case "."
  667.             IsSeparatorChar = True
  668.     End Select
  669. End Function
  670.  
  671. Public Sub FormatLine(nSpaces,sLines)
  672.     Dim nLen,nOutputSpaces,aLines,sTemp
  673.     aLines = Split(sLines,vbCrLf)
  674.  
  675.     If nSpaces > kLINE_WRAP Then
  676.         Fail VBsprintf(GLR.Localize("formatline_error"),Array(nSpaces))
  677.     End If
  678.  
  679.     For Each sTemp In aLines
  680.  
  681.         nOutputSpaces = 0
  682.  
  683.         While Len(sTemp)> kLINE_WRAP - nOutputSpaces
  684.             nLen = kLINE_WRAP - nOutputSpaces
  685.             While nLen > 1 And Not( IsSeparatorChar(Mid(sTemp,nLen,1)) )
  686.                 nLen = nLen -1
  687.             Wend
  688.             If nLen = 1 Then
  689.                 nLen = kLINE_WRAP - nOutputSpaces
  690.             End if
  691.             WScript.StdOut.WriteLine(Space(nOutputSpaces) & Left(sTemp,nLen))
  692.             sTemp = Right(sTemp,Len(sTemp)-nLen)
  693.  
  694.             sTemp = LTrim(sTemp)
  695.             nOutputSpaces = nSpaces
  696.         Wend
  697.     
  698.         WScript.StdOut.WriteLine(Space(nOutputSpaces) & sTemp)
  699.  
  700.     Next
  701. End Sub
  702.  
  703. Public Sub SetPreamble(nSpaces,sStr)
  704.     m_sPreamble = sStr
  705.     m_nPreambleIndent = nSpaces
  706. End Sub 
  707.  
  708. Public Sub SetDescription(sStr)
  709.     m_sDescription = sStr
  710. End Sub
  711.  
  712. Function AddParam(oBdeArg)
  713.     Dim sSynonym
  714.  
  715.     Select Case oBdeArg.ParamType()
  716.         Case kPARAM_CMD
  717.             m_dCommands.Add oBdeArg.PubName(), oBdeArg
  718.             m_bCommandFound = False
  719.         Case kPARAM_PRM
  720.             m_dArgs.Add    oBdeArg.PubName(), oBdeArg
  721.         Case kPARAM_FREE
  722.             ReDim Preserve m_aFreeArgs(UBound(m_aFreeArgs)+1)
  723.             Set m_aFreeArgs(UBound(m_aFreeArgs)) = oBdeArg
  724.         Case Else
  725.     End select
  726.  
  727.     For Each sSynonym In oBdeArg.Synonyms()
  728.         m_dSynonyms.Add sSynonym, oBdeArg.PubName()
  729.     Next
  730.     
  731.     ReDim Preserve m_aArgs(UBound(m_aArgs)+1)
  732.     m_aArgs(UBound(m_aArgs)) = oBdeArg.PubName()
  733.  
  734.     If oBdeArg.IsRequired() Then
  735.         m_dRequired.Add oBdeArg.PubName(), oBdeArg.PubName()
  736.     End If
  737.  
  738.     m_dAll.Add oBdeArg.PubName(), oBdeArg
  739.  
  740. End Function
  741.  
  742. Function GetArg(sKey)
  743.     sKey = TranslateSynonym(sKey)
  744.     If Not m_dAll.Exists(sKey) Then
  745.         WScript.StdOut.WriteLine("Key does not exist" & sKey)
  746.     End If
  747.     GetArg = m_dAll.Item(sKey).Value()
  748. End Function
  749.  
  750. '--- Set an argument value explicitly ---'
  751. Function SetArg(sKey,Value)
  752.     sKey = TranslateSynonym(sKey)
  753.     m_dAll.Item(sKey).Parse(Value)
  754. End Function
  755.  
  756. Public Function IsSet(sKey)
  757.     sKey = TranslateSynonym(sKey)
  758.     If Not m_dAll.Exists(sKey) Then
  759.         WScript.StdOut.WriteLine("Key does not exist" & sKey)
  760.     End If
  761.     IsSet = m_dAll.Item(sKey).IsSet()
  762. End Function
  763.  
  764. Private Function TranslateSynonym(sName)
  765.     sName = LCase(sName)
  766.     If m_dSynonyms.Exists(sName) Then
  767.         TranslateSynonym = m_dSynonyms.Item(sName)
  768.     Else
  769.         TranslateSynonym = sName
  770.     End If
  771. End Function
  772.  
  773. 'If an argument is required, calling this function
  774. 'Will mark it as having been used and not cause
  775. Private Function RemoveRequired(sArg)
  776.     If m_dRequired.Exists(sArg) Then
  777.         m_dRequired.Remove(sArg)
  778.     End If
  779. End Function
  780.  
  781. Private Function FindFreeArgNoFail(sArg)
  782.     FindFreeArgNoFail = FindFreeArgFlag(sArg,False)
  783. End Function
  784.  
  785. Private Function FindFreeArg(sArg)
  786.     FindFreeArg = FindFreeArgFlag(sArg,True)
  787. End Function
  788.  
  789. 'Search the list of free arguments.
  790. 'Find the first one that successfully parses the argument
  791. Private Function FindFreeArgFlag(sArg,tDoFail)
  792.     Dim i,tArgParsed
  793.  
  794.     tArgParsed = False
  795.  
  796.     For i = 0 To UBound(m_aFreeArgs)
  797.         If Not(IsEmpty(m_aFreeArgs(i))) Then
  798.             If m_aFreeArgs(i).ParseNoFail(sArg) Then
  799.                 tArgParsed = True
  800.                 RemoveRequired(m_aFreeArgs(i).PubName())
  801.                 m_aFreeArgs(i) = Empty
  802.             End If
  803.         End If
  804.     Next
  805.  
  806.     If Not(tArgParsed) and tDoFail Then
  807.         InvalidSyntax(sArg)
  808.     End If
  809.  
  810.     FindFreeArgFlag = tArgParsed
  811. End Function
  812.  
  813. Function ParseArgs()
  814.     Dim iArg,sArg,sArgVal,bNextArg,sArgRef
  815.     Dim fFun,sVal,oArgRef
  816.     Dim ParseResult
  817.  
  818.     bNextArg = False
  819.     oArgRef = Empty
  820.  
  821.     '---------Main body of argument parsing
  822.     For iArg = 0 To WScript.Arguments.Count - 1
  823.         sArg = WScript.Arguments(iArg)
  824.  
  825.         '-Command switch with - in front of it
  826.         If Left(sArg,2) = "/?" Then
  827.             DoHelp(Empty)
  828.  
  829.         ElseIf Left(sArg,1) = "-" Then
  830.  
  831.             If bNextArg Then
  832.                 oArgRef.Parse(Empty)
  833.                 bNextArg = False
  834.             End If
  835.  
  836.             '--- All arguments case insensitive
  837.             sArg = Right(LCase(sArg),Len(sArg)-1)
  838.             sArg = TranslateSynonym(sArg)
  839.  
  840.             '----- Case #1 ----------'
  841.             'Argument is -switch
  842.             If m_dArgs.Exists(sArg) Then
  843.                 
  844.                 Set oArgRef = m_dArgs.Item(sArg)
  845.  
  846.                 If oArgRef.AcceptsArg() Then
  847.                     bNextArg = True
  848.                 Else
  849.                     oArgRef.Parse(True)
  850.                 End If
  851.                 
  852.                 RemoveRequired(sArg)
  853.  
  854.             '-----This is a command of some sort ----'
  855.             ElseIf m_dCommands.Exists( sArg ) Then 
  856.     
  857.                 If m_bCommandFound Then
  858.                     InvalidSyntax(WScript.Arguments(iArg))
  859.                 End If
  860.  
  861.                 m_bCommandFound = True
  862.                 Set oArgRef = m_dCommands.Item(sArg)
  863.  
  864.                 If oArgRef.AcceptsArg() Then
  865.                     bNextArg = True
  866.                 Else
  867.                     oArgRef.Parse(True)
  868.                 End If
  869.             Else
  870.                 InvalidSyntax(WScript.Arguments(iArg))
  871.             End if
  872.         
  873.         '--- End if for -arg -----'
  874.         ElseIf bNextArg Then
  875.             bNextArg = False
  876.             '- If it wasn't accepted (or errored on) then
  877.             '- We fail and have to pass it on to parse it as
  878.             '- a non-named argument
  879.             If Not(oArgRef.ParseNoFail(sArg)) Then
  880.                 If Not( FindFreeArgNoFail(sArg) ) Then
  881.                     'A free argument couldn't be found, parse it with failure.
  882.                     oArgRef.Parse(sArg)
  883.                 Else
  884.                     'Parse the previous parameter as empty
  885.                     oArgRef.Parse(Empty)
  886.                 End If
  887.             End If
  888.         Else
  889.  
  890.             '-------- Default Case-------'
  891.             FindFreeArg sArg
  892.         End If
  893.     Next
  894.  
  895.     If iArg = 0 Then
  896.         DoHelp(Empty)
  897.     End If 
  898.  
  899.     '-----If there is a command which can be used, one of them must be used-----'
  900.     If Not m_bCommandFound Then
  901.         Fail( Vbsprintf(GLR.Localize("parse.req_param"),empty))
  902.         WScript.Quit -1
  903.     End If
  904.     
  905.     '-----An argument wants a value, but none was supplied-----'
  906.     If bNextArg And oArgRef.AcceptsArg() Then
  907.         oArgRef.Parse(Empty)
  908.     End If
  909.  
  910.     '-----Ensure that each required argument was passed------'
  911.     For Each sArg In m_dRequired.Items
  912.         Fail( VBsprintf(GLR.Localize("parse.isrequired"),Array(m_dAll.Item(sArg).DisplayName())))
  913.     Next
  914.     
  915.     If Not(IsEmpty(m_rContinuationFunction)) Then
  916.         Call (m_rContinuationFunction) (m_vContinuationArg)
  917.     End If
  918. End Function
  919.  
  920. End Class
  921.  
  922. Dim BdeArgs
  923. Set BdeArgs = new BDE_Args
  924.  
  925. Function DoHelp(arg)
  926.     BdeArgs.ShortUsage()
  927.     WScript.Quit 0
  928. End Function
  929.  
  930. Function DoLongHelp(arg)
  931.     BdeArgs.Usage()
  932.     WScript.Quit 0
  933. End Function
  934.  
  935. Function ParseComputerName(oParseObj)
  936.     WScript.StdOut.WriteLine VBSprintf(GLR.Localize("parse.computer_display"),oParseObj.Argument)
  937.  
  938.     ParseComputerName = oParseObj.Argument
  939. End Function
  940.  
  941. Dim oHelp,oComputer,oLongHelp
  942. Set oHelp = new BdeArgElem
  943. Set oComputer = new BdeArgElem
  944. Set oLongHelp = new BdeArgElem
  945. oHelp.Init          kPARAM_PRM, "?"          , ""  , kARG_FUNC,GetRef("DoHelp")             , Empty, False, False
  946. oLongHelp.Init      kPARAM_PRM, "h"          , "help"  , kARG_FUNC,GetRef("DoLongHelp")      , Empty, False, False
  947. oComputer.Init      kPARAM_PRM, "computername"  , "cn"   , kARG_FUNC ,GetRef("ParseComputerName") , "."  , False, True
  948. oHelp.SetUsage      kUSAGE_SHR, "-? or /?"    , GLR.Localize("parse.help_usage")
  949. oLongHelp.SetUsage  kUSAGE_SHR, "-Help or -h"       , GLR.Localize("parse.longhelp_usage")
  950. oComputer.SetUsage  kUSAGE_SHR, "-ComputerName or -cn", GLR.Localize("parse.comp_usage")
  951.  
  952. BdeArgs.AddParam oComputer
  953. BdeArgs.AddParam oHelp
  954. BdeArgs.AddParam oLongHelp
  955. </script>
  956.  
  957. <!------------------------------------------------------>
  958. <!-------- BDE Common     ------------------------------>
  959. <!------------------------------------------------------>
  960.  
  961.  
  962. <script language="VBScript" id="bde-common">
  963. Option Explicit
  964. '--- Need a separate language localizer for this included script ---'
  965. Dim gComGLR
  966. Set gComGLR = new LanguageResourcer
  967. gComGLR.Initialize WScript.ScriptName,"common"
  968.  
  969.  
  970. 'Constants
  971. '--------------'
  972. Const skComputerName_Default = "."
  973. Const skSecurityPath = "/Security/MicrosoftVolumeEncryption"
  974. Const skTpmPath      = "/Security/MicrosoftTpm"
  975.                               
  976.  
  977. 'Common Objects
  978. '--------------'
  979. Dim objWMIServiceSecurity
  980. Dim objWMIService
  981. Dim g_sConnectionString
  982. '---------------------------'
  983.  
  984. Function PushArray( aArr, vVal)
  985.     ReDim Preserve aArr(UBound(aArr)+1)
  986.     aArr(UBound(aArr)) = vVal
  987.     PushArray = aArr
  988. End Function
  989.  
  990. Function Min(nVal1,nVal2)
  991.     If nVal1 < nVal2 Then
  992.         Min = nVal1
  993.     Else
  994.         Min = nVal2
  995.     End If
  996. End Function
  997.  
  998. 'CheckRC
  999. '- Check Return Value=0
  1000. '- Fail otherwise
  1001. '--------------------'
  1002. Function CheckRC( nRC , sMsg)
  1003.     Dim sErrDesc
  1004.     If Not ( nRC = 0 ) Then
  1005.         On Error Resume Next
  1006.         Err.Raise nRC
  1007.         sErrDesc = Err.description
  1008.         Err.Clear()
  1009.         On Error GoTo 0
  1010.  
  1011.         FailCode VBsprintf(gComGLR.Localize("checkrc_msg"),Array(sMsg,nRC,sErrDesc)), nRC
  1012.     End If
  1013. End Function
  1014.  
  1015. 'CheckEmpty
  1016. '- Ensure that the object isn't Empty or null
  1017. '- Fail and exit function if it is
  1018. '---------------------'
  1019. Function CheckEmpty( oObj, sMsg)
  1020.     If IsEmpty(oObj) Or IsNull(oObj) Then
  1021.         Fail( sMsg )
  1022.     End If
  1023.     Set CheckEmpty = oObj
  1024. End Function
  1025.  
  1026.  
  1027. 'CheckArg
  1028. '- Ensure that the argument exists
  1029. '- Fail if it doesn't.
  1030. Function CheckArg( sArgName, sMsg )
  1031.     Dim ArgVal
  1032.     ArgVal = gScriptArgs(sArgName)
  1033.  
  1034.     If IsNull(ArgVal) Or IsEmpty(ArgVal)  Then
  1035.         Fail(sMsg & VBCRlf & gComGLR.Localize("help_message"))
  1036.     End If
  1037.     
  1038.     CheckArg = ArgVal
  1039. End Function
  1040.  
  1041. 'Finish - Exit the Script with a message (but not an error)'
  1042. Function Finish( sMsg )
  1043.     BdeArgs.FormatLine 0,sMsg
  1044.     WScript.Quit 0
  1045. End Function
  1046.  
  1047. Function Fail (sMsg)
  1048.     FailCode sMsg, -1
  1049. End Function
  1050.  
  1051. 'Fail - Exit the Script with a message.
  1052. Function FailCode( sMsg , nExitCode)
  1053.     sMsg = GLR.Localize("error_str") & sMsg
  1054.     BdeArgs.FormatLine 0,sMsg
  1055.     WScript.Quit nExitCode
  1056. End Function
  1057.  
  1058. Function InvalidSyntax(sArg)
  1059.     Dim aParameters
  1060.     aParameters = BdeArgs.GetUnUsedParameterArray()
  1061.  
  1062.     BdeArgs.FormatLine 4, VBsprintf(gComGLR.Localize("err_syntax"),_
  1063.                                       Array(sArg,Join(aParameters,", ") ) _
  1064.                                       )
  1065.     WScript.Quit -1
  1066. End Function
  1067.  
  1068. Function CheckErr()
  1069.     If Err.Number Then
  1070.         WScript.StdOut.WriteLine "------------------------------------------------------------"
  1071.         WScript.StdOut.WriteLine VBsprintf(GLR.Localize("checkerr_str"),_
  1072.                                  Array(Err.Number,Err.Description))
  1073.         WScript.StdOut.WriteLine "------------------------------------------------------------"
  1074.  
  1075.         Wscript.Quit -1
  1076.     End If
  1077. End Function
  1078.  
  1079. 'Do Common Startup options for an BDE Script
  1080. Function BdeCommonStartup()
  1081.     g_sConnectionString = "winmgmts:{impersonationLevel=impersonate" & _
  1082.                           ",authenticationLevel=pktPrivacy}!//"& _
  1083.                           BdeArgs.GetArg("computername") & "/root/cimv2"
  1084.  
  1085.     On Error Resume Next
  1086.     Set objWMIServiceSecurity = GetObject(g_sConnectionString & skSecurityPath)
  1087.     Set objWMIService = GetObject(g_sConnectionString)
  1088.  
  1089.     On Error GoTo 0
  1090.  
  1091.     CheckEmpty objWMIServiceSecurity, gComGLR.Localize("WBEM_error")
  1092.     CheckEmpty objWMIService, gComGLR.Localize("WMI_Error")
  1093. End Function
  1094.  
  1095.  
  1096. 'Check to ensure that the TPM is available for protection
  1097. Function BdeCommonCheckTpmCapability()
  1098.     Dim aTPMs,tEnabled,tOwned,rc
  1099.     Dim oTPM,bTpmOkay,bActivated,bSrkCompat
  1100.  
  1101.     bTpmOkay = False
  1102.     Set aTPMs = GetWMIObject(skTpmPath & ":Win32_Tpm").Instances_
  1103.     CheckErr()
  1104.  
  1105.  
  1106.     '----WARNING: this code really assumed you have one TPM which is
  1107.     '---- owned and capable of being used with the OS volume
  1108.     '---- this likely won't work for more than one TPM.
  1109.  
  1110.     For Each oTPM In aTPMs
  1111.         CheckRC oTPM.IsEnabled( tEnabled ) ,_
  1112.                       gComGLR.Localize("check_enable_fail")
  1113.  
  1114.         '-- Each consecutive check requires that the previous one didn't fail --'
  1115.         If tEnabled Then
  1116.             CheckRC oTPM.IsOwned( tOwned   ) ,_
  1117.                     gComGLR.Localize("check_owner_fail")
  1118.  
  1119.             If tOwned Then 
  1120.                 CheckRC oTPM.IsActivated( bActivated ) ,_
  1121.                         gComGLR.Localize("check_active_fail")
  1122.  
  1123.                 If bActivated Then
  1124.                     CheckRC oTPM.IsSrkAuthCompatible( bSrkCompat ) ,_
  1125.                             gComGLR.Localize("check_srk_fail")
  1126.  
  1127.                     If bSrkCompat Then
  1128.                         bTpmOkay = True
  1129.                     Else
  1130.                         Fail VBsprintf(gComGLR.Localize("tpm_notcompat"),empty)
  1131.                     End If
  1132.                 Else
  1133.                     Fail VBsprintf(gComGLR.Localize("tpm_notactivated"),empty)
  1134.                 End If
  1135.  
  1136.             Else
  1137.  
  1138.                 Fail VBsprintf(gComGLR.Localize("tpm_notowned"),empty)
  1139.  
  1140.             End If
  1141.  
  1142.         Else
  1143.  
  1144.             Fail VBsprintf(gComGLR.Localize("tpm_notenabled"),empty)
  1145.  
  1146.         End If
  1147.     Next
  1148.  
  1149.     BdeCommonCheckTpmCapability = bTpmOkay
  1150.  
  1151. End Function 
  1152.  
  1153. const HKEY_LOCAL_MACHINE = &H80000002
  1154.  
  1155. Function BdeCommonIsFipsEnabled()
  1156.     Dim sConnectionStr,oReg,sKeyPath,sValueName,nValue,rc
  1157.     
  1158.     sConnectionStr = "winmgmts:{impersonationLevel=impersonate" & _
  1159.                      ",authenticationLevel=pktPrivacy}!//"& _
  1160.                      BdeArgs.GetArg("computername") & "\root\default:StdRegProv"
  1161.     
  1162.     On Error Resume Next
  1163.     Set oReg = GetObject(sConnectionStr)
  1164.     On Error Goto 0
  1165.  
  1166.     'We were unable to connect to the registry, warn, and then return false
  1167.     If IsNull(oReg) Then
  1168.         WScript.Stdout.WriteLine gComGLR.Localize("no_registry_warning")
  1169.         BdeCommonIsFipsEnabled = False
  1170.     End If
  1171.  
  1172.     sKeyPath = "System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy"
  1173.     sValueName = "Enabled"
  1174.     rc = oReg.GetDWORDValue(HKEY_LOCAL_MACHINE,sKeyPath,sValueName,nValue)
  1175.     If rc <> 0 Then
  1176.         sKeyPath = "System\CurrentControlSet\Control\Lsa"
  1177.         sValueName = "fipsalgorithmpolicy"
  1178.         oReg.GetDWORDValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,nValue
  1179.     End If
  1180.  
  1181.     If IsEmpty(nValue) Or nValue = 0 Then
  1182.         BdeCommonIsFipsEnabled = False
  1183.     Else
  1184.         BdeCommonIsFipsEnabled = True
  1185.     End If
  1186.  
  1187. End Function
  1188.  
  1189. Function BdePolicyAllowsPassword()
  1190.     BdePolicyAllowsPassword = Not BdeCommonIsFipsEnabled()
  1191. End Function
  1192.  
  1193. 'Get an Object that's a subset of WIM
  1194. Function GetWMIObject( sPath)
  1195.     Set GetWMIObject = GetObject(g_sConnectionString & sPath)
  1196. End Function
  1197.  
  1198. 'Get The Encryptable Volume object from a physical volume
  1199. Function GetEncryptableFromPhysical( oPhysVolume )
  1200.     Dim oEncVolume,oTemp,aEncVolumes
  1201.     oEncVolume = null
  1202.  
  1203.     Set oEncVolume = GetObject(g_sConnectionString & skSecurityPath & ":Win32_EncryptableVolume='"&oPhysVolume.DeviceID & "'")
  1204.  
  1205.     If IsNull(oEncVolume) Then
  1206.         Fail(gComGLR.Localize("notencryptable"))
  1207.     End If
  1208.  
  1209.     Set GetEncryptableFromPhysical = oEncVolume
  1210.  
  1211. End Function
  1212.  
  1213. 'Get The Encryptable Volume object from a physical volume
  1214. Function GetPhysicalFromEncryptable( oEncVolume )
  1215.     Dim oPhysVolume,oTemp,aPhysVolumes
  1216.  
  1217.     Set oPhysVolume = GetObject(g_sConnectionString  & ":Win32_Volume='" & oEncVolume.DeviceID & "'")
  1218.     CheckErr()
  1219.  
  1220.     Set GetPhysicalFromEncryptable = oPhysVolume
  1221.  
  1222. End Function
  1223.  
  1224. '
  1225. ' Determines which program is being used to run this script.
  1226. ' Returns True if the script host is cscript.exe
  1227. '
  1228. function IsHostCscript()
  1229.     On Error Resume Next
  1230.  
  1231.     Dim sFullName
  1232.     Dim sCommand
  1233.     Dim i, j
  1234.     Dim bReturn
  1235.  
  1236.     bReturn = False
  1237.     sFullName = WScript.FullName
  1238.  
  1239.     i = InStr(1, sFullName, ".exe", 1)
  1240.  
  1241.     If i <> 0 Then
  1242.         j = InStrRev(sFullName, "\", i, 1)
  1243.         If j <> 0 Then
  1244.             sCommand = Mid(sFullName, j+1, i-j-1)
  1245.             If LCase(sCommand) = "cscript" Then
  1246.                 bReturn = True
  1247.             End If
  1248.         End If
  1249.     End If
  1250.  
  1251.     If Err <> 0 Then
  1252.         WScript.Echo VBsprintf(gComGLR.Localize("cscript_detect_error"),Array(Err.Number,Err.Description))
  1253.         WScript.Quit -1
  1254.     End If
  1255.     
  1256.     On Error GoTo 0
  1257.     IsHostCscript = bReturn
  1258. End Function
  1259.  
  1260. Class ArrayLookup
  1261.     Private m_aArray
  1262.  
  1263.     Sub Class_Initialize()
  1264.         m_aArray = Array()
  1265.     End Sub
  1266.  
  1267.     Public Function SetArray(vArg)
  1268.         if( isArray(vArg) ) Then
  1269.             m_aArray = vArg
  1270.         Else
  1271.             m_aArray = Array(vArg)
  1272.         End If
  1273.     End Function
  1274.  
  1275.     Public function Lookup(num,format)
  1276.         Dim sMsg
  1277.         num = num -1
  1278.  
  1279.         If Not(format = "%" Or format="v") And _
  1280.             num < LBound(m_aArray) Or num > UBound(m_aArray) Then
  1281.             Fail num & " Is out of bounds"
  1282.         End If
  1283.  
  1284.         Select Case format
  1285.             Case "x"
  1286.                 sMsg = sMsg & "0x" & Hex(m_aArray(num))
  1287.             Case "i"
  1288.                 sMsg = sMsg & Int(m_aArray(num))
  1289.             Case "s"
  1290.                 sMsg = m_aArray(num)
  1291.             Case "f"
  1292.                 sMsg = sMsg & CDbl(m_aArray(num))
  1293.             Case "v"
  1294.                 '--- special argument for the volumeletter --'
  1295.                 sMsg = sMsg & BdeArgs.GetArg("v")
  1296.             Case "%"
  1297.                 sMsg = sMsg & "%"
  1298.             Case Else
  1299.                 sMsg = sMsg & m_aArray(num)
  1300.         End Select
  1301.  
  1302.         Lookup = sMsg
  1303.     End Function
  1304.  
  1305. End Class
  1306.  
  1307. Function Vbsprintf(sFmt, aOutputs)
  1308.     Dim oLookup
  1309.     Set oLookup = new ArrayLookup
  1310.     oLookup.SetArray(aOutputs)
  1311.     Vbsprintf = VBsprintfLookup(sFmt,oLookup)
  1312. End Function
  1313.  
  1314. Dim gFormatRegExp
  1315. Set gFormatRegExp = new RegExp
  1316. gFormatRegExp.Pattern = "%[%0-9](![a-z]+!)?"
  1317. gFormatRegExp.Global = True
  1318.  
  1319. '--- oLookupObj must support Lookup(arg) and return a value ---'
  1320. Function VBsprintfLookup( sFmt, oLookupObj)
  1321.     Dim iFmt
  1322.     Dim iOutput,aMatches,oMatch,sType,iMatchIndex
  1323.     Dim sMsg,sInsert
  1324.     iFmt = 1
  1325.     iOutput = 0
  1326.     sMsg = ""
  1327.  
  1328.     Set aMatches = gFormatRegExp.Execute(sFmt)
  1329.  
  1330.     if aMatches.Count > 0 Then
  1331.         For Each oMatch In aMatches
  1332.  
  1333.             iOutput = Mid(oMatch.Value,2,1)
  1334.  
  1335.             If iOutput = "%" Then
  1336.                 sInsert = "%"
  1337.             Else
  1338.  
  1339.                 If Len(oMatch.Value) > 4 Then
  1340.                     sType = Mid(oMatch.Value,4,Len(oMatch.Value)-4)
  1341.                 Else
  1342.                     sType = "s"
  1343.                 End If
  1344.  
  1345.                 sInsert = oLookupObj.Lookup(iOutput,sType)
  1346.             End If
  1347.  
  1348.             iMatchIndex = oMatch.FirstIndex+1
  1349.  
  1350.             If iFmt < iMatchIndex Then
  1351.                 sMsg = sMsg & Mid(sFmt,iFmt,iMatchIndex - iFmt)
  1352.             End If
  1353.             sMsg = sMsg & sInsert
  1354.  
  1355.             iFmt = iMatchIndex + Len(oMatch.Value)
  1356.         Next
  1357.     End If
  1358.  
  1359.     If Len(sFmt)+1 > iFmt Then
  1360.         sMsg = sMsg & Mid(sFmt,iFmt,Len(sFmt)+1 - iFmt)
  1361.     End If
  1362.  
  1363.     sFmt = Empty
  1364.     VBsprintfLookup = sMsg
  1365. End Function
  1366.  
  1367. '----------------------'
  1368. '- Arrays and functions to get and translate status information '
  1369. ''''''''''''''''''''''
  1370. Function ArrayStatusToString(aArray,nStatusIndex)
  1371.     If nStatusIndex <0 Or nStatusIndex > UBound(aArray) Then
  1372.         ArrayStatusToString = gComGLR.Localize("Unknown")
  1373.     Else 
  1374.         ArrayStatusToString = aArray(nStatusIndex)
  1375.     End If 
  1376. End Function
  1377.  
  1378. Const kBDE_CONVERSION_STATUS_UNKNOWN    = -1
  1379. Const kBDE_CONVERSION_STATUS_DECRYPTED  = 0
  1380. Const kBDE_CONVERSION_STATUS_ENCRYPTED  = 1
  1381. Const kBDE_CONVERSION_STATUS_ENCRYPTING = 2
  1382. Const kBDE_CONVERSION_STATUS_DECRYPTING = 3
  1383. Const kBDE_CONVERSION_STATUS_ENCPAUSED  = 4
  1384. Const kBDE_CONVERSION_STATUS_DECPAUSED  = 5
  1385.  
  1386. 'Conversion Status Translation
  1387. Dim aConversionStatusToString
  1388. aConversionStatusToString = Array( _
  1389.     gComGLR.Localize("convstatus0"),_
  1390.     gComGLR.Localize("convstatus1"),_
  1391.     gComGLR.Localize("convstatus2"),_
  1392.     gComGLR.Localize("convstatus3"),_
  1393.     gComGLR.Localize("convstatus4"),_
  1394.     gComGLR.Localize("convstatus5")_
  1395. )
  1396. Function ConversionStatusToString(nConversionStatus)
  1397.     ConversionStatusToString = ArrayStatusToString(aConversionStatusToString,_
  1398.                                                    nConversionStatus)
  1399. End Function
  1400.  
  1401. Const kBDE_LOCK_STATUS_UNLOCKED = 0
  1402. Const kBDE_LOCK_STATUS_LOCKED   = 1
  1403. ''''''''''''''''''''''
  1404. 'Lock Status Translation
  1405. Dim aLockStatusToString
  1406. aLockStatusToString = Array( _
  1407.     gComGLR.Localize("lockstatus0"),_
  1408.     gComGLR.Localize("lockstatus1")_
  1409. )
  1410. Function LockStatusToString(nLockStatus)
  1411.     LockStatusToString = ArrayStatusToString(aLockStatusToString,_
  1412.                                                    nLockStatus)
  1413. End Function
  1414.  
  1415. Const kBDE_PROTECTION_STATUS_OFF = 0
  1416. Const kBDE_PROTECTION_STATUS_ON  = 1
  1417. ''''''''''''''''''''''
  1418. 'Protection Status Translation
  1419. Dim aProtectionStatusToString
  1420. aProtectionStatusToString = Array( _
  1421.     gComGLR.Localize("protstatus0"),_
  1422.     gComGLR.Localize("protstatus1")_
  1423. )
  1424. Function ProtectionStatusToString(nProtectionStatus)
  1425.     ProtectionStatusToString = ArrayStatusToString(aProtectionStatusToString,_
  1426.                                                    nProtectionStatus)
  1427. End Function
  1428.  
  1429.  
  1430. Const kBDE_ENCRYPTION_NONE            = 0
  1431. Const kBDE_ENCRYPTION_AES128_DIFFUSER = 1
  1432. Const kBDE_ENCRYPTION_AES256_DIFFUSER = 2
  1433. Const kBDE_ENCRYPTION_AES128          = 3
  1434. Const kBDE_ENCRYPTION_AES256          = 4
  1435. ''''''''''''''''''''''
  1436. 'Protection Status Translation
  1437. Dim aEncryptionMethodToString
  1438. aEncryptionMethodToString = Array( _
  1439.     gComGLR.Localize("encstatus0"),_
  1440.     gComGLR.Localize("encstatus1"),_
  1441.     gComGLR.Localize("encstatus2"),_
  1442.     gComGLR.Localize("encstatus3"),_
  1443.     gComGLR.Localize("encstatus4")_
  1444. )
  1445. Function EncryptionMethodToString(nEncryptionMethod)
  1446.     EncryptionMethodToString = ArrayStatusToString(aEncryptionMethodToString,_
  1447.                                                    nEncryptionMethod)
  1448.  
  1449. End Function
  1450.  
  1451.  
  1452.  
  1453. Const kBDE_PROTECTOR_TYPE_ANY = 0
  1454. Const kBDE_PROTECTOR_TYPE_TPM = 1
  1455. Const kBDE_PROTECTOR_TYPE_KEY = 2
  1456. Const kBDE_PROTECTOR_TYPE_PASSWORD = 3
  1457. Const kBDE_PROTECTOR_TYPE_TPM_PIN = 4
  1458. Const kBDE_PROTECTOR_TYPE_TPM_KEY = 5
  1459. Const kBDE_PROTECTOR_TYPE_TPM_PIN_KEY = 6
  1460. ''''''''''''''''''''''
  1461. 'Protection Status Translation
  1462. Dim aProtectorTypeToString
  1463. aProtectorTypeToString = Array( _
  1464.     gComGLR.Localize("prottype0"),_
  1465.     gComGLR.Localize("prottype1"),_
  1466.     gComGLR.Localize("prottype2"),_
  1467.     gComGLR.Localize("prottype3"),_
  1468.     gComGLR.Localize("prottype4"),_
  1469.     gComGLR.Localize("prottype5"),_
  1470.     gComGLR.Localize("prottype6")_
  1471. )
  1472. Function ProtectorTypeToString(nProtectorType)
  1473.     ProtectorTypeToString = ArrayStatusToString(aProtectorTypeToString,_
  1474.                                                 nProtectorType)
  1475. End Function
  1476.  
  1477. '---- Hardware test status constants ----'
  1478. Const kBDE_HARDWARE_TEST_NONE = 0
  1479. Const kBDE_HARDWARE_TEST_FAILED = 1
  1480. Const kBDE_HARDWARE_TEST_PENDING = 2
  1481.  
  1482.  
  1483.  
  1484. '------ BDE error codes -------'
  1485. Dim kBDE_ERROR_NOT_DATA_VOLUME
  1486. Dim kBDE_ERROR_KEY_REQUIRED
  1487. Dim kBDE_ERROR_RELATIVE_PATH
  1488. Dim kBDE_ERROR_FIPS_POLICY
  1489. Dim kBDE_ERROR_BOOTABLE_CDDVD
  1490.  
  1491. kBDE_ERROR_NOT_DATA_VOLUME = CLng("&H80310019")
  1492. kBDE_ERROR_KEY_REQUIRED    = CLng("&H8031001D")
  1493. kBDE_ERROR_RELATIVE_PATH   = CLng("&H80310032")
  1494. kBDE_ERROR_FIPS_POLICY     = CLng("&H80310037")
  1495. kBDE_ERROR_BOOTABLE_CDDVD  = CLng("&H80310030")
  1496.  
  1497. Const kPHYS_REQ_ENABLE_ACTIVATE = 10
  1498.  
  1499. Const kTPM_TRANSITION_SHUTDOWN = 1
  1500. Const kTPM_TRANSITION_RESTART = 2
  1501.  
  1502. Const kMIN_OWNER_PASSWORD_LENGTH = 8
  1503.  
  1504. </script>
  1505.  
  1506.  
  1507. <script language="VBScript" id="class-library">
  1508. Option Explicit
  1509.  
  1510.  
  1511.  
  1512.  
  1513. '---- Figuring out the OS volume, makes use of this global WMI object --------'
  1514. Dim g_OSobj
  1515. g_OSobj = Empty
  1516.  
  1517. Function GetOSVolume()
  1518.     Dim oOSService,sDriveLetter
  1519.     Dim WshShell,WshSysEnv
  1520.  
  1521.     sDriveLetter = Empty
  1522.  
  1523.     On Error Resume Next
  1524.  
  1525.     If IsEmpty(g_OSobj) Then
  1526.         Set oOSService = GetWMIObject("")
  1527.         Set g_OSobj = oOSService.Get("Win32_OperatingSystem=@")
  1528.     End If
  1529.  
  1530.     If Err.Number = 0 Then
  1531.         sDriveLetter = Left(g_OSobj.WindowsDirectory,2)
  1532.     End If
  1533.  
  1534.     'Resume failing on errors
  1535.     On Error GoTo 0
  1536.  
  1537.     If IsEmpty(sDriveLetter) And BdeArgs.IsSet("cn") Then 
  1538.         Fail GLR.Localize("no_operatingsystem")
  1539.     
  1540.     ElseIf IsEmpty(sDriveLetter) Then
  1541.         Set WshShell = WScript.CreateObject("WScript.Shell")
  1542.         Set WshSysEnv = WshShell.Environment("PROCESS")
  1543.  
  1544.         sDriveLetter = Left(WshSysEnv("SYSTEMDRIVE"),2)
  1545.     End If
  1546.  
  1547.     GetOSVolume = sDriveLetter
  1548. End Function
  1549. '-----------------------'
  1550.  
  1551.  
  1552.  
  1553. Function IsOsVolumeName(sVolName)
  1554.     If GetOsVolume() = sVolName Then
  1555.         IsOsVolumeName = True
  1556.     Else
  1557.         IsOsVolumeName = False
  1558.     End If
  1559. End function
  1560.  
  1561. Function GetEncryptableVolume()
  1562.     Dim aEncVolumes,oEncVolume,oTemp
  1563.  
  1564.     Set aEncVolumes = GetWMIObject(skSecurityPath & ":Win32_EncryptableVolume").Instances_
  1565.  
  1566.     oEncVolume=Empty
  1567.     For Each oTemp In aEncVolumes
  1568.         If( oTemp.DriveLetter = BdeArgs.GetArg("volumeletter") ) Then
  1569.             Set oEncVolume = oTemp
  1570.         End If
  1571.     Next
  1572.  
  1573.     Set oEncVolume = CheckEmpty(oEncVolume,_
  1574.                                  VBsprintf(GLR.Localize("drive_invalid"),_
  1575.                                            Array(BdeArgs.GetArg("volumeletter"))))
  1576.  
  1577.     Set GetEncryptableVolume = oEncVolume
  1578. End Function
  1579.  
  1580. '--- Format using the locale ID, arguments to format
  1581. '--- Come from oVolume, and aArray
  1582. Public Function FormatStr3(sLocID,aArray,oVolume)
  1583.     oVolume.SetFormatArray(aArray)
  1584.     FormatStr3 = VbsprintfLookup(GLR.Localize(sLocID),oVolume)
  1585. End Function
  1586.  
  1587. Public Function FormatStr2(sLocID,aArray)
  1588.     FormatStr2 = Vbsprintf(GLR.Localize(sLocID),aArray)
  1589. End Function
  1590.  
  1591. Public Function FormatStr(sLocID)
  1592.     FormatStr = Vbsprintf(GLR.Localize(sLocID),empty)
  1593. End Function
  1594.  
  1595. Class VolumeObject
  1596.     Private m_oEncVolume
  1597.     Private m_oPhysVolume
  1598.     Private m_aArrayLookup
  1599.  
  1600.     Sub Class_initialize()
  1601.         m_oPhysVolume = Null
  1602.         m_oEncVolume = Null
  1603.     End Sub
  1604.  
  1605.     public Function SetFormatArray(aArray)
  1606.         Set m_aArrayLookup = new ArrayLookup
  1607.         m_aArrayLookup.SetArray(aArray)
  1608.     End Function
  1609.  
  1610.     Public Function WMIObjectReference()
  1611.         Set WMIObjectReference = m_oEncVolume
  1612.     End Function
  1613.  
  1614.  
  1615. '----- VBsprintf needs an object that can do a "lookup" ----
  1616. '----- This function responds to particular control characters ---'
  1617. '----- in the string and will return the appropriate text for the string ----'
  1618.     Public function Lookup(i,ch)
  1619.         Dim sMsg
  1620.  
  1621.         Select Case ch
  1622.             Case "c"
  1623.                 sMsg = ConversionStatusToString(ConversionStatus)
  1624.             Case "z"
  1625.                 sMsg = Capacity
  1626.             Case "v"
  1627.                 sMsg = DriveLetter
  1628.             Case "l"
  1629.                 sMsg = Label
  1630.             Case "%"
  1631.                 sMsg = "%"
  1632.             Case Else
  1633.                 sMsg = m_aArrayLookup.Lookup(i,ch)
  1634.         End Select
  1635.  
  1636.         Lookup = sMsg
  1637.     End Function
  1638.  
  1639. '-------- Constructors --------'
  1640.     Public Function CreateByReference(oEncVolume)
  1641.         Set m_oEncVolume = oEncVolume
  1642.         On Error Resume Next
  1643.             Set m_oPhysVolume = GetPhysicalFromEncryptable(oEncVolume)
  1644.         On Error GoTo 0
  1645.     End Function
  1646.  
  1647.     Public Function CreateByLetter(sDrive)
  1648.         Dim aEncVolumes,oEncVolume,oTemp
  1649.  
  1650.         Set aEncVolumes = GetWMIObject(skSecurityPath & ":Win32_EncryptableVolume").Instances_
  1651.  
  1652.         oEncVolume=Empty
  1653.         For Each oTemp In aEncVolumes
  1654.             If( oTemp.DriveLetter = sDrive ) Then
  1655.                 Set oEncVolume = oTemp
  1656.             End If
  1657.         Next
  1658.  
  1659.  
  1660.         Set oEncVolume = CheckEmpty(oEncVolume,_
  1661.                                  VBsprintf(GLR.Localize("drive_invalid"),_
  1662.                                            Array(sDrive)))
  1663.  
  1664.         CreateByReference(oEncVolume)
  1665.     End Function
  1666.  
  1667. '------------------------------'
  1668.  
  1669. '--------Prints a message telling whether or not this is the OS Volume ------'
  1670. Function PrintOSVolume()
  1671.     If IsOsVolumeName(DriveLetter) Then
  1672.         PrintOSVolume = GLR.Localize("OSVolume")
  1673.     Else
  1674.         PrintOSVolume = GLR.Localize("DataVolume")
  1675.     End If 
  1676. End Function
  1677. '------------------------'
  1678.  
  1679. Function GetPassword(sKeyProtector)
  1680.     Dim sPassword
  1681.  
  1682.     CheckRC m_oEncVolume.GetKeyProtectorNumericalPassword(sKeyProtector,_
  1683.                                                           sPassword),_
  1684.                                    GLR.Localize("getpassword_error")
  1685.     
  1686.     GetPassword = sPassword
  1687. End Function
  1688.  
  1689. Public Property Get HardwareTestStatus
  1690.     Dim nTestStatus,nTestError
  1691.  
  1692.     CheckRC m_oEncVolume.GetHardwareTestStatus(nTestStatus,nTestError),_
  1693.             FormatStr("error_hardware_status")
  1694.  
  1695.     HardwareTestStatus = nTestStatus
  1696. End Property
  1697.  
  1698. Public Property Get HardwareTestError
  1699.     Dim nTestStatus,nTestError
  1700.  
  1701.     CheckRC m_oEncVolume.GetHardwareTestStatus(nTestStatus,nTestError),_
  1702.             FormatStr("error_hardware_status")
  1703.  
  1704.     HardwareTestError = nTestError
  1705. End Property
  1706.  
  1707. Public Function IsHardwareTestPending()
  1708.     if HardwareTestStatus = kBDE_HARDWARE_TEST_PENDING Then
  1709.         IsHardwareTestPending = True
  1710.     Else
  1711.         IsHardwareTestPending = False
  1712.     End If
  1713. End Function
  1714.  
  1715. Public Function IsHardwareTestFailed()
  1716.     if HardwareTestStatus = kBDE_HARDWARE_TEST_FAILED Then
  1717.         IsHardwareTestFailed = True
  1718.     Else
  1719.         IsHardwareTestFailed = False
  1720.     End If
  1721. End Function
  1722.  
  1723. '---- Display/Save a key protector ----'
  1724. Public Function DoKeyProtector(sKeyProtector,sKeyDir)
  1725.     Dim nKeyprotType,sKeyPath,sPassword,rc,sProtID,bIsAutoUnlockEnabled
  1726.     Dim bUnLocked,nLockedStatus
  1727.  
  1728.     nKeyProtType = GetKeyProtectorType(sKeyProtector)
  1729.  
  1730.     bIsAutoUnlockEnabled = IsAutoUnlockEnabled(sProtID)
  1731.     
  1732.     bUnLocked = Not(IsLocked())
  1733.  
  1734.     Select Case nKeyProtType
  1735.         Case kBDE_PROTECTOR_TYPE_KEY
  1736.             CheckRC m_oEncVolume.GetExternalKeyFileName(sKeyProtector,sKeyPath),_
  1737.                     GLR.Localize("Externalkey_error")
  1738.  
  1739.             WScript.StdOut.WriteLine Space(4) & GLR.Localize("recoverykey")
  1740.             WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
  1741.             WScript.StdOut.WriteLine Space(6) & GLR.Localize("keypath_str")
  1742.             WScript.StdOut.WriteLine Space(8) & sKeyPath
  1743.  
  1744.             If bIsAutoUnlockEnabled And sProtID = sKeyProtector Then
  1745.                 WScript.StdOut.WriteLine ""
  1746.                 WScript.StdOut.WriteLine Space(6) & GLR.Localize("autounlock_str")
  1747.             End If
  1748.  
  1749.             If Not(IsEmpty(sKeyDir)) Then
  1750.                 SaveKey sKeyProtector,sKeyDir
  1751.                 WScript.StdOut.WriteLine ""
  1752.                 WScript.StdOut.WriteLine Space(4) & VBSprintf(GLR.Localize("keyprot_saved"),_
  1753.                                                     Array(sKeyDir))
  1754.             End if
  1755.  
  1756.             WScript.StdOut.WriteLine ""
  1757.         Case kBDE_PROTECTOR_TYPE_TPM_KEY
  1758.             CheckRC m_oEncVolume.GetExternalKeyFileName(sKeyProtector,sKeyPath),_
  1759.                     GLR.Localize("Externalkey_error")
  1760.  
  1761.             WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_key")
  1762.             WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
  1763.             WScript.StdOut.WriteLine Space(6) & GLR.Localize("keypath_str")
  1764.             WScript.StdOut.WriteLine Space(8) & sKeyPath
  1765.  
  1766.             If Not(IsEmpty(sKeyDir)) Then
  1767.                 SaveKey sKeyProtector,sKeyDir
  1768.                 WScript.StdOut.WriteLine ""
  1769.                 WScript.StdOut.WriteLine Space(4) & VBSprintf(GLR.Localize("keyprot_saved"),_
  1770.                                                     Array(sKeyDir))
  1771.             End If
  1772.             
  1773.             WScript.StdOut.WriteLine ""
  1774.         Case kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
  1775.             CheckRC m_oEncVolume.GetExternalKeyFileName(sKeyProtector,sKeyPath),_
  1776.                     GLR.Localize("Externalkey_error")
  1777.  
  1778.             WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_pin_key")
  1779.             WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
  1780.             WScript.StdOut.WriteLine Space(6) & GLR.Localize("keypath_str")
  1781.             WScript.StdOut.WriteLine Space(8) & sKeyPath
  1782.  
  1783.             If Not(IsEmpty(sKeyDir)) Then
  1784.                 SaveKey sKeyProtector,sKeyDir
  1785.                 WScript.StdOut.WriteLine ""
  1786.                 WScript.StdOut.WriteLine Space(4) & VBSprintf(GLR.Localize("keyprot_saved"),_
  1787.                                                     Array(sKeyDir))
  1788.             End If
  1789.             
  1790.             WScript.StdOut.WriteLine ""
  1791.         Case kBDE_PROTECTOR_TYPE_TPM
  1792.             WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_only")
  1793.             WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
  1794.             WScript.StdOut.WriteLine ""
  1795.         Case kBDE_PROTECTOR_TYPE_TPM_PIN
  1796.             WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_pin")
  1797.             WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
  1798.             WScript.StdOut.WriteLine ""
  1799.         Case kBDE_PROTECTOR_TYPE_PASSWORD
  1800.  
  1801.             WScript.StdOut.WriteLine Space(4) & GLR.Localize("recoverypassword")
  1802.             WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
  1803.  
  1804.             If bUnLocked Then
  1805.                 WScript.StdOut.WriteLine Space(6) & GLR.Localize("passw_str")
  1806.                 WScript.StdOut.WriteLine Space(8) & GetPassword(sKeyProtector)
  1807.             End If
  1808.  
  1809.             WScript.StdOut.WriteLine ""
  1810.         Case Else
  1811.             Fail GLR.Localize("unknown_prot_type") & nKeyProtType
  1812.     End Select
  1813. End Function
  1814.  
  1815. '---- End display/save ---------'
  1816.  
  1817. '--- Unlock the volume given a key file ----'
  1818. Function UnlockWithKeyFile(sRecoveryFile)
  1819.     Dim aKey(32)
  1820.  
  1821.     CheckRC m_oEncVolume.GetExternalKeyFromFile(sRecoveryFile,_
  1822.                                                   aKey),_
  1823.                 GLR.Localize("getkey_error")
  1824.  
  1825.     CheckRC m_oEncVolume.UnlockWithExternalKey(aKey),_
  1826.                 VBsprintf(GLR.Localize("unlockkey_error"),Array(sRecoveryFile,DriveLetter))
  1827. End Function
  1828.  
  1829. '--- Unlock the volume given raw key bytes ----'
  1830. Function UnlockWithNumericalPassword(sPassword)
  1831.     CheckRC m_oEncVolume.UnlockWithNumericalPassword(sPassword),_
  1832.                 VBsprintf(GLR.Localize("unlockpassw_error"),_
  1833.                           Array(DriveLetter))
  1834. End Function
  1835.  
  1836. '----- Deletes a protector and produces the standard output ----'
  1837. Function DeleteKeyProtector(sKeyProtector)
  1838.     Dim rc,tDisable
  1839.     tDisable = False
  1840.  
  1841.     rc = m_oEncVolume.DeleteKeyProtector(sKeyProtector)
  1842.  
  1843.     If rc = kBDE_ERROR_KEY_REQUIRED Then 
  1844.         DisableKeyProtectors()
  1845.         tDisable = True
  1846.  
  1847.         rc = m_oEncVolume.DeleteKeyProtector(sKeyProtector)
  1848.     End If
  1849.         CheckRC rc, GLR.Localize("deleteKeyProtError")
  1850.         
  1851.     WScript.StdOut.WriteLine VBsprintf(GLR.Localize("force_delete"),_
  1852.                                            Array(sKeyProtector))
  1853.  
  1854.     If tDisable Then
  1855.         WScript.StdOut.WriteLine VBSprintf(GLR.Localize("disabled_warning"),empty)
  1856.     End If
  1857. End Function
  1858.  
  1859. '------ Delete all the key protectors of a particular type ------'
  1860. '------ Doesn't fail if they don't exist ----------'
  1861. Function DeleteKeyProtectorByType(nType)
  1862.     Dim aProtectors,sProtector
  1863.  
  1864.     aProtectors = GetKeyProtectors(nType)
  1865.  
  1866.     For Each sProtector In aProtectors
  1867.         DeleteKeyProtector sProtector
  1868.     Next
  1869. End Function
  1870.  
  1871.  
  1872. '---- Simple properties and wrapped methods ----'
  1873.  
  1874.     Public Property Get DriveLetter
  1875.         DriveLetter = m_oEncVolume.DriveLetter
  1876.     End Property
  1877.  
  1878.     Public Function IsOsVolume()
  1879.         IsOsVolume = IsOsVolumeName(DriveLetter)
  1880.     End Function
  1881.  
  1882.     Public Function IsDataVolume()
  1883.         IsDataVolume = Not(IsOsVolumeName(DriveLetter))
  1884.     End Function
  1885.  
  1886. '---- Tells if it is bound to the OS volume, key prot placed in sProtID ---'
  1887. '---- sProtID is an out parameter ----'
  1888.     Public Function IsAutoUnlockEnabled(sProtID)
  1889.         Dim bIsAutoUnlockEnabled
  1890.  
  1891.         m_oEncVolume.IsAutoUnlockEnabled bIsAutoUnlockEnabled,_
  1892.                                                       sProtID
  1893.  
  1894.         IsAutoUnlockEnabled = bIsAutoUnlockEnabled
  1895.     End Function
  1896.  
  1897. '----- Turn on autounlocking ----'
  1898. Function EnableAutoUnlock()
  1899.     Dim sKeyProt
  1900.  
  1901.     sKeyProt = AddExternalKey()
  1902.     CheckRC m_oEncVolume.EnableAutoUnlock(sKeyProt),_
  1903.                 GLR.Localize("autolock_error")
  1904.  
  1905.     EnableAutoUnlock = sKeyProt
  1906. End Function
  1907.  
  1908. '----- Turn on autounlocking ----'
  1909. Function DisableAutoUnlock()
  1910.     CheckRC m_oEncVolume.DisableAutoUnlock(),_
  1911.                     GLR.Localize("disableautounlockerror")
  1912. End Function
  1913.  
  1914. '----- Clear all the autounlock keys------'
  1915. Function ClearAllAutoUnlockKeys()
  1916.     CheckRC m_oEncVolume.ClearAllAutoUnlockKeys(),_
  1917.                 GLR.Localize("clearall_error")
  1918. End Function
  1919.  
  1920. '---- Check for stored autounlock keys -----'
  1921. Function IsAutoUnlockKeyStored()
  1922.     Dim bAutoKeys
  1923.     CheckRC m_oEncVolume.IsAutoUnlockKeyStored(bAutoKeys),_
  1924.                 GLR.Localize("autounlockkeys_error")
  1925.  
  1926.     IsAutoUnlockKeyStored = bAutoKeys
  1927. End Function
  1928.  
  1929.  
  1930. '---- add a clear key ----'
  1931.     Public Function DisableKeyProtectors()
  1932.         CheckRC m_oEncVolume.DisableKeyProtectors(),_
  1933.                 GLR.Localize("disable_error")
  1934.     End Function
  1935.  
  1936. '---- remove the clear key ---'
  1937.     Public Function EnableKeyProtectors()
  1938.         CheckRC m_oEncVolume.EnableKeyProtectors(),_
  1939.                 GLR.Localize("enable_error")
  1940.     End Function
  1941.  
  1942. '----- return the label if we've got the underlying object ----'
  1943.     Public Property Get Label
  1944.         On Error Resume Next
  1945.  
  1946.         If Not(IsNull(m_oPhysVolume)) and Not(IsEmpty(m_oPhysVolume)) _
  1947.            And Not(IsLocked()) Then
  1948.  
  1949.            Label = m_oPhysVolume.Label
  1950.         Else
  1951.            Label = GLR.Localize("status.nolabel")
  1952.         End If
  1953.  
  1954.         On Error Goto 0
  1955.     End Property
  1956.  
  1957. '----- Size of the disk in GB ----'
  1958.     Public Property Get Capacity
  1959.         Dim bLogic
  1960.  
  1961.         On Error Resume Next
  1962.  
  1963.         bLogic = (Not IsNull(m_oPhysVolume)) And _
  1964.                  (Not IsEmpty(m_oPhysVolume)) And _
  1965.                  (Not IsLocked())
  1966.  
  1967.         If bLogic Then
  1968.             bLogic = Not IsNull(m_oPhysVolume.Capacity)
  1969.         End If
  1970.  
  1971.         If bLogic  Then
  1972.            Capacity = Round(m_oPhysVolume.Capacity/(1024*1024*1024),2)
  1973.         Else
  1974.            Capacity = GLR.Localize("status.nosize")
  1975.         End If
  1976.  
  1977.         On Error GoTo 0
  1978.     End Property
  1979.  
  1980.     Public Function GetKeyProtectorType(sProtector)
  1981.         Dim nKeyProtType
  1982.         CheckRC m_oEncVolume.GetKeyProtectorType(sProtector,nKeyProtType) ,_
  1983.                             GLR.Localize("status.keyproterror2")
  1984.  
  1985.         GetKeyProtectorType = nKeyProtType
  1986.     End Function
  1987.  
  1988.     Public Function GetKeyProtectors(nType)
  1989.         Dim aProtectors
  1990.  
  1991.         CheckRC m_oEncVolume.GetKeyProtectors(nType,aProtectors),_
  1992.                     GLR.Localize("volumekeyproterror")
  1993.  
  1994.         GetKeyProtectors = aProtectors
  1995.     End Function
  1996.  
  1997. '--- Locked status ----'
  1998.     Public Property Get LockStatus
  1999.         Dim nLockStatus
  2000.         CheckRC m_oEncVolume.GetLockStatus(nLockStatus) , _
  2001.                 GLR.Localize("LockStatusError")
  2002.  
  2003.         LockStatus = nLockStatus
  2004.     End Property
  2005.  
  2006.     Public Function IsLocked()
  2007.         If LockStatus = kBDE_LOCK_STATUS_LOCKED Then
  2008.             IsLocked = True
  2009.         Else
  2010.             IsLocked = False
  2011.         End If
  2012.     End Function
  2013.  
  2014. '---- Lock the volume ----'
  2015.     Public Function Lock(tForceDismount)
  2016.         CheckRC m_oEncVolume.Lock(tForceDismount),_
  2017.             GLR.Localize("disklockerror")
  2018.     End Function
  2019. '-----------------'
  2020.  
  2021. '--- Resume conversion of the disk ---'
  2022.     Public Function ResumeConversion()
  2023.         CheckRC m_oEncVolume.ResumeConversion(),_
  2024.                 GLR.Localize("resume_failure")
  2025.     End Function
  2026.  
  2027. '--- Pause conversion of the disk ---'
  2028.     Public Function PauseConversion()
  2029.         CheckRC m_oEncVolume.PauseConversion(),_
  2030.                 GLR.Localize("pause_failure")
  2031.     End Function
  2032.  
  2033. '--- Conversion Status Functions----'
  2034.     Public Property Get ConversionStatus
  2035.         Dim nConversionStatus,nEncryptPercentage
  2036.  
  2037.         If IsLocked() Then
  2038.             nConversionStatus = -1
  2039.         Else
  2040.             CheckRC m_oEncVolume.GetConversionStatus( nConversionStatus, nEncryptPercentage ), _
  2041.                     GLR.Localize("convstatuserror")
  2042.         End If
  2043.  
  2044.         ConversionStatus = nConversionStatus
  2045.     End Property
  2046.  
  2047.     Public Function IsDecrypted()
  2048.         If ConversionStatus = kBDE_CONVERSION_STATUS_DECRYPTED Then
  2049.             IsDecrypted = True
  2050.         Else
  2051.             IsDecrypted = False
  2052.         End If
  2053.     End Function
  2054.  
  2055.     Public Function IsEncrypted()
  2056.         If ConversionStatus = kBDE_CONVERSION_STATUS_ENCRYPTED Then
  2057.             IsEncrypted = True
  2058.         Else
  2059.             IsEncrypted = False
  2060.         End If
  2061.     End Function
  2062.  
  2063.     Public Function IsEncrypting()
  2064.         If ConversionStatus = kBDE_CONVERSION_STATUS_ENCRYPTING Or _
  2065.            ConversionStatus = kBDE_CONVERSION_STATUS_ENCPAUSED Then
  2066.            IsEncrypting = True
  2067.         Else
  2068.            IsEncrypting = False
  2069.         End If
  2070.     End Function
  2071.  
  2072.     Public Function IsDecrypting()
  2073.         If ConversionStatus = kBDE_CONVERSION_STATUS_DECRYPTING Or _
  2074.            ConversionStatus = kBDE_CONVERSION_STATUS_DECPAUSED Then
  2075.            IsDecrypting = True
  2076.         Else
  2077.            IsDecrypting = False
  2078.         End If
  2079.     End Function
  2080.  
  2081.     Public Function IsPaused()
  2082.         If ConversionStatus = kBDE_CONVERSION_STATUS_ENCPAUSED Or _
  2083.            ConversionStatus = kBDE_CONVERSION_STATUS_DECPAUSED Then
  2084.            
  2085.             IsPaused = True
  2086.         Else
  2087.             IsPaused = False
  2088.         End If
  2089.     End Function
  2090.  
  2091.     Public Property Get EncryptionMethod
  2092.         Dim nEncMethod
  2093.         CheckRC m_oEncVolume.GetEncryptionMethod(nEncMethod) ,_
  2094.                     GLR.Localize("status.encerror")
  2095.  
  2096.         EncryptionMethod = nEncMethod
  2097.     End Property
  2098.  
  2099.  
  2100. '----- Wrapper methods for the protection status -------'
  2101.     Public Property Get ProtectionStatus
  2102.         Dim nProtStatus
  2103.         CheckRC m_oEncVolume.GetProtectionStatus( nProtStatus ) ,_
  2104.             GLR.Localize("protstaterror")
  2105.  
  2106.         ProtectionStatus = nProtStatus
  2107.     End Property
  2108.  
  2109.     Public Function IsProtected()
  2110.         If ProtectionStatus = kBDE_PROTECTION_STATUS_ON Then
  2111.             IsProtected = True
  2112.         Else
  2113.             IsProtected = False
  2114.         End If
  2115.     End Function
  2116.  
  2117. '------------------------------'
  2118.             
  2119.         
  2120.  
  2121. '------ Encryption Percentage Functions -----'
  2122.     Public Property Get EncryptionPercentage
  2123.         Dim nConversionStatus,nEncryptPercentage
  2124.  
  2125.         If IsLocked() Then
  2126.             nEncryptPercentage = GLR.Localize("status.nosize")
  2127.         Else
  2128.             CheckRC m_oEncVolume.GetConversionStatus( nConversionStatus, nEncryptPercentage ), _
  2129.                     GLR.Localize("convstatuserror")
  2130.         End if
  2131.  
  2132.         EncryptionPercentage = nEncryptPercentage
  2133.     End Property
  2134.  
  2135. '---- Key Protector Available Functions -------'
  2136.     Private Function IsKeyProtectorAvailable(nType,bBoolRef)
  2137.         Dim rc
  2138.  
  2139.         rc = m_oEncVolume.IsKeyProtectorAvailable(nType,bBoolRef)
  2140.  
  2141.         IsKeyProtectorAvailable = rc
  2142.     End Function
  2143.  
  2144. '----- Start Encryption of the Disk ---------'
  2145. Public Function Encrypt(nEncryption)
  2146.     CheckRC m_oEncVolume.Encrypt(nEncryption),_
  2147.                 GLR.Localize("encrypt_fail")
  2148. End Function
  2149.  
  2150. '----- Start Encryption of the Disk ---------'
  2151. Public Function EncryptAfterHardwareTest(nEncryption)
  2152.     CheckRC m_oEncVolume.EncryptAfterHardwareTest(nEncryption),_
  2153.                 GLR.Localize("encrypt_fail")
  2154. End Function
  2155.  
  2156. '----- Decrypt the disk-----------'
  2157. Public Function Decrypt()
  2158.     CheckRC m_oEncVolume.Decrypt(), _
  2159.             GLR.Localize("DecryptFailure")
  2160. End Function
  2161.  
  2162.     '---- Check to see if ANY tpm protector is being used ----'
  2163.     Public Function UsesAnyTPM()
  2164.         UsesAnyTPM = UsesTPM() Or UsesTPMAndPin() Or UsesTpmAndKey() Or UsesTpmAndPinAndKey()
  2165.     End Function
  2166.  
  2167.     Public Function UsesTPM()
  2168.         Dim bTPMPresent
  2169.  
  2170.         CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM,bTPMPresent),_
  2171.                 GLR.Localize("tpm_available_error")
  2172.  
  2173.         UsesTpm = bTPMPresent
  2174.     End Function
  2175.  
  2176.     Public Function UsesPassword()
  2177.         Dim bPasswordPresent
  2178.         CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_PASSWORD,_
  2179.                                                    bPasswordPresent),_
  2180.                 GLR.Localize("passw_available_error")
  2181.  
  2182.         UsesPassword = bPasswordPresent
  2183.     End Function
  2184.  
  2185.     Public Function UsesKey()
  2186.         Dim bRecoveryKeyPresent
  2187.         CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_KEY,_
  2188.                                                    bRecoveryKeyPresent),_
  2189.                 GLR.Localize("key_available_error")
  2190.  
  2191.         UsesKey = bRecoveryKeyPresent
  2192.     End Function
  2193.  
  2194.     Public Function UsesTPMAndPIN()
  2195.         Dim bTPM_PINPresent
  2196.         CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM_PIN,_
  2197.                                                    bTPM_PINPresent),_
  2198.                 GLR.Localize("pin_available_error")
  2199.  
  2200.         UsesTPMAndPIN = bTPM_PINPresent
  2201.     End Function
  2202.  
  2203.     Public Function UsesTPMAndKey()
  2204.         Dim bTPM_KeyPresent
  2205.         CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM_KEY,_
  2206.                                                    bTPM_KeyPresent),_
  2207.                 GLR.Localize("tpmsk_available_error")
  2208.  
  2209.         UsesTPMAndKey = bTPM_KeyPresent
  2210.     End Function
  2211.  
  2212.     Public Function UsesTPMAndPINAndKey()
  2213.         Dim bTPM_PIN_KeyPresent
  2214.         CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM_PIN_KEY,_
  2215.                                                    bTPM_PIN_KeyPresent),_
  2216.                 GLR.Localize("tpm_pin_key_available_error")
  2217.  
  2218.         UsesTPMAndPINAndKey = bTPM_PIN_KeyPresent
  2219.     End Function
  2220.  
  2221.  
  2222. 'External Key
  2223. '-----------------------'
  2224. '- External Key means that we generate
  2225. '- A 32 byte key at random.
  2226. '- And this is used to protect the disk.
  2227. '- This key is meant to be stored at the root
  2228. '- Of a USB disk.  BDE will prompt for the location
  2229. '- Of this key at mount time
  2230. '-----------------------'
  2231.     Public Function AddExternalKey()
  2232.         Dim sProtID,rc
  2233.         Dim aExternalKey
  2234.  
  2235.         aExternalKey = Empty
  2236.         rc = m_oEncVolume.ProtectKeyWithExternalKey("ExternalKey",_
  2237.                                                  aExternalKey,sProtID)
  2238.         CheckRC rc,GLR.Localize("ProtectKeyFail")
  2239.         AddExternalKey = sProtID
  2240.     End Function
  2241.  
  2242. 'Numeric Password
  2243. '----------------------'
  2244. '- Protecting the BDE with a password means
  2245. '- That a 48 digit numeric key must be generated
  2246. '- And will have to be entered to unlock the disk
  2247. '----------------------'
  2248.     Function AddPassword(sPasswd)
  2249.         Dim iPasswd
  2250.         Dim sProtID
  2251.         Dim bIsValid,rc
  2252.  
  2253.         If Not IsEmpty(sPasswd) Then
  2254.             CheckRC m_oEncVolume.IsNumericalPasswordValid(sPasswd,bIsValid),_
  2255.                     GLR.Localize("CheckPasswFail")
  2256.  
  2257.             If Not bIsValid Then
  2258.                 Fail(GLR.Localize("PasswNotValid"))
  2259.             End If
  2260.         End If
  2261.  
  2262.         rc = m_oEncVolume.ProtectKeyWithNumericalPassword("DiskPassword",_
  2263.                             sPasswd,sProtID)
  2264.  
  2265.         if rc = kBDE_ERROR_FIPS_POLICY Then
  2266.             BdeArgs.FormatLine 4, GLR.Localize("fips_warning")
  2267.             sProtID = Empty
  2268.         Else
  2269.             CheckRC rc, GLR.Localize("ProtectDiskFail")
  2270.         End If
  2271.  
  2272.         AddPassword = sProtID
  2273.     End Function
  2274.  
  2275. Function CustomTpmErrorMessages(rc)
  2276.     If rc = kBDE_ERROR_BOOTABLE_CDDVD Then
  2277.         Fail FormatStr("error_dvd")
  2278.     End If
  2279. End Function
  2280.  
  2281. 'TPM BDE protection
  2282. '--------------------'
  2283. '- The TPM will be used to validate a BOOT drive
  2284. '- This is done by setting the PlatformValidationProfile
  2285. '- The numbers in this array specify what boot components to
  2286. '- Examine at boot time.
  2287. '- This function uses the default metrics.
  2288. '--------------------'
  2289.     Function AddTpm()
  2290.         Dim sProtID,rc
  2291.  
  2292.         rc = m_oEncVolume.ProtectKeyWithTPM("TPM Protection",_
  2293.                                              Empty,_
  2294.                                              sProtID)
  2295.         CustomTpmErrorMessages(rc)
  2296.  
  2297.         CheckRC rc,GLR.Localize("tpm_fail")
  2298.  
  2299.         AddTpm = sProtID
  2300.      End Function
  2301.  
  2302. 'TPM and PIN BDE Protection
  2303. '---------------------------'
  2304. '- The disk will only be unlocked if BOTH the TPM
  2305. '- Correctly validates the boot components
  2306. '- AND the user inputs the correct PIN
  2307. '- PIN is generated below(random)
  2308. '---------------------------'
  2309.     Function AddTpmAndPin(sPasswd)
  2310.         Dim iPasswd
  2311.         Dim aPasswd
  2312.         Dim oInParams
  2313.         Dim oOutParams
  2314.         Dim bIsValid,sProtID,rc
  2315.  
  2316.         rc = m_oEncVolume.ProtectKeyWithTPMAndPIN("TPMAndPin",_
  2317.                                                 Empty,_
  2318.                                                 sPasswd,_
  2319.                                                 sProtID)
  2320.         CustomTpmErrorMessages(rc)
  2321.  
  2322.         CheckRC rc,GLR.Localize("tpm_pin_fail")
  2323.  
  2324.         AddTpmAndPin = sProtID
  2325.     End Function
  2326.  
  2327. 'TPM and KEY BDE Protection
  2328. '---------------------------'
  2329. '- The disk will only be unlocked if BOTH the TPM
  2330. '- Correctly validates the boot components
  2331. '- AND the USB key is found.
  2332. '---------------------------'
  2333.     Function AddTpmAndKey()
  2334.         Dim sProtID,rc
  2335.         Dim aKey
  2336.  
  2337.         aKey = Empty
  2338.  
  2339.         rc = m_oEncVolume.ProtectKeyWithTPMAndStartupKey(_
  2340.                                     "TpmAndStartupKey",_
  2341.                                     Empty,_
  2342.                                     aKey,_
  2343.                                     sProtID)
  2344.  
  2345.         CustomTpmErrorMessages(rc)
  2346.         CheckRC rc,GLR.Localize("tpm_key_fail")
  2347.  
  2348.         AddTpmAndKey = sProtID
  2349.     End Function
  2350.  
  2351. 'TPM and PIN and KEY BDE Protection
  2352. '---------------------------'
  2353. '- The disk will only be unlocked if the TPM
  2354. '- Correctly validates the boot components
  2355. '- AND the user inputs the correct PIN
  2356. '- AND the USB key is found
  2357. '---------------------------'
  2358.     Function AddTpmAndPinAndKey(sPasswd)
  2359.         Dim sProtID,rc
  2360.         Dim aKey
  2361.  
  2362.         aKey = Empty
  2363.  
  2364.         rc = m_oEncVolume.ProtectKeyWithTPMAndPINAndStartupKey(_
  2365.                                     "TpmAndPinAndStartupKey",_
  2366.                                     Empty,_
  2367.                                     sPasswd,_
  2368.                                     aKey,_
  2369.                                     sProtID)
  2370.  
  2371.         CustomTpmErrorMessages(rc)
  2372.         CheckRC rc,GLR.Localize("tpm_pin_key_fail")
  2373.  
  2374.         AddTpmAndPinAndKey = sProtID
  2375.     End Function
  2376.  
  2377. '---- Save a Key to an external directory ----'
  2378.     Function SaveKey(sProtID,sFilePath)
  2379.         Dim rc
  2380.         rc = m_oEncVolume.SaveExternalKeyToFile(sProtID,_
  2381.                                               sFilePath)
  2382.  
  2383.         If rc = kBDE_ERROR_RELATIVE_PATH Then
  2384.             Fail GLR.Localize("relative_path_error")
  2385.         End If
  2386.  
  2387.         CheckRC rc, GLR.Localize("bde_save_failure")
  2388.  
  2389.     End Function
  2390.  
  2391. End Class
  2392.  
  2393.  
  2394. '-------- End VolumeObject Class-----------------'
  2395. '------------------------------------------------'
  2396. </script>
  2397.  
  2398.  
  2399.  
  2400.  
  2401. <!--------------------------------------------------->
  2402. <!-- Manage-BDE MAIN Body -->
  2403. <!--------------------------------------------------->
  2404.  
  2405.  
  2406.  
  2407. <script id="runtime" language="VBscript">
  2408. Option Explicit
  2409.  
  2410. '----Important first step------------------'
  2411. '- Ensure that we're running under cscript-'
  2412. If Not IsHostCScript() Then
  2413.     WScript.Echo VBsprintf(GLR.Localize("wscript_message"),empty)
  2414.     WScript.Quit -1
  2415. End If
  2416.  
  2417. '-----Constants--------'
  2418. '2 Specifies AES 256 with Diffuser
  2419. Const nkEncryptionType = 2
  2420.  
  2421. Function IsAlpha( cChar )
  2422.     Dim tRet
  2423.     tRet = False
  2424.  
  2425.     cChar = LCase(cChar)
  2426.     If ( Asc(cChar) >= Asc("a") And _
  2427.        Asc(cChar) <= Asc("z") ) Then
  2428.  
  2429.        tRet = True
  2430.     End If
  2431.  
  2432.     IsAlpha = tRet
  2433. End Function
  2434.  
  2435. Function ParseVolume( oParseObj)
  2436.     Dim vRetVal,volArg
  2437.  
  2438.     volArg = oParseObj.Argument
  2439.  
  2440.     If Len(volArg) <> 2 Or Right(volArg,1) <> ":" _
  2441.        Or Not(IsAlpha(Left(volArg,1))) Then
  2442.  
  2443.         If oParseObj.FailOnError() Then
  2444.             Fail(GLR.Localize("volume_format_error"))
  2445.         Else
  2446.             vRetVal = Null
  2447.         End If
  2448.     Else
  2449.         vRetVal = UCase(Left(volArg,1)) & ":"
  2450.     End If
  2451.  
  2452.     ParseVolume = vRetVal
  2453. End Function
  2454.  
  2455. Function ParsePassword(oParseObj)
  2456.     Dim vRetVal,sArg
  2457.     sArg = oParseObj.Argument
  2458.  
  2459.     '--- need this function so we can accept empty passwords ---'
  2460.     If IsEmpty(sArg) Or Len(sArg) >= 48 Then
  2461.         vRetVal = sArg
  2462.     Else
  2463.         If oParseObj.FailOnError() Then
  2464.             Fail( vbsprintf(GLR.Localize("PasswNotValid"),Array(sArg)))
  2465.         Else
  2466.             vRetVal = Null
  2467.         End if
  2468.     End If
  2469.  
  2470.     ParsePassword = vRetVal
  2471. End Function
  2472.  
  2473. Function parseProtType( oParseObj )
  2474.     Dim nType
  2475.  
  2476.     '---- This will still fail, but it will be clearer why ----'
  2477.     If( IsEmpty(oParseObj.Argument)) Then
  2478.         oParseObj.Argument = "(Empty)"
  2479.     End If
  2480.  
  2481.     Select Case LCase(oParseObj.Argument)
  2482.         Case "recoverypassword"
  2483.             nType = kBDE_PROTECTOR_TYPE_PASSWORD
  2484.         Case "externalkey"
  2485.             nType = kBDE_PROTECTOR_TYPE_KEY
  2486.         Case "tpm"
  2487.             nType = kBDE_PROTECTOR_TYPE_TPM
  2488.         Case "tpmandstartupkey"
  2489.             nType = kBDE_PROTECTOR_TYPE_TPM_KEY
  2490.         Case "tpmandpin"
  2491.             nType = kBDE_PROTECTOR_TYPE_TPM_PIN
  2492.         Case "tpmandpinandstartupkey"
  2493.             nType = kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
  2494.         Case Else
  2495.             If oParseObj.FailOnError() Then
  2496.                 Fail(VBsprintf(GLR.Localize("key_type_invalid"),Array(oParseObj.Argument)))
  2497.             Else
  2498.                 nType = Null
  2499.             End If
  2500.     End Select
  2501.  
  2502.     parseProtType = nType
  2503. End Function
  2504.  
  2505. Function parseEncryption( oParseObj )
  2506.     Dim nEncryptionType
  2507.  
  2508.     Select Case LCase(oParseObj.Argument)
  2509.         Case "none"
  2510.             nEncryptionType = kBDE_ENCRYPTION_NONE
  2511.         Case "aes128_diffuser"
  2512.             nEncryptionType = kBDE_ENCRYPTION_AES128_DIFFUSER
  2513.         Case "aes256_diffuser"
  2514.             nEncryptionType = kBDE_ENCRYPTION_AES256_DIFFUSER
  2515.         Case "aes128"
  2516.             nEncryptionType = kBDE_ENCRYPTION_AES128
  2517.         Case "aes256"
  2518.             nEncryptionType = kBDE_ENCRYPTION_AES256
  2519.         Case Else
  2520.             If oParseObj.FailOnError() Then
  2521.                 Fail(VBsprintf(GLR.Localize("encryption_invalid"),Array(oParseObj.Argument)))
  2522.             Else
  2523.                 nEncryptionType = Null
  2524.             End If
  2525.     End Select
  2526.  
  2527.     parseEncryption = nEncryptionType
  2528. End Function
  2529.  
  2530. Function AddVolumeParameter()
  2531.     Dim oVolParam
  2532.  
  2533.     Set oVolParam = new BdeArgElem
  2534.  
  2535.     oVolParam.Init          kPARAM_FREE, "volumeletter"          , "v", kARG_FUNC, GetRef("ParseVolume"), Empty, True, True
  2536.     oVolParam.SetUsage        kUSAGE_CMN, GLR.Localize("volusage_req"), GLR.Localize("volusage_required")
  2537.     oVolParam.ShortDescription = FormatStr("volusage_short")
  2538.  
  2539.     BdeArgs.AddParam oVolParam
  2540. End Function
  2541.  
  2542. Function AddProtectorParameters()
  2543.     Dim oTPMStartupkeyParam,oRecoveryKeyParam,oPasswordParam
  2544.     Dim oTPMPinParam,oSKParam,oTPMPinKeyParam
  2545.  
  2546.     Set oTPMStartupkeyParam = new BdeArgElem
  2547.     Set oRecoveryKeyParam   = new BdeArgElem
  2548.     Set oPasswordParam      = new BdeArgElem
  2549.     Set oTPMPinParam        = new BdeArgElem
  2550.     Set oSKParam            = new BdeArgElem
  2551.     Set oTPMPinKeyParam     = new BdeArgElem
  2552.  
  2553.     '---OBJECT                     PARAM_TYPE  PARAMETER_NAME         SYNONYM  ARG_TYPE     CALLBACK_FUNCTION           DEFAULT VALUE                   Required   Argument Required
  2554.     oTPMStartupkeyParam.Init    kPARAM_PRM, "tpmandstartupkey"      ,"tsk"  ,kARG_STR   ,Empty                      ,Empty                          , False    ,True
  2555.     oRecoveryKeyParam.Init      kPARAM_PRM, "recoverykey"           ,"rk"   ,kARG_STR   ,Empty                      ,Empty                          , False    ,True
  2556.     oSKParam.Init               kPARAM_PRM, "startupkey"            ,"sk"   ,kARG_STR   ,Empty                      ,Empty                          , False    ,True
  2557.     oPasswordParam.Init         kPARAM_PRM, "recoverypassword"      ,"rp"   ,kARG_FUNC  ,GetRef("ParsePassword")    ,Empty                          , False    ,True
  2558.     oTPMPinParam.Init           kPARAM_PRM, "tpmandpin"             ,"tp"   ,kARG_STR   ,Empty                      ,Empty                          , False    ,True
  2559.     oTPMPinKeyParam.Init        kPARAM_PRM, "tpmandpinandstartupkey","tpsk" ,kARG_STR   ,Empty                      ,Empty                          , False    ,False
  2560.  
  2561.     oTPMStartupkeyParam.SetUsage kUSAGE_CMN,"-TPMAndStartupKey or -tsk"   ,GLR.Localize("tsk_desc")
  2562.     oRecoveryKeyParam.SetUsage   kUSAGE_CMN,"-RecoveryKey or -rk"       ,GLR.Localize("rk_desc")
  2563.     oSKParam.SetUsage            kUSAGE_CMN,"-StartupKey or -sk"        ,GLR.Localize("sk_desc")
  2564.     oPasswordParam.SetUsage      kUSAGE_CMN,"-RecoveryPassword or -rp"  ,GLR.Localize("rp_desc")
  2565.     oTPMPinParam.SetUsage        kUSAGE_CMN,"-TPMAndPIN or -tp"           ,GLR.Localize("tp_desc")
  2566.     oTPMPinKeyParam.SetUsage     kUSAGE_CMN,"-TPMAndPINAndStartupKey or -tpsk",GLR.Localize("tpsk_desc")
  2567.  
  2568.     oTPMStartupkeyParam.ShortDescription = FormatStr("tsk_desc_short")
  2569.     oRecoveryKeyParam.ShortDescription = FormatStr("rk_desc_short")
  2570.     oSKParam.ShortDescription = FormatStr("sk_desc_short")
  2571.     oPasswordParam.ShortDescription = FormatStr("rp_desc_short")
  2572.     oTPMPinParam.ShortDescription = FormatStr("tp_desc_short")
  2573.     oTPMPinKeyParam.ShortDescription = FormatStr("tpsk_desc_short")
  2574.  
  2575.     BdeArgs.AddParam oPasswordParam
  2576.     BdeArgs.AddParam oRecoveryKeyParam
  2577.     BdeArgs.AddParam oSKParam
  2578.     BdeArgs.AddParam oTPMPinParam
  2579.     BdeArgs.AddParam oTPMStartupkeyParam
  2580.     BdeArgs.AddParam oTPMPinKeyParam
  2581. End Function
  2582.  
  2583. Function Cmd_Status(arg)
  2584.     Dim oVolParam,oProtStatusParam
  2585.  
  2586.     Set oVolParam   = new BdeArgElem
  2587.     Set oProtStatusParam = new BdeArgElem
  2588.  
  2589.     oVolParam.Init          kPARAM_FREE, "volumeletter"          , "v", kARG_FUNC, GetRef("ParseVolume"), Empty, False, True
  2590.     oProtStatusParam.Init   kPARAM_PRM, "protectionaserrorlevel", "p", kARG_BOOL, Empty                , False, False, False
  2591.  
  2592.     oVolParam.SetUsage        kUSAGE_CMN, GLR.Localize("volusage_req"), GLR.Localize("vol_usage")
  2593.     oProtStatusParam.SetUsage kUSAGE_CMN, "-ProtectionAsErrorLevel or -p", GLR.Localize("proterror_usage")
  2594.  
  2595.     oVolParam.ShortDescription = FormatStr("volusage_short")
  2596.     oProtStatusParam.ShortDescription = FormatStr("pusage_short")
  2597.  
  2598.     BdeArgs.ClearCommands()
  2599.     BdeArgs.AddParam oVolParam
  2600.     BdeArgs.AddParam oProtStatusParam
  2601.  
  2602.     BdeArgs.SetPreamble 8, FormatStr("status_preamble")
  2603.     BdeArgs.SetDescription(GLR.Localize("status_desc"))
  2604.  
  2605.     BdeArgs.AddExample("manage-bde -status")
  2606.     BdeArgs.AddExample("manage-bde -status e:")
  2607.     BdeArgs.AddExample("manage-bde -status e: -ProtectionAsErrorLevel")
  2608.  
  2609.     BdeArgs.SetContinuation GetRef("DoStatus"), Empty
  2610. End Function
  2611.  
  2612. Function Cmd_On(arg)
  2613.     Dim oEncryptionParam,oHardwareTestParam
  2614.  
  2615.     Set oEncryptionParam    = new BdeArgElem
  2616.     Set oHardwareTestParam  = new BdeArgElem
  2617.  
  2618.     BdeArgs.ClearCommands()
  2619.  
  2620.     BdeArgs.SetPreamble 8,FormatStr("on_preamble")
  2621.  
  2622.     BdeArgs.SetDescription(GLR.Localize("on_desc"))
  2623.     BdeArgs.ShortDescription = FormatStr("on_desc_short")
  2624.  
  2625.     oEncryptionParam.Init       kPARAM_PRM, "encryptionmethod"      ,"em"   ,kARG_FUNC  ,GetRef("parseEncryption")  ,0, False    ,True
  2626.     oEncryptionParam.SetUsage    kUSAGE_CMN,"-EncryptionMethod or -em"  ,GLR.Localize("em_desc")
  2627.     oEncryptionParam.ShortDescription = FormatStr("em_desc_short")
  2628.  
  2629.     oHardwareTestParam.Init       kPARAM_PRM, "skiphardwaretest"      ,"s"   ,kARG_BOOL  ,False  ,Empty, False    ,False
  2630.     oHardwareTestParam.SetUsage    kUSAGE_CMN,"-SkipHardwareTest or -s"  ,GLR.Localize("hardware_desc")
  2631.     oHardwareTestParam.ShortDescription = FormatStr("hardware_desc_short")
  2632.  
  2633.     AddVolumeParameter()
  2634.     AddProtectorParameters()
  2635.     BdeArgs.AddParam oEncryptionParam
  2636.     BdeArgs.AddParam oHardwareTestParam
  2637.  
  2638.     BdeArgs.AddExample("manage-bde -on C: -RecoveryPassword")
  2639.     BdeArgs.AddExample("manage-bde -on C: -RecoveryKey e:\ -RecoveryPassword")
  2640.     BdeArgs.AddExample("manage-bde -on C: -rp -rk ""f:\Folder"" -SkipHardwareTest")
  2641.     BdeArgs.AddExample("manage-bde -on C: -rp -StartupKey ""f:\""")
  2642.     BdeArgs.AddExample("manage-bde -on C: -rp -TPMAndPIN 1234 -em aes128_diffuser")
  2643.  
  2644.     BdeArgs.SetContinuation GetRef("DoOn"), Empty
  2645. End Function
  2646.  
  2647. Function Cmd_Pause(arg)
  2648.  
  2649.     BdeArgs.ClearCommands()
  2650.     BdeArgs.SetPreamble 8,FormatStr("pause_preamble")
  2651.     BdeArgs.SetDescription(GLR.Localize("pause_desc"))
  2652.  
  2653.     AddVolumeParameter()
  2654.  
  2655.     BdeArgs.AddExample("manage-bde -pause C:")
  2656.  
  2657.     BdeArgs.SetContinuation GetRef("DoPause"), Empty
  2658. End Function
  2659.  
  2660. Function Cmd_Resume(arg)
  2661.  
  2662.     BdeArgs.ClearCommands()
  2663.     BdeArgs.SetPreamble 8,FormatStr("resume_preamble")
  2664.     BdeArgs.SetDescription(GLR.Localize("resume_desc"))
  2665.  
  2666.     AddVolumeParameter()
  2667.  
  2668.     BdeArgs.AddExample("manage-bde -resume C:")
  2669.  
  2670.     BdeArgs.SetContinuation GetRef("DoResume"), Empty
  2671. End Function
  2672.  
  2673. Function Cmd_Unlock(arg)
  2674.     Dim oKeyParam,oPasswordParam
  2675.  
  2676.     Set oKeyParam       = new BdeArgElem
  2677.     Set oPasswordParam  = new BdeArgElem
  2678.     BdeArgs.ClearCommands()
  2679.  
  2680.     BdeArgs.SetPreamble 8,FormatStr("unlock_preamble")
  2681.     BdeArgs.SetDescription(GLR.Localize("unlock_desc"))
  2682.  
  2683.     oKeyParam.Init      kPARAM_PRM, "recoverykey"       ,"rk"    ,kARG_STR   ,Empty                 ,Empty, False    ,True
  2684.     oPasswordParam.Init kPARAM_PRM, "recoverypassword"  ,"rp"    ,kARG_STR   ,Empty                 ,Empty, False    ,True
  2685.  
  2686.     oKeyParam.SetUsage      kUSAGE_CMN,"-RecoveryKey or -rk"      ,GLR.Localize("rk_unlock_desc")
  2687.     oPasswordParam.SetUsage kUSAGE_CMN,"-RecoveryPassword or -rp" ,GLR.Localize("rp_unlock_desc")
  2688.  
  2689.     oKeyParam.ShortDescription = FormatStr("rk_unlock_short")
  2690.     oPasswordParam.ShortDescription = FormatStr("rp_unlock_short")
  2691.  
  2692.     AddVolumeParameter()
  2693.     BdeArgs.AddParam oPasswordParam
  2694.     BdeArgs.AddParam oKeyParam
  2695.  
  2696.     BdeArgs.AddExample("manage-bde -unlock -?")
  2697.     BdeArgs.AddExample("manage-bde -unlock e: -RecoveryPassword ...")
  2698.     BdeArgs.AddExample("manage-bde -unlock e: -RecoveryKey ""f:\File Folder\Filename""")
  2699.  
  2700.     BdeArgs.SetContinuation GetRef("DoUnlock"), Empty
  2701. End Function
  2702.  
  2703. Function Cmd_Off(arg)
  2704.     BdeArgs.ClearCommands()
  2705.  
  2706.     AddVolumeParameter()
  2707.  
  2708.     BdeArgs.SetPreamble 8,FormatStr("off_preamble")
  2709.     BdeArgs.SetDescription(GLR.Localize("off_desc"))
  2710.  
  2711.     BdeArgs.AddExample("manage-bde -off C:")
  2712.  
  2713.     BdeArgs.SetContinuation GetRef("DoOff"), Empty
  2714. End Function
  2715.  
  2716. Function Cmd_Protectors_Add(arg)
  2717.     Dim oTPMParam
  2718.  
  2719.     Set oTPMParam = new BdeArgElem
  2720.  
  2721.     BdeArgs.ClearCommands()
  2722.     BdeArgs.SetPreamble 12,FormatStr("add_preamble")
  2723.  
  2724.     BdeArgs.SetDescription(GLR.Localize("add_desc_full"))
  2725.     BdeArgs.ShortDescription = FormatStr("add_desc_short")
  2726.  
  2727.     '---OBJECT                     PARAM_TYPE  PARAMETER_NAME         SYNONYM  ARG_TYPE     CALLBACK_FUNCTION           DEFAULT VALUE                   Required   Argument Required
  2728.     oTPMParam.Init               kPARAM_PRM, "tpm"                   ,""     ,kARG_BOOL  ,Empty                      ,Empty                          , False    ,False
  2729.     oTPMParam.SetUsage           kUSAGE_CMN,"-tpm"                      ,GLR.Localize("tpm_desc")
  2730.     oTPMParam.ShortDescription = FormatStr("tpm_short") 
  2731.  
  2732.     AddProtectorParameters()
  2733.     BdeArgs.AddParam oTpmParam
  2734.  
  2735.     BdeArgs.AddExample("manage-bde -protectors -add e: -RecoveryPassword")
  2736.     BdeArgs.AddExample("manage-bde -protectors -add e: -rp -rk h:\")
  2737.     BdeArgs.AddExample("manage-bde -protectors -add e: -TPMAndPIN 1234")
  2738.     BdeArgs.AddExample("manage-bde -protectors -add e: -TPMAndPINAndStartupKey -tp 1234 -tsk h:\")
  2739.  
  2740.     BdeArgs.SetContinuation GetRef("DoProtectors"), "add"
  2741. End Function
  2742.  
  2743. Function Cmd_Protectors_Dis(arg)
  2744.     Cmd_Protectors_DisEn("disable")
  2745. End Function
  2746.  
  2747. Function Cmd_Protectors_En(arg)
  2748.     Cmd_Protectors_DisEn("enable")
  2749. End Function
  2750.  
  2751. Function Cmd_Protectors_DisEn(sArg)
  2752.     BdeArgs.SetContinuation GetRef("DoProtectors"), sArg
  2753. End Function
  2754.  
  2755. Function AddParametersIDType(sPrefix)
  2756.     Dim oTypeParam,oGUIDParam
  2757.  
  2758.     Set oTypeParam      = new BdeArgElem
  2759.     Set oGUIDParam      = new BdeArgElem
  2760.  
  2761.     oTypeParam.Init     kPARAM_PRM, "type"           ,"t"    ,kARG_FUNC  ,GetRef("ParseProtType")        ,Empty, False, True
  2762.     oGUIDParam.Init     kPARAM_PRM, "id"             ,""     ,kARG_STR   ,Empty                          ,Empty, False, True
  2763.  
  2764.     oTypeParam.SetUsage     kUSAGE_CMN,"-Type or -t"                ,GLR.Localize(sPrefix & "." & "type_desc")
  2765.     oGUIDParam.SetUsage     kUSAGE_CMN,"-id"                        ,GLR.Localize(sPrefix & "." & "id_desc")
  2766.  
  2767.     BdeArgs.AddParam oTypeParam
  2768.     BdeArgs.AddParam oGUIDParam
  2769. End Function
  2770.  
  2771. Function Cmd_Protectors_Get(arg)
  2772.     Dim oSaveParam
  2773.  
  2774.     Set oSaveParam      = new BdeArgElem
  2775.  
  2776.     BdeArgs.ClearCommands()
  2777.     BdeArgs.SetPreamble 12,FormatStr("get_preamble")
  2778.     BdeArgs.SetDescription(GLR.Localize("get_full_desc"))
  2779.  
  2780.     oSaveParam.Init     kPARAM_PRM, "saveexternalkey","sek"  ,kARG_STR   ,Empty                          ,Empty, False, True
  2781.     oSaveParam.SetUsage     kUSAGE_CMN,"-SaveExternalKey or -sek"   ,GLR.Localize("sek_desc")
  2782.     
  2783.     AddParametersIDType("get")
  2784.     BdeArgs.AddParam oSaveParam
  2785.  
  2786.     BdeArgs.AddExample("manage-bde -protectors -get C:")
  2787.     BdeArgs.AddExample("manage-bde -protectors -get C: -Type recoverypassword")
  2788.     BdeArgs.AddExample("manage-bde -protectors -get C: -SaveExternalKey ""f:\Folder""")
  2789.  
  2790.     BdeArgs.SetContinuation GetRef("DoProtectors"), "get"
  2791. End Function
  2792.  
  2793. Function Cmd_Protectors_Del(arg)
  2794.  
  2795.     BdeArgs.ClearCommands()
  2796.     BdeArgs.SetPreamble 12,FormatStr("prot_delete_preamble")
  2797.     BdeArgs.SetDescription(GLR.Localize("del_full_desc"))
  2798.  
  2799.     AddParametersIDType("del")
  2800.  
  2801.     BdeArgs.AddExample("manage-bde -protectors -delete C: -id {84E151C1...7A62067A512}")
  2802.     BdeArgs.AddExample("manage-bde -protectors -delete C: -Type TPMAndStartupKey")
  2803.     BdeArgs.AddExample("manage-bde -protectors -delete C: -Type TPMAndPinAndStartupKey")
  2804.  
  2805.     BdeArgs.SetContinuation GetRef("DoProtectors"), "del"
  2806. End Function
  2807.  
  2808. Function Cmd_Protectors(arg)
  2809.     Dim oDeleteCmd,oGetCmd,oDisableCmd,oEnableCmd,oAddCmd
  2810.  
  2811.     Set oDeleteCmd      = new BdeArgElem
  2812.     Set oGetCmd         = new BdeArgElem
  2813.     Set oDisableCmd     = new BdeArgElem
  2814.     Set oEnableCmd      = new BdeArgElem
  2815.     Set oAddCmd         = new BdeArgElem
  2816.  
  2817.     BdeArgs.ClearCommands()
  2818.     BdeArgs.SetPreamble 12,FormatStr("prot_preamble")
  2819.  
  2820.     BdeArgs.SetDescription(GLR.Localize("prot_desc"))
  2821.  
  2822.     oDeleteCmd.Init     kPARAM_CMD, "delete"        ,""     ,kARG_FUNC  ,GetRef("Cmd_Protectors_Del") ,Empty, False, False
  2823.     oGetCmd.Init        kPARAM_CMD, "get"           ,""     ,kARG_FUNC  ,GetRef("Cmd_Protectors_Get") ,Empty, False, False
  2824.     oDisableCmd.Init    kPARAM_CMD, "disable"       ,""     ,kARG_FUNC  ,GetRef("Cmd_Protectors_Dis") ,Empty, False, False
  2825.     oEnableCmd.Init     kPARAM_CMD, "enable"        ,""     ,kARG_FUNC  ,GetRef("Cmd_Protectors_En")  ,Empty, False, False
  2826.     oAddCmd.Init        kPARAM_CMD, "add"           ,""     ,kARG_FUNC  ,GetRef("Cmd_Protectors_add") ,Empty, False, False
  2827.  
  2828.     oDeleteCmd.SetUsage     kUSAGE_CMN,"-delete"                    ,GLR.Localize("del_desc")
  2829.     oGetCmd.SetUsage        kUSAGE_CMN,"-get"                       ,GLR.Localize("get_desc")
  2830.     oDisableCmd.SetUsage    kUSAGE_CMN,"-disable"                   ,GLR.Localize("disable_desc")
  2831.     oEnableCmd.SetUsage     kUSAGE_CMN,"-enable"                    ,GLR.Localize("enable_desc")
  2832.     oAddCmd.SetUsage        kUSAGE_CMN,"-add"                       ,GLR.Localize("add_desc")
  2833.  
  2834.     AddVolumeParameter()
  2835.     BdeArgs.AddParam oGetCmd
  2836.     BdeArgs.AddParam oAddCmd
  2837.     BdeArgs.AddParam oDeleteCmd
  2838.     BdeArgs.AddParam oDisableCmd
  2839.     BdeArgs.AddParam oEnableCmd
  2840.  
  2841.     BdeArgs.AddExample("manage-bde -protectors -add -?")
  2842.     BdeArgs.AddExample("manage-bde -protectors -get -?")
  2843.     BdeArgs.AddExample("manage-bde -protectors -disable C:")
  2844.  
  2845.     BdeArgs.SetContinuation GetRef("DoProtectors"), Empty
  2846. End Function
  2847.  
  2848. Function Cmd_Autounlock(arg)
  2849.     Dim oDisableCmd,oEnableCmd,oClearAllCmd
  2850.  
  2851.     Set oDisableCmd     = new BdeArgElem
  2852.     Set oEnableCmd      = new BdeArgElem
  2853.     Set oClearAllCmd    = new BdeArgElem
  2854.     BdeArgs.ClearCommands()
  2855.     BdeArgs.SetPreamble 12,FormatStr("autounlock_preamble")
  2856.  
  2857.     BdeArgs.SetDescription(GLR.Localize("autounlock_desc"))
  2858.  
  2859.     oDisableCmd.Init    kPARAM_CMD, "disable"       ,""     , kARG_BOOL, False                 ,Empty, False, False
  2860.     oEnableCmd.Init     kPARAM_CMD, "enable"        ,""     , kARG_BOOL, False                 ,Empty, False, False
  2861.     oClearAllCmd.Init   kPARAM_CMD, "clearallkeys"  ,""     , kARG_BOOL, False                 ,Empty, False, False
  2862.  
  2863.     oDisableCmd.SetUsage    kUSAGE_CMN,"-disable",           GLR.Localize("disable_auto_desc")
  2864.     oEnableCmd.SetUsage     kUSAGE_CMN,"-enable",            GLR.Localize("enable_auto_desc")
  2865.     oClearAllCmd.SetUsage   kUSAGE_CMN,"-ClearAllKeys",      GLR.Localize("clearall_desc")
  2866.  
  2867.     oDisableCmd.ShortDescription = FormatStr("disable_auto_short")
  2868.     oEnableCmd.ShortDescription = FormatStr("enable_auto_short")
  2869.     oClearAllCmd.ShortDescription = FormatStr("clearall_auto_short")
  2870.  
  2871.     AddVolumeParameter()
  2872.     BdeArgs.AddParam oEnableCmd
  2873.     BdeArgs.AddParam oDisableCmd
  2874.     BdeArgs.AddParam oClearAllCmd
  2875.  
  2876.     BdeArgs.AddExample("managee-bde -autounlock -enable E:")
  2877.     BdeArgs.AddExample("managee-bde -autounlock -disable E:")
  2878.     BdeArgs.AddExample("managee-bde -autounlock -ClearAllKeys C:")
  2879.  
  2880.     BdeArgs.SetContinuation GetRef("DoAutounlock"), Empty
  2881. End Function
  2882.  
  2883. Function Cmd_Force(arg)
  2884.  
  2885.     BdeArgs.ClearCommands()
  2886.     BdeArgs.SetPreamble 8,FormatStr("force_preamble")
  2887.     BdeArgs.SetDescription(GLR.Localize("fr_desc"))
  2888.  
  2889.     AddVolumeParameter()
  2890.  
  2891.     BdeArgs.AddExample("manage-bde -fr")
  2892.     BdeArgs.AddExample("manage-bde -forcerecovery x:")
  2893.  
  2894.     BdeArgs.SetContinuation GetRef("DoForce"), Empty
  2895. End Function
  2896.  
  2897. Function Cmd_Lock(arg)
  2898.     Dim oForceParam
  2899.  
  2900.     Set oForceParam = new BdeArgElem
  2901.     BdeArgs.ClearCommands()
  2902.     BdeArgs.SetPreamble 8,FormatStr("lock_preamble")
  2903.     BdeArgs.SetDescription(GLR.Localize("lock_desc"))
  2904.  
  2905.     oForceParam.Init     kPARAM_PRM, "forcedismount","fd"   ,kARG_BOOL      ,Empty                ,False, False ,False
  2906.     oForceParam.SetUsage kUSAGE_CMN, "-ForceDismount or -fd"       ,GLR.Localize("fdusage_lock")
  2907.  
  2908.     AddVolumeParameter()
  2909.     BdeArgs.AddParam oForceParam
  2910.  
  2911.     BdeArgs.AddExample("manage-bde -lock e:")
  2912.     BdeArgs.AddExample("manage-bde -lock e: -ForceDismount")
  2913.  
  2914.     BdeArgs.SetContinuation GetRef("DoLock"), Empty
  2915. End Function
  2916.  
  2917. Function Cmd_Tpm(arg)
  2918.     Dim oOnParam,oOwnParam
  2919.  
  2920.     Set oOnParam   = new BdeArgElem
  2921.     Set oOwnParam  = new BdeArgElem
  2922.     BdeArgs.ClearCommands()
  2923.     BdeArgs.SetPreamble 12,FormatStr("tpm_preamble")
  2924.     BdeArgs.SetDescription(GLR.Localize("tpmcmd_desc"))
  2925.     BdeArgs.ShortDescription = FormatStr("tpm_desc_upper")
  2926.  
  2927.     oOnParam.Init   kPARAM_CMD, "TurnOn"        , "t", kARG_BOOL, Empty, False, False, False
  2928.     oOwnParam.Init  kPARAM_CMD, "TakeOwnership" , "o", kARG_STR , Empty, False, False, True
  2929.  
  2930.     oOnParam.SetUsage   kUSAGE_CMN, "-TurnOn or -t"       , GLR.Localize("turnon_usage")
  2931.     oOwnParam.SetUsage  kUSAGE_CMN, "-TakeOwnership or -o", GLR.Localize("own_usage")
  2932.  
  2933.     oOnParam.ShortDescription = FormatStr("turnon_short")
  2934.     oOwnParam.ShortDescription = FormatStr("own_short")
  2935.  
  2936.     BdeArgs.AddParam oOnParam
  2937.     BdeArgs.AddParam oOwnParam
  2938.  
  2939.     BdeArgs.AddExample("manage-bde -tpm -TurnOn")
  2940.     BdeArgs.AddExample("manage-bde -tpm -TakeOwnership test_password")
  2941.  
  2942.     BdeArgs.SetContinuation GetRef("DoTpm"), Empty
  2943. End Function
  2944.  
  2945. '------------------- MAIN BODY -----------------------'
  2946. Dim oStatusCmd,oOffCmd,oOnCmd,oUnLockCmd
  2947. Dim oLockCmd,oProtCmd,oAutoCmd,oForceCmd
  2948. Dim oPauseCmd,oResumeCmd,oTpmCmd
  2949. Set oStatusCmd  = new BdeArgElem
  2950. Set oOffCmd     = new BdeArgElem
  2951. Set oOnCmd  = new BdeArgElem
  2952. Set oUnlockCmd  = new BdeArgElem
  2953. Set oLockCmd    = new BdeArgElem
  2954. Set oProtCmd    = new BdeArgElem
  2955. Set oAutoCmd    = new BdeArgElem
  2956. Set oUnlockCmd  = new BdeArgElem
  2957. Set oForceCmd   = new BdeArgElem
  2958. Set oPauseCmd   = new BdeArgElem
  2959. Set oResumeCmd  = new BdeArgElem
  2960. Set oTpmCmd     = new BdeArgElem
  2961.  
  2962. oStatusCmd.Init  kPARAM_CMD , "status"  ,""      ,kARG_FUNC, GetRef("Cmd_Status")    ,Empty, False,False
  2963. oOffCmd.Init     kPARAM_CMD , "off"     ,""      ,kARG_FUNC, GetRef("Cmd_Off")       ,Empty, False,False
  2964. oOnCmd.Init      kPARAM_CMD , "on"  ,""          ,kARG_FUNC, GetRef("Cmd_On")    ,Empty, False,False
  2965. oUnlockCmd.Init  kPARAM_CMD , "unlock"  ,""      ,kARG_FUNC, GetRef("Cmd_Unlock")    ,Empty, False,False
  2966. oLockCmd.Init    kPARAM_CMD , "lock"    ,""      ,kARG_FUNC, GetRef("Cmd_Lock")      ,Empty, False,False
  2967. oProtCmd.Init    kPARAM_CMD ,"protectors",""     ,kARG_FUNC, GetRef("Cmd_Protectors"),Empty, False,False
  2968. oAutoCmd.Init    kPARAM_CMD ,"autounlock",""     ,kARG_FUNC, GetRef("Cmd_Autounlock"),Empty, False,False
  2969. oForceCmd.Init   kPARAM_CMD ,"fr","forcerecovery",kARG_FUNC, GetRef("Cmd_Force")     ,Empty, False,False
  2970. oPauseCmd.Init   kPARAM_CMD ,"pause"    ,""      ,kARG_FUNC, GetRef("Cmd_Pause")     ,Empty, False,False
  2971. oResumeCmd.Init  kPARAM_CMD ,"resume"  ,""       ,kARG_FUNC, GetRef("Cmd_Resume")    ,Empty, False,False
  2972. oTpmCmd.Init     kPARAM_CMD ,"tpm"     ,""       ,kARG_FUNC, GetRef("Cmd_Tpm")       ,Empty, False,False
  2973.  
  2974.  
  2975. oStatusCmd.SetUsage kUSAGE_CMN,"-status",               GLR.Localize("status_desc")
  2976. oOffCmd.SetUsage    kUSAGE_CMN,"-off",                  GLR.Localize("off_desc_upper")
  2977. oOnCmd.SetUsage     kUSAGE_CMN,"-on",               GLR.Localize("on_desc_upper")
  2978. oUnlockCmd.SetUsage kUSAGE_CMN,"-unlock",               GLR.Localize("unlock_short")
  2979.  
  2980. oLockCmd.SetUsage   kUSAGE_CMN,"-lock",                 GLR.Localize("lock_desc_upper")
  2981. oProtCmd.SetUsage   kUSAGE_CMN,"-protectors",           GLR.Localize("prot_desc_upper")
  2982. oAutoCmd.SetUsage   kUSAGE_CMN,"-autounlock",           GLR.Localize("auto_desc_upper")
  2983. oForceCmd.SetUsage  kUSAGE_CMN,"-ForceRecovery or -fr",GLR.Localize("fr_desc_upper")
  2984. oPauseCmd.SetUsage  kUSAGE_CMN,"-pause",                GLR.Localize("pause_desc_upper")
  2985. oResumeCmd.SetUsage kUSAGE_CMN,"-resume",               GLR.Localize("resume_desc_upper")
  2986. oTpmCmd.SetUsage    kUSAGE_CMN,"-tpm",                  GLR.Localize("tpm_desc_upper")
  2987.  
  2988. '---- Common Parameters ---'
  2989. BdeArgs.AddParam(oStatusCmd)
  2990. BdeArgs.AddParam(oOnCmd)
  2991. BdeArgs.AddParam(oOffCmd)
  2992.  
  2993. BdeArgs.AddParam(oPauseCmd)
  2994. BdeArgs.AddParam(oResumeCmd)
  2995. BdeArgs.AddParam(oLockCmd)
  2996. BdeArgs.AddParam(oUnlockCmd)
  2997. BdeArgs.AddParam(oAutoCmd)
  2998. BdeArgs.AddParam(oProtCmd)
  2999. BdeArgs.AddParam(oTpmCmd)
  3000. BdeArgs.AddParam(oForceCmd)
  3001.  
  3002. BdeArgs.SetPreamble 4, Vbsprintf(GLR.Localize("main_args"),Array("manage-bde[.wsf]"))
  3003. BdeArgs.SetDescription(GLR.Localize("main_desc"))
  3004.  
  3005. BdeArgs.AddExample("manage-bde -status")
  3006. BdeArgs.AddExample("manage-bde -on C: -RecoveryPassword -RecoveryKey F:\")
  3007. BdeArgs.AddExample("manage-bde -unlock E: -RecoveryKey F:\84E151C1...7A62067A512.bek")
  3008.  
  3009. BdeArgs.ParseArgs()
  3010.  
  3011. '-----------------------------------------'
  3012. '--------------- ON ------------------'
  3013. '-----------------------------------------'
  3014. Function DoOn(arg)
  3015.     Dim bTPM,bTPMPresent,bTPMAvailable
  3016.     Dim sRecoveryKey,bRecoveryKey,bRecoveryKeyPresent
  3017.     Dim sTPM_Key,bTPM_Key,bTPM_KeyPresent
  3018.     Dim sExtraKey,bExtraKey
  3019.     Dim sTPM_PIN,bTPM_PIN,bTPM_PINPresent
  3020.     Dim bAutoUnlock
  3021.     Dim sPassword,bPasswordPresent,bPassword
  3022.     Dim nEncryption
  3023.     Dim oVolume
  3024.     Dim nLockStatus,nConversionStatus,nEncryptPercentage
  3025.     Dim nProtectionStatus
  3026.     Dim rc,sKeyProtector,sVolName
  3027.     Dim aKeyProtectors
  3028.     Dim bWasDecrypted
  3029.     Dim bDoHardwareTest
  3030.  
  3031.     BdeCommonStartup()
  3032.     nEncryption = BdeArgs.GetArg("em")
  3033.  
  3034.     Set oVolume = new VolumeObject
  3035.     oVolume.CreateByReference(GetEncryptableVolume())
  3036.     
  3037.     WScript.StdOut.WriteLine FormatStr2("bdeexamine",Array(BdeArgs.GetArg("volumeletter")))
  3038.     WScript.StdOut.WriteLine oVolume.PrintOSVolume()
  3039.  
  3040.     'Ensure that the disk is unlocked before proceeding
  3041.     If oVolume.IsLocked() Then
  3042.         Fail FormatStr("disklock_fail")
  3043.     End If
  3044.  
  3045.     If oVolume.IsDecrypted() Then
  3046.  
  3047.         bWasDecrypted = True
  3048.  
  3049.         '------ ProtectorsAdd REQUIRES that there be a -tpm parameter -------'
  3050.         Dim oTPMParam
  3051.         Set oTPMParam = new BdeArgElem
  3052.         oTPMParam.Init kPARAM_PRM, "tpm", "", kARG_BOOL , Empty, Empty, False, False
  3053.         BdeArgs.AddParam(oTpmParam)
  3054.         '--------------------------'
  3055.  
  3056.         '---- Check availability of TPM on OS volume only ----'
  3057.         If oVolume.IsOsVolume() Then
  3058.             bTpmAvailable = BdeCommonCheckTpmCapability()
  3059.  
  3060.             '---- Default behavior, if nothing is specified use the TPM -----'
  3061.             If bTPMAvailable Then
  3062.                 If  Not(BdeArgs.IsSet("tsk")) And _
  3063.                     Not(BdeArgs.IsSet("tp")) And _
  3064.                     Not(BdeArgs.IsSet("tpsk")) And _
  3065.                     Not( oVolume.UsesAnyTPM() ) Then
  3066.  
  3067.                     BdeArgs.SetArg "tpm",True
  3068.                 End If
  3069.             Else
  3070.                 If Not(BdeArgs.IsSet("sk")) And _
  3071.                    Not(oVolume.UsesKey()) Then
  3072.  
  3073.                    Fail FormatStr("sk_required")
  3074.                 End If
  3075.             End If
  3076.         End If
  3077.  
  3078.         '--- If no password is set for this volume error out to the user ---'
  3079.         If Not(BdeArgs.IsSet("rp")) _
  3080.             And Not( oVolume.UsesPassword() ) Then
  3081.  
  3082.             If BdePolicyAllowsPassword() Then
  3083.  
  3084.                 Fail FormatStr("no_recovery_password")
  3085.             ElseIf Not BdeArgs.IsSet("rk") _
  3086.                 And Not oVolume.UsesKey() Then
  3087.  
  3088.                 Fail FormatStr("no_recovery_key")
  3089.             End If
  3090.         End If
  3091.  
  3092.         ProtectorsAdd(oVolume)
  3093.  
  3094.         bDoHardwareTest = Not(BdeArgs.IsSet("s")) And oVolume.IsOsVolume()
  3095.  
  3096.         If bDoHardwareTest Then
  3097.             oVolume.EncryptAfterHardwareTest nEncryption
  3098.         Else
  3099.             oVolume.Encrypt nEncryption
  3100.         End If
  3101.     Else
  3102.         bWasDecrypted = False
  3103.         oVolume.Encrypt nEncryption
  3104.  
  3105.         WScript.StdOut.WriteLine GLR.Localize("no_key_protectors")
  3106.     End If
  3107.  
  3108.     If bWasDecrypted Then
  3109.         If bDoHardwareTest Then
  3110.             ProduceHardwareTestOutput(oVolume)
  3111.         Else
  3112.             WScript.StdOut.WriteLine FormatStr("encrypt_started")
  3113.         End If
  3114.  
  3115.     ElseIf oVolume.IsEncrypted() Then
  3116.         WScript.StdOut.WriteLine GLR.Localize("encrypt_complete")
  3117.     Else
  3118.         WScript.StdOut.WriteLine GLR.Localize("encrypt_progress")
  3119.     End If
  3120.  
  3121.     If oVolume.IsEncrypted() Then
  3122.         If oVolume.IsProtected() Then
  3123.             WScript.StdOut.WriteLine FormatStr("on_already")
  3124.         Else
  3125.             WScript.StdOut.WriteLine FormatStr("on_enabled")
  3126.         End If
  3127.     End If
  3128.  
  3129.     oVolume.EnableKeyProtectors()
  3130.  
  3131. End Function
  3132.  
  3133. Function ProtectorsAdd(oEncVolume)
  3134.     ProtectorsAddFlag oEncVolume,False
  3135. End Function
  3136.  
  3137. Function ProtectorsAddFlag(oVolume,tFail)
  3138.     Dim bTPM,bTPMPresent,bTPMAvailable
  3139.     Dim sRecoveryKey,bRecoveryKey,bRecoveryKeyPresent
  3140.     Dim sTPM_Key,bTPM_Key,bTPM_KeyPresent
  3141.     Dim sExtraKey,bExtraKey
  3142.     Dim sTPM_PIN,bTPM_PIN,bTPM_PINPresent
  3143.     Dim sTPM_PIN_Key,bTPM_PIN_Key,bTPM_PIN_KeyPresent
  3144.     Dim bAutoUnlock
  3145.     Dim sPassword,bPasswordPresent,bPassword
  3146.     Dim nEncryption
  3147.     Dim nLockStatus,nConversionStatus,nEncryptPercentage
  3148.     Dim nProtectionStatus
  3149.     Dim rc,sKeyProtector,sVolName
  3150.     Dim aKeyProtectors,nDeleteType
  3151.  
  3152.     sRecoveryKey = BdeArgs.GetArg("recoverykey")
  3153.     bRecoveryKey = BdeArgs.IsSet( "recoverykey")
  3154.     bRecoveryKeyPresent = oVolume.UsesKey()
  3155.  
  3156.     sTPM_Key      = BdeArgs.GetArg("tsk")
  3157.     bTPM_Key      = BdeArgs.IsSet( "tsk")
  3158.     bTPM_KeyPresent = oVolume.UsesTPMAndKey()
  3159.  
  3160.     sExtraKey     = BdeArgs.GetArg("startupkey")
  3161.     bExtraKey     = BdeArgs.IsSet( "startupkey")
  3162.  
  3163.     sPassword     = BdeArgs.GetArg("recoverypassword")
  3164.     bPassword     = BdeArgs.IsSet( "recoverypassword")
  3165.     bPasswordPresent = oVolume.UsesPassword()
  3166.  
  3167.     sTPM_PIN      = BdeArgs.GetArg("tp")
  3168.     bTPM_PIN      = BdeArgs.IsSet( "tp")
  3169.     bTPM_PINPresent = oVolume.UsesTPMAndPIN()
  3170.  
  3171.     sTPM_PIN_Key      = BdeArgs.GetArg("tpsk")
  3172.     bTPM_PIN_Key      = BdeArgs.IsSet( "tpsk")
  3173.     bTPM_PIN_KeyPresent = oVolume.UsesTPMAndPINAndKey()
  3174.  
  3175.     bTPM          = BdeArgs.GetArg("tpm")
  3176.     bTPMPresent   = oVolume.UsesTPM()
  3177.     bTPMAvailable = False
  3178.  
  3179.     sVolName      = BdeArgs.GetArg("volumeletter")
  3180.     nDeleteType = Empty
  3181.  
  3182.     If (bTPM Or bTPM_PIN Or bTPM_Key Or bTPM_PIN_Key) And Not oVolume.IsOSVolume() Then
  3183.         Fail(GLR.Localize("not_os_volume_error"))
  3184.     End if
  3185.  
  3186.     If (bTPM Or bTPM_PIN Or bTPM_Key Or bTPM_PIN_Key) Then
  3187.         If Not(BdeCommonCheckTpmCapability()) Then
  3188.             Fail(GLR.Localize("no_tpm_error"))
  3189.         End If
  3190.     End If
  3191.  
  3192.     If (bTPM_PIN_Key And ((Not bTPM_PIN) Or (Not bTPM_Key))) Then
  3193.         Fail(GLR.Localize("tpsk_parameters_missing"))
  3194.     End if
  3195.  
  3196.     If bRecoveryKey Or bExtraKey Or bPassword Or bTPM Or bTPM_PIN _
  3197.         Or bTPM_Key Or bTPM_PIN_Key Then 
  3198.         WScript.StdOut.WriteLine GLR.Localize("key_protectors_added") & vbCrLf
  3199.     End If
  3200.     'Now set up the drive to be protected via the
  3201.     'Specified Method
  3202.     '--------------------------'
  3203.     If bRecoveryKey Then
  3204.         sKeyProtector = oVolume.AddExternalKey()
  3205.  
  3206.         oVolume.DoKeyProtector sKeyProtector,sRecoveryKey
  3207.     End If
  3208.  
  3209.     If bExtraKey Then
  3210.         sKeyProtector = oVolume.AddExternalKey()
  3211.  
  3212.         oVolume.DoKeyProtector sKeyProtector,sExtraKey
  3213.     End If
  3214.  
  3215.     If bPassword Then
  3216.         sKeyProtector = oVolume.AddPassword(sPassword)
  3217.  
  3218.         If IsEmpty(sKeyProtector) Then
  3219.             If Not(bRecoveryKey Or bRecoveryKeyPresent) Then
  3220.                 Fail GLR.Localize("no_recovery_key")
  3221.             End If
  3222.  
  3223.             '---- We're not failing, so we need to indicate that this wasn't done ---'
  3224.             bPassword = False
  3225.         Else
  3226.             oVolume.DoKeyProtector sKeyProtector,empty
  3227.             sPassword = oVolume.GetPassword(sKeyProtector)
  3228.         End If
  3229.     End If
  3230.  
  3231.     'TPM only
  3232.     '----------------------'
  3233.     If bTPM Then
  3234.         sKeyProtector = oVolume.AddTpm()
  3235.         oVolume.DoKeyProtector sKeyProtector,empty
  3236.     End If
  3237.     '------------------------'
  3238.  
  3239.     'TPM and Numeric PIN
  3240.     '----------------------'
  3241.     If (Not bTPM_PIN_Key) And bTPM_PIN Then
  3242.         sKeyProtector = oVolume.AddTpmAndPIN(sTPM_PIN)
  3243.         oVolume.DoKeyProtector sKeyProtector,empty
  3244.     End If
  3245.  
  3246.     'TPM and External Key
  3247.     '-----------------------'
  3248.     If (Not bTPM_PIN_Key) And bTPM_Key Then
  3249.         sKeyProtector = oVolume.AddTpmAndKey()
  3250.         oVolume.DoKeyProtector sKeyProtector,sTPM_Key
  3251.     End If
  3252.  
  3253.     'TPM and Numeric PIN and External Key
  3254.     '-----------------------'
  3255.     If bTPM_PIN_Key and bTPM_PIN and bTPM_Key Then
  3256.         sKeyProtector = oVolume.AddTpmAndPINAndKey(sTPM_PIN)
  3257.         oVolume.DoKeyProtector sKeyProtector,sTPM_Key
  3258.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN
  3259.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_KEY
  3260.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM
  3261.     End If
  3262.  
  3263.     If (Not bTPM_PIN_Key) And (bTPM_PIN Or bTPM_Key) Then
  3264.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM
  3265.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
  3266.     End If
  3267.  
  3268.     If bTPM Then
  3269.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN
  3270.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_KEY
  3271.         oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
  3272.     End If
  3273.  
  3274.     If bPassword Then
  3275.         ProduceRecoveryPasswordOutput oVolume,sPassword
  3276.     End If
  3277.  
  3278.     If Not(bRecoveryKey Or bExtraKey Or bPassword Or bTpm _
  3279.         Or bTPM_PIN Or bTPM_Key Or bTPM_PIN_Key Or bExtraKey) and tFail Then
  3280.         Fail GLR.Localize("protectors_not_added")
  3281.     End If
  3282.  
  3283. End Function
  3284.  
  3285. '--------------------------------------------'
  3286. '------------------ autounlock --------------'
  3287. '--------------------------------------------'
  3288. Function DoAutounlock(arg)
  3289.     Dim oVolume,bEnable,bDisable,nLockStatus,bClearAll
  3290.     Dim sKeyProtector,bIsAutoUnlockEnabled
  3291.  
  3292.     bIsAutoUnlockEnabled = False
  3293.  
  3294.     bEnable  = BdeArgs.GetArg("enable")
  3295.     bDisable = BdeArgs.GetArg("disable")
  3296.     bClearAll = BdeArgs.IsSet("clearallkeys")
  3297.  
  3298.     BdeCommonStartup()
  3299.     Set oVolume = new VolumeObject
  3300.     oVolume.CreateByReference(GetEncryptableVolume())
  3301.  
  3302.     If bEnable And bDisable Then
  3303.         Fail GLR.Localize("both_enable_dis_error")
  3304.     End If
  3305.  
  3306.     If oVolume.IsLocked() Then
  3307.         Fail FormatStr("disklock_fail")
  3308.     End If
  3309.  
  3310.     If bEnable Or bDisable Then
  3311.         If Not(oVolume.IsDataVolume()) Then
  3312.             Fail FormatStr("not_data_volume_error")
  3313.         End If
  3314.  
  3315.         bIsAutoUnlockEnabled = oVolume.IsAutoUnlockEnabled(sKeyProtector)
  3316.  
  3317.         If bEnable Then
  3318.             If bIsAutoUnlockEnabled Then
  3319.                 Fail GLR.Localize("volume_bound_error")
  3320.             End If
  3321.  
  3322.             sKeyProtector = oVolume.EnableAutoUnlock()
  3323.  
  3324.             WScript.StdOut.WriteLine GLR.Localize("key_protectors_added")
  3325.  
  3326.             oVolume.DoKeyProtector sKeyProtector,Empty
  3327.  
  3328.         Else
  3329.             If Not(bIsAutoUnlockEnabled) Then
  3330.                 Fail GLR.Localize("volumedisabled_error")
  3331.             End If
  3332.  
  3333.             oVolume.DisableAutoUnlock()
  3334.  
  3335.             BdeArgs.FormatLine 0,VBsprintf(GLR.Localize("autounlock_disable_msg"),_
  3336.                                  Array(sKeyProtector))
  3337.         End If
  3338.     End If
  3339.  
  3340.     If bClearAll Then
  3341.         If Not(oVolume.IsOsVolume()) Then
  3342.             Fail FormatStr("clearall_notos")
  3343.         End If
  3344.  
  3345.         oVolume.ClearAllAutoUnlockKeys()
  3346.  
  3347.         BdeArgs.FormatLine 0,VBSprintf(GLR.Localize("clearall_msg"),_
  3348.                                        Array(oVolume.DriveLetter))
  3349.     End If
  3350.  
  3351. End Function
  3352.  
  3353. '--------------------------------------------'
  3354. '------------------ unlock ------------------'
  3355. '--------------------------------------------'
  3356. Function DoUnlock(arg)
  3357.     Dim oVolume
  3358.     Dim sRecoveryFile,sPassword
  3359.  
  3360.     BdeCommonStartup()
  3361.  
  3362.     Set oVolume = new VolumeObject
  3363.     oVolume.CreateByReference(GetEncryptableVolume())
  3364.  
  3365.     sRecoveryFile = BdeArgs.GetArg("recoverykey")
  3366.     sPassword     = BdeArgs.GetArg("recoverypassword")
  3367.  
  3368.     If Not(oVolume.IsLocked()) Then
  3369.         Fail GLR.Localize("diskunlocked_error")
  3370.     End If
  3371.  
  3372.     If IsEmpty(sRecoveryFile) And IsEmpty(sPassword) Then
  3373.         Fail GLR.Localize("recovery_data_needed")
  3374.     End If
  3375.  
  3376.     If Not(IsEmpty(sRecoveryFile)) Then
  3377.         oVolume.UnlockWithKeyFile(sRecoveryFile)
  3378.  
  3379.         WScript.StdOut.WriteLine VBsprintf(GLR.Localize("unlock_succ_key"),_
  3380.                                            Array(sRecoveryFile,oVolume.DriveLetter))
  3381.     End If
  3382.  
  3383.     If Not(IsEmpty(sPassword)) Then
  3384.         oVolume.UnlockWithNumericalPassword(sPassword)
  3385.  
  3386.         WScript.StdOut.WriteLine VBsprintf(GLR.Localize("unlock_succ_passw"),_
  3387.                                            Array(oVolume.DriveLetter))
  3388.     End If
  3389.  
  3390.     
  3391.  
  3392. End Function
  3393.  
  3394. '--------------------------------------------'
  3395. '------------------ Lock ------------------'
  3396. '--------------------------------------------'
  3397. Function DoLock(arg)
  3398.     Dim oVolume,tForceDismount
  3399.  
  3400.     BdeCommonStartup()
  3401.  
  3402.     Set oVolume = new VolumeObject
  3403.     oVolume.CreateByReference(GetEncryptableVolume())
  3404.  
  3405.     tForceDismount = BdeArgs.GetArg("forcedismount")
  3406.  
  3407.     If oVolume.IsLocked() Then
  3408.         Fail FormatStr("diskunlock_fail")
  3409.     End If
  3410.  
  3411.     If oVolume.IsOsVolume() Then
  3412.         Fail FormatStr("os_not_lockable")
  3413.     End If
  3414.  
  3415.     oVolume.Lock(tForceDismount)
  3416.  
  3417.     WScript.StdOut.WriteLine(VBsprintf(GLR.Localize("lock_msg"),_
  3418.                              Array(BdeArgs.GetArg("volumeletter"))))
  3419.  
  3420. End Function
  3421.  
  3422. '--------------------------------------------'
  3423. '------------------ Pause ------------------'
  3424. '--------------------------------------------'
  3425. Function DoPause(arg)
  3426.     Dim oVolume
  3427.  
  3428.     BdeCommonStartup()
  3429.  
  3430.     Set oVolume = new VolumeObject
  3431.     oVolume.CreateByReference(GetEncryptableVolume())
  3432.  
  3433.     If oVolume.IsLocked() Then
  3434.         Fail GLR.Localize("diskunlock_fail")
  3435.     End If
  3436.  
  3437.  
  3438.     If oVolume.IsPaused() Then
  3439.  
  3440.         If oVolume.IsEncrypting() Then
  3441.             WScript.StdOut.WriteLine GLR.Localize("disk_enc_already_paused")
  3442.         Else
  3443.             WScript.StdOut.WriteLine GLR.Localize("disk_dec_already_paused")
  3444.         End If
  3445.  
  3446.     Else
  3447.         If Not(oVolume.IsDecrypting() Or oVolume.IsEncrypting()) Then
  3448.             Fail FormatStr("disk_unpauseable")
  3449.         End If
  3450.  
  3451.         oVolume.PauseConversion()
  3452.  
  3453.         If oVolume.IsEncrypting() Then
  3454.             WScript.StdOut.WriteLine GLR.Localize("encryption_paused")
  3455.         Else
  3456.             WScript.StdOut.WriteLine(GLR.Localize("decryption_paused"))
  3457.         End If
  3458.  
  3459.     End If
  3460.  
  3461.     WScript.StdOut.WriteLine GLR.Localize("pause_moreinfo")
  3462. End Function
  3463.  
  3464. '--------------------------------------------'
  3465. '------------------ Resume ------------------'
  3466. '--------------------------------------------'
  3467. Function DoResume(arg)
  3468.     Dim oVolume
  3469.  
  3470.     BdeCommonStartup()
  3471.  
  3472.     Set oVolume = new VolumeObject
  3473.     oVolume.CreateByReference(GetEncryptableVolume())
  3474.  
  3475.     If oVolume.IsLocked() Then
  3476.         Fail GLR.Localize("diskunlock_fail")
  3477.     End If
  3478.  
  3479.     If oVolume.IsPaused() Then
  3480.  
  3481.         oVolume.ResumeConversion()
  3482.  
  3483.         If oVolume.IsEncrypting() Then
  3484.             WScript.StdOut.WriteLine(GLR.Localize("encryption_resumed"))
  3485.         Else
  3486.             WScript.StdOut.WriteLine(GLR.Localize("decryption_resumed"))
  3487.         End If
  3488.  
  3489.     ElseIf oVolume.IsEncrypting() Then
  3490.  
  3491.         WScript.StdOut.WriteLine( GLR.Localize("disk_already_encrypting"))
  3492.  
  3493.     ElseIf oVolume.IsDecrypting() Then
  3494.  
  3495.         WScript.StdOut.WriteLine( GLR.Localize("disk_already_decrypting"))
  3496.     Else
  3497.         Fail( FormatStr("disk_unresumeable") )
  3498.     End If
  3499.  
  3500.     WScript.StdOut.WriteLine GlR.Localize("on_moreinfo")
  3501. End Function
  3502.  
  3503. '-----------------------------------------'
  3504. '------------------ OFF ------------------'
  3505. '-----------------------------------------'
  3506. Function DoOff(arg)
  3507.     Dim nLockStatus,oVolume,bAutoKeys
  3508.  
  3509.     BdeCommonStartup()
  3510.  
  3511.     Set oVolume = new VolumeObject
  3512.     oVolume.CreateByReference(GetEncryptableVolume())
  3513.  
  3514.     If oVolume.IsLocked() Then
  3515.         Fail GLR.Localize("disklock_fail")
  3516.     End If
  3517.  
  3518.     If oVolume.IsOsVolume() Then 
  3519.         bAutoKeys = oVolume.IsAutoUnlockKeyStored()
  3520.  
  3521.         If bAutoKeys Then
  3522.             Fail VBsprintf(GLR.Localize("os_contains_keys"),Array(oVolume.DriveLetter))
  3523.         End If
  3524.     End If
  3525.  
  3526.     oVolume.Decrypt()
  3527.  
  3528.     WScript.StdOut.WriteLine GLR.Localize("bde_off_done")
  3529. End Function
  3530.  
  3531. '-----------------------------------------'
  3532. '-------------- TPM initialization--------'
  3533. '-----------------------------------------'
  3534. Function DoTpm(arg)
  3535.     Dim oTpm,oTpmService
  3536.     Dim bTurnOn,bOwn,sOwnerPassword
  3537.     Dim bActivated,bEnabled,bOwnerAllowed
  3538.     Dim bPhysicalPresenceEnabled,nPhysicalPresenceTrans
  3539.     Dim bOwned,abOwnerAuthDigest
  3540.  
  3541.     bActivated = False
  3542.     bEnabled = False
  3543.     bOwnerAllowed = False
  3544.     bPhysicalPresenceEnabled = False
  3545.     bOwned = False
  3546.  
  3547.     bTurnOn = BdeArgs.IsSet("turnon")
  3548.     bOwn    = BdeArgs.IsSet("takeownership")
  3549.     sOwnerPassword = BdeArgs.GetArg("TakeOwnership")
  3550.  
  3551.     BdeCommonStartup()
  3552.  
  3553.     Set oTpmService = GetWMIObject(skTpmPath)
  3554.  
  3555.     On Error Resume Next
  3556.     Set oTpm = oTpmService.Get("Win32_Tpm=@")
  3557.  
  3558.     If Err.Number<>0 Then 
  3559.         Fail GLR.Localize("no_tpm_detected")
  3560.     End If
  3561.     On Error GoTo 0
  3562.  
  3563.     CheckRC oTPM.IsActivated( bActivated ) ,_
  3564.             gComGLR.Localize("check_active_fail")
  3565.  
  3566.     If bActivated Then
  3567.         CheckRC oTPM.IsEnabled( bEnabled ) ,_
  3568.                 gComGLR.Localize("check_enable_fail")
  3569.  
  3570.         If bEnabled Then
  3571.             CheckRC oTPM.IsOwnershipAllowed( bOwnerAllowed ) ,_
  3572.                     gComGLR.Localize("check_owner_fail")
  3573.         End If
  3574.     End If
  3575.  
  3576.  
  3577.     '---- Turn on the TPM via a physical presence command ----'
  3578.     If bTurnOn Then
  3579.         
  3580.         '----- bOwnerAllowed indicates that the TPM is already on ---'
  3581.         If bOwnerAllowed Then
  3582.             Finish GLR.Localize("tpm_is_on")
  3583.         End If
  3584.  
  3585.         If IsEmpty(oTpm.PhysicalPresenceVersionInfo) Or _
  3586.             oTpm.PhysicalPresenceVersionInfo = "Not supported" Or _
  3587.             oTpm.PhysicalPresenceVersionInfo = "Unknown" Then
  3588.  
  3589.             Finish GLR.Localize("no_physical_presence")
  3590.         End If
  3591.  
  3592.         CheckRC oTPM.SetPhysicalPresenceRequest(kPHYS_REQ_ENABLE_ACTIVATE),_
  3593.                 GLR.Localize("phys_pres_req_error")
  3594.  
  3595.         CheckRC oTpm.GetPhysicalPresenceTransition(nPhysicalPresenceTrans),_
  3596.                 GLR.Localize("phys_pres_resp_error")
  3597.  
  3598.         If nPhysicalPresenceTrans = kTPM_TRANSITION_SHUTDOWN Then
  3599.             Finish VBsprintf(GLR.Localize("tpm_shutdown_req"),Empty)
  3600.  
  3601.         ElseIf nPhysicalPresenceTrans = kTPM_TRANSITION_RESTART Then
  3602.             Finish VBsprintf(GLR.Localize("tpm_restart_req"),Empty)
  3603.  
  3604.         Else
  3605.             Fail GLR.Localize("tpm_transition_error")
  3606.         End If
  3607.  
  3608.     End If
  3609.     '------- END Tpm On ----'
  3610.  
  3611.  
  3612.     '----- Ownership, convert to owner auth digest
  3613.     '----- Then take ownership
  3614.     If bOwn Then
  3615.  
  3616.         If Not(bOwnerAllowed) Then
  3617.             Fail VBsprintf(GLR.Localize("tpm_not_on"),empty)
  3618.         End If
  3619.  
  3620.         CheckRC oTPM.IsOwned(bOwned),_
  3621.                 GLR.Localize("isowned_error")
  3622.  
  3623.         If bOwned Then
  3624.             Finish VBsprintf(GLR.Localize("tpm_already_owned"),empty)
  3625.         End If
  3626.  
  3627.         If Len(sOwnerPassword) < kMIN_OWNER_PASSWORD_LENGTH Then
  3628.             
  3629.             Fail VBsprintf(GLR.Localize("password_length_bad"),_
  3630.                  Array(kMIN_OWNER_PASSWORD_LENGTH))
  3631.         End If
  3632.  
  3633.         CheckRC oTPM.ConvertToOwnerAuth(sOwnerPassword,abOwnerAuthDigest),_
  3634.                 GLR.Localize("convert_auth_error")
  3635.  
  3636.         CheckRC oTPM.TakeOwnership(abOwnerAuthDigest),_
  3637.                 GLR.Localize("take_owner_error")
  3638.  
  3639.         Finish VBsprintf(GLR.Localize("owner_success"),Empty)
  3640.     End If
  3641. End Function
  3642.  
  3643. '-----------------------------------------'
  3644. '-------------- ForceRecovery ------------'
  3645. '-----------------------------------------'
  3646. Function DoForce(arg)
  3647.     Dim oVolume,aProtectors,sKeyProtector
  3648.     Dim bDeleted : bDeleted = False
  3649.     Dim rc,nKeyProtType,bRpPresent,bRkPresent
  3650.     Dim nProtectionStatus
  3651.     
  3652.     BdeCommonStartup()
  3653.  
  3654.     Set oVolume = new VolumeObject
  3655.     oVolume.CreateByReference(GetEncryptableVolume())
  3656.  
  3657.     If Not( oVolume.UsesPassword() Or oVolume.UsesKey()) Then
  3658.         Fail VBSprintf(GLR.Localize("no_recovery"),Array(oVolume.DriveLetter))
  3659.     End If
  3660.  
  3661.     If Not(oVolume.IsProtected()) Then
  3662.  
  3663.         Fail VBSprintf(GLR.Localize("force_noton"),Array(oVolume.DriveLetter))
  3664.     End If
  3665.  
  3666.     aProtectors = oVolume.GetKeyProtectors(0)
  3667.  
  3668.     If UBound(aProtectors) < 0 Then
  3669.         Fail(GLR.Localize("nokeyprots"))
  3670.     End If
  3671.  
  3672.     For Each sKeyProtector In aProtectors
  3673.         nKeyProtType = oVolume.GetKeyProtectorType(sKeyProtector)
  3674.  
  3675.         If nKeyProtType = kBDE_PROTECTOR_TYPE_TPM Or _
  3676.             nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN Or _
  3677.             nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_KEY Or _
  3678.             nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN_KEY Then
  3679.  
  3680.             oVolume.DoKeyProtector sKeyProtector,Empty
  3681.         End If
  3682.     Next
  3683.  
  3684.     For Each sKeyProtector In aProtectors
  3685.         nKeyProtType = oVolume.GetKeyProtectorType(sKeyProtector)
  3686.  
  3687.         If nKeyProtType = kBDE_PROTECTOR_TYPE_TPM Or _
  3688.             nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN Or _
  3689.             nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_KEY Or _
  3690.             nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN_KEY Then
  3691.  
  3692.                oVolume.DeleteKeyProtector( sKeyProtector)
  3693.                bDeleted = True
  3694.         End If
  3695.     Next
  3696.  
  3697.     If bDeleted Then
  3698.         WScript.StdOut.WriteLine ""
  3699.     Else
  3700.         BdeArgs.FormatLine 0,VBsprintf(GLR.Localize("force_unable"),Array(oVolume.DriveLetter))
  3701.     End If
  3702.  
  3703.     BdeArgs.FormatLine 0,Vbsprintf(GLR.Localize("force_warning"),Array(oVolume.DriveLetter))
  3704.  
  3705. End Function
  3706.  
  3707. '-----------------------------------------'
  3708. '-------------- PROTECTORS ---------------'
  3709. '-----------------------------------------'
  3710. Function DoProtectors(sCommand)
  3711.     Dim oVolume,aProtectors
  3712.     Dim bDelete,bGet,bDisable,bEnable,rc
  3713.     Dim sProtector,nType,sGUID,sKeyDir
  3714.     Dim bIsAutoUnlockEnabled,sProtID
  3715.     Dim sKeyProtector,bAdd
  3716.  
  3717.     BdeCommonStartup()
  3718.  
  3719.     Set oVolume = new VolumeObject
  3720.     oVolume.CreateByReference(GetEncryptableVolume())
  3721.  
  3722.     bDelete = False
  3723.     bGet    = False
  3724.     bAdd    = False
  3725.     bDisable= False
  3726.     bEnable = False
  3727.     aProtectors = Array()
  3728.  
  3729.     Select Case sCommand
  3730.         Case "del"
  3731.             bDelete = True
  3732.         Case "get"
  3733.             bGet = True
  3734.         Case "add"
  3735.             bAdd = True
  3736.         Case "disable"
  3737.             bDisable = True
  3738.         Case "enable"
  3739.             bEnable = True
  3740.         Case Else
  3741.             WScript.StdOut.WriteLine VbSprintf(GLR.Localize("protector.bad_command"),Array(sCommand))
  3742.     End Select
  3743.  
  3744.     If bGet Or bDelete Then
  3745.         nType   = BdeArgs.GetArg("type")
  3746.         sGUID   = BdeArgs.GetArg("id")
  3747.  
  3748.         If Not(IsEmpty(nType)) And Not(IsEmpty(sGUID)) Then
  3749.             Fail GLR.Localize("protector.both_error")
  3750.         End If
  3751.  
  3752.  
  3753.         '---- Determine which protectors we're using ---'
  3754.         If IsEmpty(nType) Then
  3755.             nType = kBDE_PROTECTOR_TYPE_ANY
  3756.         End If
  3757.         
  3758.         If Not(IsEmpty(sGUID)) Then
  3759.             aProtectors = Array(sGUID)
  3760.         ElseIf IsEmpty(sGUID) Then
  3761.             aProtectors = oVolume.GetKeyProtectors(nType)
  3762.         End If
  3763.         '------------'
  3764.  
  3765.         WScript.StdOut.WriteLine FormatStr3("protector.preamble",empty,oVolume)
  3766.  
  3767.         '------ Produce preamble output info------'
  3768.         If IsEmpty(sGUID) Then
  3769.             
  3770.             If nType = kBDE_PROTECTOR_TYPE_ANY Then
  3771.                 WScript.StdOut.WriteLine FormatStr("protector.all")
  3772.             Else
  3773.                 WScript.StdOut.WriteLine FormatStr2("protector.type",_
  3774.                                                     ProtectorTypeToString(nType))
  3775.             End If
  3776.         Else
  3777.             WScript.StdOut.WriteLine FormatStr2("protector.guid",sGUID)
  3778.         End If
  3779.  
  3780.         If UBound(aProtectors) < 0 Then
  3781.            Fail GLR.Localize("protector.none")
  3782.         End If
  3783.         '-------------'
  3784.  
  3785.  
  3786.         '-------- Do the actual deletion --------'
  3787.         If bDelete Then
  3788.             For Each sProtector In aProtectors
  3789.                 oVolume.DoKeyProtector sProtector,Empty
  3790.             Next
  3791.  
  3792.             For Each sProtector In aProtectors
  3793.                 oVolume.DeleteKeyProtector sProtector
  3794.             Next
  3795.  
  3796.         End If
  3797.         '--------------'
  3798.  
  3799.         '------- Display the Key Protectors ------'
  3800.         If bGet Then
  3801.             sKeyDir = BdeArgs.GetArg("saveexternalkey")
  3802.  
  3803.             For Each sKeyProtector In aProtectors
  3804.                 oVolume.DoKeyProtector sKeyProtector,sKeyDir
  3805.             next
  3806.         End If
  3807.         '-----------------'
  3808.  
  3809.     End If
  3810.  
  3811.     If bDisable Then
  3812.         '----------Disable all BDE Keys -------------'
  3813.         oVolume.DisableKeyProtectors()
  3814.  
  3815.         WScript.StdOut.WriteLine VBsprintf(GLR.Localize("protector.disable"),empty)
  3816.     End If
  3817.  
  3818.     If bEnable Then
  3819.         '----------Enable all BDE Keys -------------'
  3820.         oVolume.EnableKeyProtectors()
  3821.  
  3822.         WScript.StdOut.WriteLine VBsprintf(GLR.Localize("protector.enable"),empty)
  3823.     End If
  3824.  
  3825.     If bAdd Then
  3826.         ProtectorsAddFlag oVolume,True
  3827.     End If
  3828.  
  3829. End function
  3830.  
  3831.  
  3832. Dim g_RecoveryPasswordOutputProduced
  3833. g_RecoveryPasswordOutputProduced = False
  3834.  
  3835. '----- This function produces the warning message for saving
  3836. '----- the password provided.  If sPassword is empty it finds the first
  3837. '----- password on the disk and uses that for the message.  If none
  3838. '----- are found, no message is produced.
  3839. Function ProduceRecoveryPasswordOutput(oVolume,sPassword)
  3840.     Dim aProtectors
  3841.  
  3842.     If Not g_RecoveryPasswordOutputProduced Then
  3843.         If IsEmpty(sPassword) Then
  3844.             
  3845.             aProtectors = oVolume.GetKeyProtectors(kBDE_PROTECTOR_TYPE_PASSWORD)
  3846.  
  3847.             If UBound(aProtectors) > -1 Then
  3848.                 sPassword = oVolume.GetPassword(aProtectors(0))
  3849.             End If
  3850.  
  3851.         End If
  3852.  
  3853.         If Not(IsEmpty(sPassword)) Then
  3854.             g_RecoveryPasswordOutputProduced = True
  3855.  
  3856.             WScript.StdOut.WriteLine FormatStr("on_warning")
  3857.             BdeArgs.FormatLine 4, FormatStr2("hardware_test_1",_
  3858.                                      Array(1,sPassword))
  3859.         End If
  3860.     End If
  3861.  
  3862.     ProduceRecoveryPasswordOutput = g_RecoveryPasswordOutputProduced
  3863. End Function
  3864.  
  3865.  
  3866. Function ProduceHardwareTestOutput(oVolume)
  3867.     Dim aProtectors,iHardware
  3868.  
  3869.     If oVolume.IsHardwareTestPending() Then
  3870.         iHardware = 1
  3871.  
  3872.         If ProduceRecoveryPasswordOutput(oVolume,Empty) Then
  3873.             iHardware = iHardware +1
  3874.         Else
  3875.             WScript.StdOut.WriteLine FormatStr("on_warning")
  3876.         End If
  3877.  
  3878.         If oVolume.UsesKey() Or oVolume.UsesTpmAndKey() Then
  3879.             WScript.StdOut.WriteLine FormatStr2("hardware_test_2",iHardware)
  3880.             iHardware = iHardware+1
  3881.         End If
  3882.  
  3883.         WScript.StdOut.WriteLine FormatStr2("hardware_test_3",iHardware)
  3884.         WScript.StdOut.WriteLine FormatStr2("hardware_test_4",iHardware+1)
  3885.     End If
  3886.  
  3887.     If oVolume.IsHardwareTestFailed() Then
  3888.         WScript.StdOut.WriteLine FormatStr2("hardware_fail",oVolume.HardwareTestError)
  3889.     End If
  3890.  
  3891. End Function
  3892.  
  3893. '-----------------------------------------'
  3894. '------------------ STATUS ---------------'
  3895. '-----------------------------------------'
  3896. Function DoStatus(arg)
  3897.     Dim aEncVolumes
  3898.     Dim oEncVolume
  3899.     Dim oVolume
  3900.     Dim oTemp
  3901.     Dim nTotalSizeGB
  3902.     Dim aTemp
  3903.     Dim oProperty
  3904.     Dim rc
  3905.     Dim sVolName
  3906.     Dim sWhere
  3907.     Dim oOutParams
  3908.     Dim bIsAutoUnlockEnabled
  3909.  
  3910.     Dim VolumeLabel
  3911.  
  3912.     sVolName = BdeArgs.GetArg("v")
  3913.  
  3914.     '--------Main Script------------'
  3915.     BdeCommonStartup()
  3916.  
  3917.     If IsEmpty(sVolName) Then
  3918.         
  3919.         'Examine all Win32 Encryptable Volumes
  3920.         Set aEncVolumes = objWMIServiceSecurity.ExecQuery("Select * from Win32_EncryptableVolume")
  3921.  
  3922.         If aEncVolumes.Count < 1 Then
  3923.             Fail GLR.Localize("status.execquery_error")
  3924.         End If
  3925.  
  3926.         WScript.StdOut.WriteLine FormatStr("status.statusdisp")
  3927.     Else
  3928.         aEncVolumes = Array(GetEncryptableVolume())
  3929.     End If
  3930.  
  3931.     For Each oEncVolume in aEncVolumes
  3932.         Set oVolume = new VolumeObject
  3933.         oVolume.CreateByReference(oEncVolume)
  3934.  
  3935.  
  3936.         '- Find the physical volume object associated with the encryptable one.
  3937.         '- THIS SHOULD NOT BE DONE IN THE OPPOSITE MANNER
  3938.         '- All encryptable volumes are associated with a physical volume
  3939.         '- However, not all physical volumes are associated with an encryptable
  3940.         '- So if you change this loop to find the physical volume first, you
  3941.         '- will get null object errors on this association.
  3942.  
  3943.         VolumeLabel = oVolume.Label
  3944.         nTotalSizeGB = oVolume.Capacity
  3945.  
  3946.         Dim aProtectors, sProtector, nKeyProtType, sProtName,sprotID
  3947.  
  3948.         sprotID = Empty
  3949.  
  3950.         WScript.StdOut.WriteLine FormatStr3("status.vol",Empty,oVolume)
  3951.         WScript.StdOut.WriteLine oVolume.PrintOSVolume()
  3952.         WScript.StdOut.WriteLine("")
  3953.  
  3954.         WScript.StdOut.WriteLine FormatStr3("status.sizedisp",Empty,oVolume)
  3955.         WScript.StdOut.WriteLine FormatStr3("status.convstat",_
  3956.                                             ConversionStatusToString(oVolume.ConversionStatus),_
  3957.                                             oVolume)
  3958.         WScript.StdOut.WriteLine FormatStr3("status.encdisp",_
  3959.                                             oVolume.EncryptionPercentage,_
  3960.                                             oVolume)
  3961.         WScript.StdOut.WriteLine FormatStr3("status.encmethdisp",_
  3962.                                             EncryptionMethodToString(oVolume.EncryptionMethod),_
  3963.                                             oVolume)
  3964.         WScript.StdOut.WriteLine FormatStr3("status.protstatus",_
  3965.                                             ProtectionStatusToString(oVolume.ProtectionStatus),_
  3966.                                             oVolume)
  3967.         WScript.StdOut.WriteLine FormatStr3("status.lockstat",_
  3968.                                             LockStatusToString(oVolume.LockStatus),_
  3969.                                             oVolume)
  3970.         '-------'
  3971.         aProtectors = oVolume.GetKeyProtectors(0)
  3972.  
  3973.         If Not(oVolume.IsOsVolume()) Then 
  3974.             bIsAutoUnlockEnabled = oVolume.IsAutoUnlockEnabled(sProtID)
  3975.  
  3976.             If bIsAutoUnlockEnabled Then
  3977.                 WScript.StdOut.WriteLine FormatStr2("status.autounlockstateon",empty)
  3978.             Else
  3979.                 WScript.StdOut.WriteLine FormatStr2("status.autounlockstateoff",empty)
  3980.             End If
  3981.  
  3982.         End if
  3983.  
  3984.         If UBound(aProtectors) < 0 Then
  3985.             WScript.StdOut.WriteLine GLR.Localize("status.nokeyprots")
  3986.         Else
  3987.             WScript.StdOut.WriteLine GLR.Localize("status.keyprot1")
  3988.  
  3989.  
  3990.             For Each sProtector In aProtectors
  3991.  
  3992.                 nKeyProtType = oVolume.GetKeyProtectorType(sProtector)
  3993.  
  3994.                 If sProtID = sProtector Then
  3995.                     WScript.StdOut.WriteLine Space(8) & ProtectorTypeToString(nKeyProtType) & " "_
  3996.                                              & GLR.Localize("status.required_auto")
  3997.                 Else
  3998.                     WScript.StdOut.WriteLine Space(8) & ProtectorTypeToString(nKeyProtType)
  3999.                 End If
  4000.  
  4001.             Next
  4002.         End If
  4003.  
  4004.         WScript.StdOut.WriteLine " "
  4005.  
  4006.         ProduceHardwareTestOutput(oVolume)
  4007.  
  4008.         If BdeArgs.GetArg("p") And Not(IsEmpty(sVolName)) Then
  4009.             If oVolume.IsProtected() Then
  4010.                 WScript.Quit 0
  4011.             Else
  4012.                 WScript.Quit 1
  4013.             End If
  4014.         End if
  4015.  
  4016.     Next
  4017.  
  4018. End Function
  4019. '-------------------------------------------------------------'
  4020. '---------------- END STATUS ---------------------------------'
  4021. '-------------------------------------------------------------'
  4022.  
  4023.     </script>
  4024. </job>
  4025. </package>