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 >
Wrap
Text File
|
2008-01-05
|
128KB
|
4,025 lines
<package>
<job id="manage-bde">
<script language="VBScript" id="language-resourcer">
'------------------------------------------------------------------------------'
'-------------Language resourcer-----------------------------------------------'
'------------------------------------------------------------------------------'
Option Explicit
'-------------Language Localizer-------------'
'- The language resourcer localizes the script
'- According to the current language
'- INI files are contained in the hex(language)
'- Directory
'- The class is instantiated for a particular
'- file and language.
Class LanguageResourcer
Private Values
Private m_sPrefix
' Get the overridden UI language.
Function GetLangID()
Dim args, lang
Set args = WScript.Arguments.Named
If args.Exists("lang") Then
lang = args.Item("lang")
GetLangID = CInt(lang)
Else
GetLangID = GetUILanguage()
End If
End Function
Sub Class_Initialize
Set Values = CreateObject("Scripting.Dictionary")
Values.CompareMode = VBTextCompare
m_sPrefix = Empty
End Sub
'Initialize the Resourcer for a particular script
'We then look up the script and fill the dictionary
'with strings for this script.
Function Initialize( sScriptName , sPrefix)
Const ForReading = 1, TristateUseDefault = -2
Dim lang, value, ini
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
lang = GetLangID()
m_sPrefix = sPrefix
'-We assume that the ini file is in (script_dir)/locale/script.ini
ini = fso.GetParentFolderName(WScript.ScriptFullName) & "\" _
& ToHex(lang) & "\" & fso.GetBaseName(sScriptName) & ".ini"
'-If it isn't there, we'll attempt to fall back to (script_dir)/script.ini
If Not fso.FileExists(ini) Then
ini = fso.GetParentFolderName(WScript.ScriptFullName) & "\" _
& fso.GetBaseName(sScriptName) & ".ini"
End If
'-If that isn't there (script_dir)/script.ini.en contains english strings
If Not fso.FileExists(ini) Then
ini = fso.GetParentFolderName(WScript.ScriptFullName) & "\" _
& fso.GetBaseName(sScriptName) & ".ini.en"
End If
If fso.FileExists(ini) Then
Dim stream, file
Debug.WriteLine "Using resource file " & ini
Set file = fso.GetFile(ini)
Set stream = file.OpenAsTextStream(ForReading, TristateUseDefault)
ReadResources( stream )
Else
WScript.StdErr.WriteLine "ERROR:Could not locate resource file " & ini
WScript.Quit -1
End If
End Function
' Get a localized resource for 'resourceID' if available;
' otherwise, get the neutral resource.
Function Localize(resourceID)
If Values.Exists(resourceID) Then
Localize = Values.Item(resourceID)
Else
WScript.StdOut.WriteLine "Localization-Warning: "&resourceID&" not found"
Localize = Empty
End If
End Function
'Read all the resource IDs and place them in the dictionary
Function ReadResources(stream)
Const ERROR_FILE_NOT_FOUND = 2
Dim ln, arr, key, value,pref_arr
Dim bLineContinuation
bLineContinuation = False
If Not IsObject(stream) Then Err.Raise ERROR_FILE_NOT_FOUND
Do Until stream.AtEndOfStream
ln = stream.ReadLine
If bLineContinuation Then
value = value & vbCrLf & ln
If IsTerminated(value) Then
AddString key,value
bLineContinuation = False
End If
End If
arr = Split(ln, "=", 2, 1)
If UBound(arr, 1) = 1 Then
If bLineContinuation Then
WScript.Quit -1
End If
' Trim the key and the value first before trimming quotes
key = Trim(arr(0))
value = Trim(arr(1))
If Not IsTerminated(value) then
bLineContinuation = True 'Tell engine to add to this line
Else
AddString key,value
End If
End If
Loop
stream.Close
End Function
Private Function AddString(key,value)
Dim sKey,sValue,pref_arr
sValue = Trim(value)
sValue = StripQuotes(Trim(sValue))
sValue = Replace(sValue,"\""","""")
sValue = Replace(sValue,"\n",VbCrLf)
sKey = key
If Not(IsEmpty(m_sPrefix)) Then
pref_arr = Split(sKey,".",2,1)
If UBound(pref_arr,1) = 1 Then
If m_sPrefix = pref_arr(0) Then
sKey = pref_arr(1)
Else
sKey = Empty
End If
Else
sKey = Empty
End If
End If
If Not IsEmpty(sKey) Then
If Values.Exists(sKey) Then
WScript.StdOut.WriteLine "ResourceID " & sKey & "Is listed twice"
Else
Values.Add sKey,sValue
End If
End If
End Function
Function IsTerminated(s)
If Len(s) > 1 Then
If InStr(Len(s), s, """", vbTextCompare) = Len(s) _
And Not InStr(Len(s)-1, s, "\""", vbTextCompare) = Len(s)-1 Then
IsTerminated = True
Else
IsTerminated = False
End If
Else
IsTerminated = False
End If
End Function
Function StripQuotes(s)
Dim c
c = """"
If Len(s) > 2 Then
If InStr(1, s, c, vbTextCompare) > 0 Then
s = Mid(s, InStr(1, s, """", vbTextCompare) + 1)
End If
If Len(s) > 0 Then
If InStr(Len(s), s, c, vbTextCompare) = Len(s) Then
s = Mid(s, 1, Len(s) - 1)
End If
End If
End If
StripQuotes = s
End Function
' Get a 4-digit hexadecimal number
Function ToHex(n)
Dim s : s = Hex(n)
ToHex = String(4 - Len(s), "0") & s
End Function
End Class
'- The global object GLR
'- is initially instantiated and represents the main
'- script which is being run
'- instantiate a more local LanguageResourcer with a
'- custom script name for included files.
Dim GLR
Set GLR = new LanguageResourcer
GLR.Initialize WScript.ScriptName,Empty
</script>
<!------------------------------------------------------>
<!-------- Parsing Library ----------------------------->
<!------------------------------------------------------>
<script language="VBScript" id="parser">
Option Explicit
'These constants are used to indicate how
'the parameter should be parsed
'func indicates to call a function
'to parse the data
Const kARG_STR = 0
Const kARG_FUNC = 1
Const kARG_BOOL = 2
'Indicates what kind of command line parameter it is
'CMD = command, only one of these may be used
'PRM = regular parameter, no special processing done
Const kPARAM_CMD = 1
Const kPARAM_PRM = 2
Const kPARAM_FREE = 3
'Which list of parameters to place the parameter in
'Advanced, common, and shared respectively
Const kUSAGE_ADV = 0
Const kUSAGE_CMN = 1
Const kUSAGE_SHR = 2
'- How many characters to wrap each line at
Const kLINE_WRAP = 79
Class ParseInfo
Private m_sArg
Private m_tDoFail
Public Property Get Argument()
Argument = m_sArg
End Property
Public Property Let Argument(InVal)
m_sArg = InVal
End Property
Public Property Let DoFail(tInVal)
m_tDoFail = tInVal
End Property
Public Function FailOnError()
FailOnError = m_tDoFail
End Function
End Class
Class BdeArgElem
Private m_nType
Private m_sName,m_aShortNames
Private m_vVal
Private m_bRequired
Private m_bArgAccepted
Private m_nParamType
Private m_Val
Private m_sDescription
Private m_sShortDescription
Private m_sInlineUsage
Private m_nUsageType
Private m_bSet
Private Sub class_initialize
m_bRequired = False
m_sDescription = GLR.Localize("parse.no_desc")
m_sShortDescription = Empty
m_sInlineUsage = "-arg val"
m_bSet = False
End Sub
Public Property Let ShortDescription(InVal)
m_sShortDescription = InVal
End Property
Public Function InlineUsage()
InlineUsage = m_sInlineUsage
End Function
Public Function Description()
Description = m_sDescription
End Function
Public Property Get ShortDescription()
If IsEmpty(m_sShortDescription) Then
ShortDescription = m_sDescription
Else
ShortDescription = m_sShortDescription
End If
End Property
Public Function Init(nParamType, sName,sShortName,nType, vVal,vDefault,bRequired, bArgAccepted)
m_nParamType = nParamType
m_sName = LCase(sName)
m_aShortNames = Split(LCase(sShortName),",")
m_nType = nType
m_bRequired = bRequired
m_bArgAccepted = bArgAccepted
m_Val = vDefault
If( IsObject(vVal) ) Then
Set m_vVal = vVal
Else
m_vVal = vVal
End If
End Function
Public Function SetUsage(nUsage,sInlineUsage, sDescription)
m_sInlineUsage = sInlineUsage
m_sDescription = sDescription
m_nUsageType = nUsage
End Function
Public Function Parse(sArg)
Parse = ParsePrivate(sArg,True)
End Function
Public Function ParseNoFail(sArg)
ParseNoFail = ParsePrivate(sArg,False)
End Function
Private Function ParsePrivate(sArg,tDoFail)
Dim sVal,oParseObj
Set oParseObj = new ParseInfo
oParseObj.Argument = sArg
oParseObj.DoFail = tDoFail
If m_bSet Then
InvalidSyntax(DisplayName())
End If
If m_nType <> kARG_FUNC And m_bArgAccepted And IsEmpty(sArg) And IsEmpty(m_Val) Then
Fail VBsprintf(GLR.Localize("parse.required_missing"),Array(m_sName))
End If
Select Case m_nType
Case kARG_STR
sVal = sArg
Case kARG_FUNC
sVal = ((m_vVal)(oParseObj))
Case kARG_BOOL
If sArg Then
sVal = True
Else
sVal = False
End If
Case Else
Fail GLR.Localize("parse.bad_elm_type")
End Select
'Null for sVal indicates that the value was not accepted.
If Not(IsNull(sVal)) Then
m_Val = sVal
ParsePrivate = True
m_bSet = True
Else
ParsePrivate = False
End If
End Function
Public function PubName()
PubName = m_sName
End function
Public Function DisplayName()
select case m_nParamType
Case kPARAM_FREE
DisplayName = m_sName
Case Else
DisplayName = "-" & m_sName
End Select
End Function
Public function Synonyms()
Synonyms = m_aShortNames
End function
Public function IsRequired()
IsRequired = m_bRequired
End function
Public function AcceptsArg()
AcceptsArg = m_bArgAccepted
End function
Public function ParamType()
ParamType = m_nParamType
End function
Public function Value()
Value = m_Val
End Function
Public Function UsageType()
UsageType = m_nUsageType
End Function
Public Function IsSet()
IsSet = m_bSet
End Function
End Class
Const kPARAM_SPACES = 12
Class BDE_Args
Private m_dArgs,m_,m_dCommands,m_dSynonyms
Private m_dRequired,m_dAll
Private m_bCommandFound
Private m_rContinuationFunction,m_vContinuationArg
private m_sPreamble,m_sDescription,m_nPreambleIndent
private m_sShortDescription
Private m_aExamples
Private m_sPrologue
Private m_aArgs
Private m_aFreeArgs
'-Set up the Argument List
'- Fills in the gScriptArgs Object as a dictionary of arguments
'----------------------------'
Public Function ClearCommands
Dim sElem,i
If Not(IsEmpty(m_dCommands)) Then
For Each sElem In m_dCommands.Keys()
m_dAll.remove(sElem)
For i=0 to UBound(m_aArgs)
If m_aArgs(i) = sElem Then
m_aArgs(i) = Empty
End If
Next
Next
End If
Set m_dCommands = Nothing
m_sShortDescription = Empty
Set m_dCommands = CreateObject("Scripting.Dictionary")
m_bCommandFound = True
m_aExamples = Array()
End Function
Public Sub AddExample(sExample)
m_aExamples = PushArray(m_aExamples,sExample)
End Sub
Private Sub Class_Initialize
Set m_dArgs = CreateObject("Scripting.Dictionary")
Set m_dRequired = CreateObject("Scripting.Dictionary")
Set m_dSynonyms = CreateObject("Scripting.Dictionary")
Set m_dAll = CreateObject("Scripting.Dictionary")
m_rContinuationFunction = Empty
m_vContinuationArg = Empty
m_sPreamble = ""
m_sDescription = GLR.Localize("parse.no_desc")
m_sPrologue = ""
m_nPreambleIndent = 4
m_aArgs = Array()
m_aFreeArgs = Array()
m_aExamples = Array()
ClearCommands()
End Sub
Public Sub FailUsage(sMsg)
WScript.StdOut.WriteLine sMsg
Usage()
WScript.Quit -1
End Sub
'Set up a function
Public Sub SetContinuation( rFunction , vArg)
Set m_rContinuationFunction = rFunction
m_vContinuationArg = vArg
End Sub
Function GetUnUsedParameterArray()
Dim aParameters,sArgName,oArg
aParameters = Array()
For Each sArgName In m_aArgs
If m_dAll.Exists(sArgName) Then
Set oArg = m_dAll.Item(sArgName)
If Not(oArg.IsSet()) Then
aParameters = PushArray(aParameters,oArg.DisplayName())
End If
End If
Next
GetUnUsedParameterArray = aParameters
End Function
Private Sub PrintList(nUsage,sHeader)
Dim oArg,bMsgPrinted,sArgName
bMsgPrinted = False
For Each sArgName In m_aArgs
If m_dAll.Exists(sArgName) Then
Set oArg = m_dAll.Item(sArgName)
If oArg.UsageType() = nUsage Then
If Not(bMsgPrinted) And Not(IsEmpty(sHeader)) Then
WScript.StdOut.WriteLine(sHeader)
bMsgPrinted = True
End If
FormatParam oArg.InlineUsage(),oArg.Description()
End If
End If
Next
End Sub
Private Sub PrintListShort(nUsage,sHeader)
Dim oArg,bMsgPrinted,sArgName
bMsgPrinted = False
For Each sArgName In m_aArgs
If m_dAll.Exists(sArgName) Then
Set oArg = m_dAll.Item(sArgName)
If oArg.UsageType() = nUsage Then
If Not(bMsgPrinted) And Not(IsEmpty(sHeader)) Then
WScript.StdOut.WriteLine(sHeader)
bMsgPrinted = True
End If
FormatParam oArg.InlineUsage(),oArg.ShortDescription
End If
End If
Next
End Sub
Public Sub Usage()
Dim sUsage,oArg,sTemp,nLen
Dim bCMNprinted,bADVprinted,bSHRprinted,i
bCMNprinted = False
bADVprinted = False
bSHRprinted = False
FormatLine m_nPreambleIndent,VBsprintf(m_sPreamble,Empty)
WScript.Stdout.WriteLine("")
WScript.Stdout.WriteLine GLR.Localize("parse.desc_str")
FormatLine 4,VBsprintf(Space(4) & m_sDescription,Empty)
WScript.StdOut.WriteLine("")
PrintList kUSAGE_CMN, GLR.Localize("parse.short_param")
PrintList kUSAGE_ADV, Empty
PrintList kUSAGE_SHR, Empty
If UBound(m_aExamples) > -1 Then
WScript.StdOut.WriteLine(GLR.Localize("parse.examples"))
For i = 0 to UBound(m_aExamples)
WScript.StdOut.WriteLine Space(4) & m_aExamples(i)
Next
End If
If Len(m_sPrologue) > 0 Then
FormatLine 4,m_sPrologue
End If
End Sub
Public Property Get ShortDescription
If IsEmpty(m_sShortDescription) Then
ShortDescription = m_sDescription
Else
ShortDescription = m_sShortDescription
End If
End Property
Public Property Let ShortDescription(sVal)
m_sShortDescription = sVal
End Property
Public Sub ShortUsage()
Dim sUsage,oArg,sTemp,nLen
Dim bCMNprinted,bADVprinted,bSHRprinted,i
bCMNprinted = False
bADVprinted = False
bSHRprinted = False
FormatLine m_nPreambleIndent,VBsprintf(m_sPreamble,Empty)
WScript.StdOut.WriteLine("")
WScript.Stdout.WriteLine GLR.Localize("parse.desc_str")
FormatLine 4,VBsprintf(Space(4) & ShortDescription,Empty)
WScript.StdOut.WriteLine("")
PrintListShort kUSAGE_CMN, GLR.Localize("parse.short_param")
PrintListShort kUSAGE_ADV, Empty
PrintListShort kUSAGE_SHR, Empty
If UBound(m_aExamples) > -1 Then
WScript.StdOut.WriteLine(GLR.Localize("parse.examples"))
For i = 0 to Min(2,UBound(m_aExamples))
WScript.StdOut.WriteLine Space(4) & m_aExamples(i)
Next
End If
End Sub
Public Sub SetPrologue(sStr)
m_sPrologue = sStr
End Sub
Public Sub FormatParam(sUsage,sDescription)
Dim nSpaces : nSpaces = 0
Dim sOutput
nSpaces = kPARAM_SPACES - Len(sUsage)
If nSpaces < 1 Then
WScript.StdOut.WriteLine(Space(4) & sUsage)
nSpaces = kPARAM_SPACES + 4
sOutput = Space(nSpaces) & sDescription
Else
sOutput = Space(4) & sUsage & Space(nSpaces) & sDescription
End If
FormatLine kPARAM_SPACES+4,sOutput
End Sub
Public Function IsSeparatorChar(ch)
Select Case ch
Case ","
IsSeparatorChar = True
Case " "
IsSeparatorChar = True
Case "."
IsSeparatorChar = True
End Select
End Function
Public Sub FormatLine(nSpaces,sLines)
Dim nLen,nOutputSpaces,aLines,sTemp
aLines = Split(sLines,vbCrLf)
If nSpaces > kLINE_WRAP Then
Fail VBsprintf(GLR.Localize("formatline_error"),Array(nSpaces))
End If
For Each sTemp In aLines
nOutputSpaces = 0
While Len(sTemp)> kLINE_WRAP - nOutputSpaces
nLen = kLINE_WRAP - nOutputSpaces
While nLen > 1 And Not( IsSeparatorChar(Mid(sTemp,nLen,1)) )
nLen = nLen -1
Wend
If nLen = 1 Then
nLen = kLINE_WRAP - nOutputSpaces
End if
WScript.StdOut.WriteLine(Space(nOutputSpaces) & Left(sTemp,nLen))
sTemp = Right(sTemp,Len(sTemp)-nLen)
sTemp = LTrim(sTemp)
nOutputSpaces = nSpaces
Wend
WScript.StdOut.WriteLine(Space(nOutputSpaces) & sTemp)
Next
End Sub
Public Sub SetPreamble(nSpaces,sStr)
m_sPreamble = sStr
m_nPreambleIndent = nSpaces
End Sub
Public Sub SetDescription(sStr)
m_sDescription = sStr
End Sub
Function AddParam(oBdeArg)
Dim sSynonym
Select Case oBdeArg.ParamType()
Case kPARAM_CMD
m_dCommands.Add oBdeArg.PubName(), oBdeArg
m_bCommandFound = False
Case kPARAM_PRM
m_dArgs.Add oBdeArg.PubName(), oBdeArg
Case kPARAM_FREE
ReDim Preserve m_aFreeArgs(UBound(m_aFreeArgs)+1)
Set m_aFreeArgs(UBound(m_aFreeArgs)) = oBdeArg
Case Else
End select
For Each sSynonym In oBdeArg.Synonyms()
m_dSynonyms.Add sSynonym, oBdeArg.PubName()
Next
ReDim Preserve m_aArgs(UBound(m_aArgs)+1)
m_aArgs(UBound(m_aArgs)) = oBdeArg.PubName()
If oBdeArg.IsRequired() Then
m_dRequired.Add oBdeArg.PubName(), oBdeArg.PubName()
End If
m_dAll.Add oBdeArg.PubName(), oBdeArg
End Function
Function GetArg(sKey)
sKey = TranslateSynonym(sKey)
If Not m_dAll.Exists(sKey) Then
WScript.StdOut.WriteLine("Key does not exist" & sKey)
End If
GetArg = m_dAll.Item(sKey).Value()
End Function
'--- Set an argument value explicitly ---'
Function SetArg(sKey,Value)
sKey = TranslateSynonym(sKey)
m_dAll.Item(sKey).Parse(Value)
End Function
Public Function IsSet(sKey)
sKey = TranslateSynonym(sKey)
If Not m_dAll.Exists(sKey) Then
WScript.StdOut.WriteLine("Key does not exist" & sKey)
End If
IsSet = m_dAll.Item(sKey).IsSet()
End Function
Private Function TranslateSynonym(sName)
sName = LCase(sName)
If m_dSynonyms.Exists(sName) Then
TranslateSynonym = m_dSynonyms.Item(sName)
Else
TranslateSynonym = sName
End If
End Function
'If an argument is required, calling this function
'Will mark it as having been used and not cause
Private Function RemoveRequired(sArg)
If m_dRequired.Exists(sArg) Then
m_dRequired.Remove(sArg)
End If
End Function
Private Function FindFreeArgNoFail(sArg)
FindFreeArgNoFail = FindFreeArgFlag(sArg,False)
End Function
Private Function FindFreeArg(sArg)
FindFreeArg = FindFreeArgFlag(sArg,True)
End Function
'Search the list of free arguments.
'Find the first one that successfully parses the argument
Private Function FindFreeArgFlag(sArg,tDoFail)
Dim i,tArgParsed
tArgParsed = False
For i = 0 To UBound(m_aFreeArgs)
If Not(IsEmpty(m_aFreeArgs(i))) Then
If m_aFreeArgs(i).ParseNoFail(sArg) Then
tArgParsed = True
RemoveRequired(m_aFreeArgs(i).PubName())
m_aFreeArgs(i) = Empty
End If
End If
Next
If Not(tArgParsed) and tDoFail Then
InvalidSyntax(sArg)
End If
FindFreeArgFlag = tArgParsed
End Function
Function ParseArgs()
Dim iArg,sArg,sArgVal,bNextArg,sArgRef
Dim fFun,sVal,oArgRef
Dim ParseResult
bNextArg = False
oArgRef = Empty
'---------Main body of argument parsing
For iArg = 0 To WScript.Arguments.Count - 1
sArg = WScript.Arguments(iArg)
'-Command switch with - in front of it
If Left(sArg,2) = "/?" Then
DoHelp(Empty)
ElseIf Left(sArg,1) = "-" Then
If bNextArg Then
oArgRef.Parse(Empty)
bNextArg = False
End If
'--- All arguments case insensitive
sArg = Right(LCase(sArg),Len(sArg)-1)
sArg = TranslateSynonym(sArg)
'----- Case #1 ----------'
'Argument is -switch
If m_dArgs.Exists(sArg) Then
Set oArgRef = m_dArgs.Item(sArg)
If oArgRef.AcceptsArg() Then
bNextArg = True
Else
oArgRef.Parse(True)
End If
RemoveRequired(sArg)
'-----This is a command of some sort ----'
ElseIf m_dCommands.Exists( sArg ) Then
If m_bCommandFound Then
InvalidSyntax(WScript.Arguments(iArg))
End If
m_bCommandFound = True
Set oArgRef = m_dCommands.Item(sArg)
If oArgRef.AcceptsArg() Then
bNextArg = True
Else
oArgRef.Parse(True)
End If
Else
InvalidSyntax(WScript.Arguments(iArg))
End if
'--- End if for -arg -----'
ElseIf bNextArg Then
bNextArg = False
'- If it wasn't accepted (or errored on) then
'- We fail and have to pass it on to parse it as
'- a non-named argument
If Not(oArgRef.ParseNoFail(sArg)) Then
If Not( FindFreeArgNoFail(sArg) ) Then
'A free argument couldn't be found, parse it with failure.
oArgRef.Parse(sArg)
Else
'Parse the previous parameter as empty
oArgRef.Parse(Empty)
End If
End If
Else
'-------- Default Case-------'
FindFreeArg sArg
End If
Next
If iArg = 0 Then
DoHelp(Empty)
End If
'-----If there is a command which can be used, one of them must be used-----'
If Not m_bCommandFound Then
Fail( Vbsprintf(GLR.Localize("parse.req_param"),empty))
WScript.Quit -1
End If
'-----An argument wants a value, but none was supplied-----'
If bNextArg And oArgRef.AcceptsArg() Then
oArgRef.Parse(Empty)
End If
'-----Ensure that each required argument was passed------'
For Each sArg In m_dRequired.Items
Fail( VBsprintf(GLR.Localize("parse.isrequired"),Array(m_dAll.Item(sArg).DisplayName())))
Next
If Not(IsEmpty(m_rContinuationFunction)) Then
Call (m_rContinuationFunction) (m_vContinuationArg)
End If
End Function
End Class
Dim BdeArgs
Set BdeArgs = new BDE_Args
Function DoHelp(arg)
BdeArgs.ShortUsage()
WScript.Quit 0
End Function
Function DoLongHelp(arg)
BdeArgs.Usage()
WScript.Quit 0
End Function
Function ParseComputerName(oParseObj)
WScript.StdOut.WriteLine VBSprintf(GLR.Localize("parse.computer_display"),oParseObj.Argument)
ParseComputerName = oParseObj.Argument
End Function
Dim oHelp,oComputer,oLongHelp
Set oHelp = new BdeArgElem
Set oComputer = new BdeArgElem
Set oLongHelp = new BdeArgElem
oHelp.Init kPARAM_PRM, "?" , "" , kARG_FUNC,GetRef("DoHelp") , Empty, False, False
oLongHelp.Init kPARAM_PRM, "h" , "help" , kARG_FUNC,GetRef("DoLongHelp") , Empty, False, False
oComputer.Init kPARAM_PRM, "computername" , "cn" , kARG_FUNC ,GetRef("ParseComputerName") , "." , False, True
oHelp.SetUsage kUSAGE_SHR, "-? or /?" , GLR.Localize("parse.help_usage")
oLongHelp.SetUsage kUSAGE_SHR, "-Help or -h" , GLR.Localize("parse.longhelp_usage")
oComputer.SetUsage kUSAGE_SHR, "-ComputerName or -cn", GLR.Localize("parse.comp_usage")
BdeArgs.AddParam oComputer
BdeArgs.AddParam oHelp
BdeArgs.AddParam oLongHelp
</script>
<!------------------------------------------------------>
<!-------- BDE Common ------------------------------>
<!------------------------------------------------------>
<script language="VBScript" id="bde-common">
Option Explicit
'--- Need a separate language localizer for this included script ---'
Dim gComGLR
Set gComGLR = new LanguageResourcer
gComGLR.Initialize WScript.ScriptName,"common"
'Constants
'--------------'
Const skComputerName_Default = "."
Const skSecurityPath = "/Security/MicrosoftVolumeEncryption"
Const skTpmPath = "/Security/MicrosoftTpm"
'Common Objects
'--------------'
Dim objWMIServiceSecurity
Dim objWMIService
Dim g_sConnectionString
'---------------------------'
Function PushArray( aArr, vVal)
ReDim Preserve aArr(UBound(aArr)+1)
aArr(UBound(aArr)) = vVal
PushArray = aArr
End Function
Function Min(nVal1,nVal2)
If nVal1 < nVal2 Then
Min = nVal1
Else
Min = nVal2
End If
End Function
'CheckRC
'- Check Return Value=0
'- Fail otherwise
'--------------------'
Function CheckRC( nRC , sMsg)
Dim sErrDesc
If Not ( nRC = 0 ) Then
On Error Resume Next
Err.Raise nRC
sErrDesc = Err.description
Err.Clear()
On Error GoTo 0
FailCode VBsprintf(gComGLR.Localize("checkrc_msg"),Array(sMsg,nRC,sErrDesc)), nRC
End If
End Function
'CheckEmpty
'- Ensure that the object isn't Empty or null
'- Fail and exit function if it is
'---------------------'
Function CheckEmpty( oObj, sMsg)
If IsEmpty(oObj) Or IsNull(oObj) Then
Fail( sMsg )
End If
Set CheckEmpty = oObj
End Function
'CheckArg
'- Ensure that the argument exists
'- Fail if it doesn't.
Function CheckArg( sArgName, sMsg )
Dim ArgVal
ArgVal = gScriptArgs(sArgName)
If IsNull(ArgVal) Or IsEmpty(ArgVal) Then
Fail(sMsg & VBCRlf & gComGLR.Localize("help_message"))
End If
CheckArg = ArgVal
End Function
'Finish - Exit the Script with a message (but not an error)'
Function Finish( sMsg )
BdeArgs.FormatLine 0,sMsg
WScript.Quit 0
End Function
Function Fail (sMsg)
FailCode sMsg, -1
End Function
'Fail - Exit the Script with a message.
Function FailCode( sMsg , nExitCode)
sMsg = GLR.Localize("error_str") & sMsg
BdeArgs.FormatLine 0,sMsg
WScript.Quit nExitCode
End Function
Function InvalidSyntax(sArg)
Dim aParameters
aParameters = BdeArgs.GetUnUsedParameterArray()
BdeArgs.FormatLine 4, VBsprintf(gComGLR.Localize("err_syntax"),_
Array(sArg,Join(aParameters,", ") ) _
)
WScript.Quit -1
End Function
Function CheckErr()
If Err.Number Then
WScript.StdOut.WriteLine "------------------------------------------------------------"
WScript.StdOut.WriteLine VBsprintf(GLR.Localize("checkerr_str"),_
Array(Err.Number,Err.Description))
WScript.StdOut.WriteLine "------------------------------------------------------------"
Wscript.Quit -1
End If
End Function
'Do Common Startup options for an BDE Script
Function BdeCommonStartup()
g_sConnectionString = "winmgmts:{impersonationLevel=impersonate" & _
",authenticationLevel=pktPrivacy}!//"& _
BdeArgs.GetArg("computername") & "/root/cimv2"
On Error Resume Next
Set objWMIServiceSecurity = GetObject(g_sConnectionString & skSecurityPath)
Set objWMIService = GetObject(g_sConnectionString)
On Error GoTo 0
CheckEmpty objWMIServiceSecurity, gComGLR.Localize("WBEM_error")
CheckEmpty objWMIService, gComGLR.Localize("WMI_Error")
End Function
'Check to ensure that the TPM is available for protection
Function BdeCommonCheckTpmCapability()
Dim aTPMs,tEnabled,tOwned,rc
Dim oTPM,bTpmOkay,bActivated,bSrkCompat
bTpmOkay = False
Set aTPMs = GetWMIObject(skTpmPath & ":Win32_Tpm").Instances_
CheckErr()
'----WARNING: this code really assumed you have one TPM which is
'---- owned and capable of being used with the OS volume
'---- this likely won't work for more than one TPM.
For Each oTPM In aTPMs
CheckRC oTPM.IsEnabled( tEnabled ) ,_
gComGLR.Localize("check_enable_fail")
'-- Each consecutive check requires that the previous one didn't fail --'
If tEnabled Then
CheckRC oTPM.IsOwned( tOwned ) ,_
gComGLR.Localize("check_owner_fail")
If tOwned Then
CheckRC oTPM.IsActivated( bActivated ) ,_
gComGLR.Localize("check_active_fail")
If bActivated Then
CheckRC oTPM.IsSrkAuthCompatible( bSrkCompat ) ,_
gComGLR.Localize("check_srk_fail")
If bSrkCompat Then
bTpmOkay = True
Else
Fail VBsprintf(gComGLR.Localize("tpm_notcompat"),empty)
End If
Else
Fail VBsprintf(gComGLR.Localize("tpm_notactivated"),empty)
End If
Else
Fail VBsprintf(gComGLR.Localize("tpm_notowned"),empty)
End If
Else
Fail VBsprintf(gComGLR.Localize("tpm_notenabled"),empty)
End If
Next
BdeCommonCheckTpmCapability = bTpmOkay
End Function
const HKEY_LOCAL_MACHINE = &H80000002
Function BdeCommonIsFipsEnabled()
Dim sConnectionStr,oReg,sKeyPath,sValueName,nValue,rc
sConnectionStr = "winmgmts:{impersonationLevel=impersonate" & _
",authenticationLevel=pktPrivacy}!//"& _
BdeArgs.GetArg("computername") & "\root\default:StdRegProv"
On Error Resume Next
Set oReg = GetObject(sConnectionStr)
On Error Goto 0
'We were unable to connect to the registry, warn, and then return false
If IsNull(oReg) Then
WScript.Stdout.WriteLine gComGLR.Localize("no_registry_warning")
BdeCommonIsFipsEnabled = False
End If
sKeyPath = "System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy"
sValueName = "Enabled"
rc = oReg.GetDWORDValue(HKEY_LOCAL_MACHINE,sKeyPath,sValueName,nValue)
If rc <> 0 Then
sKeyPath = "System\CurrentControlSet\Control\Lsa"
sValueName = "fipsalgorithmpolicy"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,nValue
End If
If IsEmpty(nValue) Or nValue = 0 Then
BdeCommonIsFipsEnabled = False
Else
BdeCommonIsFipsEnabled = True
End If
End Function
Function BdePolicyAllowsPassword()
BdePolicyAllowsPassword = Not BdeCommonIsFipsEnabled()
End Function
'Get an Object that's a subset of WIM
Function GetWMIObject( sPath)
Set GetWMIObject = GetObject(g_sConnectionString & sPath)
End Function
'Get The Encryptable Volume object from a physical volume
Function GetEncryptableFromPhysical( oPhysVolume )
Dim oEncVolume,oTemp,aEncVolumes
oEncVolume = null
Set oEncVolume = GetObject(g_sConnectionString & skSecurityPath & ":Win32_EncryptableVolume='"&oPhysVolume.DeviceID & "'")
If IsNull(oEncVolume) Then
Fail(gComGLR.Localize("notencryptable"))
End If
Set GetEncryptableFromPhysical = oEncVolume
End Function
'Get The Encryptable Volume object from a physical volume
Function GetPhysicalFromEncryptable( oEncVolume )
Dim oPhysVolume,oTemp,aPhysVolumes
Set oPhysVolume = GetObject(g_sConnectionString & ":Win32_Volume='" & oEncVolume.DeviceID & "'")
CheckErr()
Set GetPhysicalFromEncryptable = oPhysVolume
End Function
'
' Determines which program is being used to run this script.
' Returns True if the script host is cscript.exe
'
function IsHostCscript()
On Error Resume Next
Dim sFullName
Dim sCommand
Dim i, j
Dim bReturn
bReturn = False
sFullName = WScript.FullName
i = InStr(1, sFullName, ".exe", 1)
If i <> 0 Then
j = InStrRev(sFullName, "\", i, 1)
If j <> 0 Then
sCommand = Mid(sFullName, j+1, i-j-1)
If LCase(sCommand) = "cscript" Then
bReturn = True
End If
End If
End If
If Err <> 0 Then
WScript.Echo VBsprintf(gComGLR.Localize("cscript_detect_error"),Array(Err.Number,Err.Description))
WScript.Quit -1
End If
On Error GoTo 0
IsHostCscript = bReturn
End Function
Class ArrayLookup
Private m_aArray
Sub Class_Initialize()
m_aArray = Array()
End Sub
Public Function SetArray(vArg)
if( isArray(vArg) ) Then
m_aArray = vArg
Else
m_aArray = Array(vArg)
End If
End Function
Public function Lookup(num,format)
Dim sMsg
num = num -1
If Not(format = "%" Or format="v") And _
num < LBound(m_aArray) Or num > UBound(m_aArray) Then
Fail num & " Is out of bounds"
End If
Select Case format
Case "x"
sMsg = sMsg & "0x" & Hex(m_aArray(num))
Case "i"
sMsg = sMsg & Int(m_aArray(num))
Case "s"
sMsg = m_aArray(num)
Case "f"
sMsg = sMsg & CDbl(m_aArray(num))
Case "v"
'--- special argument for the volumeletter --'
sMsg = sMsg & BdeArgs.GetArg("v")
Case "%"
sMsg = sMsg & "%"
Case Else
sMsg = sMsg & m_aArray(num)
End Select
Lookup = sMsg
End Function
End Class
Function Vbsprintf(sFmt, aOutputs)
Dim oLookup
Set oLookup = new ArrayLookup
oLookup.SetArray(aOutputs)
Vbsprintf = VBsprintfLookup(sFmt,oLookup)
End Function
Dim gFormatRegExp
Set gFormatRegExp = new RegExp
gFormatRegExp.Pattern = "%[%0-9](![a-z]+!)?"
gFormatRegExp.Global = True
'--- oLookupObj must support Lookup(arg) and return a value ---'
Function VBsprintfLookup( sFmt, oLookupObj)
Dim iFmt
Dim iOutput,aMatches,oMatch,sType,iMatchIndex
Dim sMsg,sInsert
iFmt = 1
iOutput = 0
sMsg = ""
Set aMatches = gFormatRegExp.Execute(sFmt)
if aMatches.Count > 0 Then
For Each oMatch In aMatches
iOutput = Mid(oMatch.Value,2,1)
If iOutput = "%" Then
sInsert = "%"
Else
If Len(oMatch.Value) > 4 Then
sType = Mid(oMatch.Value,4,Len(oMatch.Value)-4)
Else
sType = "s"
End If
sInsert = oLookupObj.Lookup(iOutput,sType)
End If
iMatchIndex = oMatch.FirstIndex+1
If iFmt < iMatchIndex Then
sMsg = sMsg & Mid(sFmt,iFmt,iMatchIndex - iFmt)
End If
sMsg = sMsg & sInsert
iFmt = iMatchIndex + Len(oMatch.Value)
Next
End If
If Len(sFmt)+1 > iFmt Then
sMsg = sMsg & Mid(sFmt,iFmt,Len(sFmt)+1 - iFmt)
End If
sFmt = Empty
VBsprintfLookup = sMsg
End Function
'----------------------'
'- Arrays and functions to get and translate status information '
''''''''''''''''''''''
Function ArrayStatusToString(aArray,nStatusIndex)
If nStatusIndex <0 Or nStatusIndex > UBound(aArray) Then
ArrayStatusToString = gComGLR.Localize("Unknown")
Else
ArrayStatusToString = aArray(nStatusIndex)
End If
End Function
Const kBDE_CONVERSION_STATUS_UNKNOWN = -1
Const kBDE_CONVERSION_STATUS_DECRYPTED = 0
Const kBDE_CONVERSION_STATUS_ENCRYPTED = 1
Const kBDE_CONVERSION_STATUS_ENCRYPTING = 2
Const kBDE_CONVERSION_STATUS_DECRYPTING = 3
Const kBDE_CONVERSION_STATUS_ENCPAUSED = 4
Const kBDE_CONVERSION_STATUS_DECPAUSED = 5
'Conversion Status Translation
Dim aConversionStatusToString
aConversionStatusToString = Array( _
gComGLR.Localize("convstatus0"),_
gComGLR.Localize("convstatus1"),_
gComGLR.Localize("convstatus2"),_
gComGLR.Localize("convstatus3"),_
gComGLR.Localize("convstatus4"),_
gComGLR.Localize("convstatus5")_
)
Function ConversionStatusToString(nConversionStatus)
ConversionStatusToString = ArrayStatusToString(aConversionStatusToString,_
nConversionStatus)
End Function
Const kBDE_LOCK_STATUS_UNLOCKED = 0
Const kBDE_LOCK_STATUS_LOCKED = 1
''''''''''''''''''''''
'Lock Status Translation
Dim aLockStatusToString
aLockStatusToString = Array( _
gComGLR.Localize("lockstatus0"),_
gComGLR.Localize("lockstatus1")_
)
Function LockStatusToString(nLockStatus)
LockStatusToString = ArrayStatusToString(aLockStatusToString,_
nLockStatus)
End Function
Const kBDE_PROTECTION_STATUS_OFF = 0
Const kBDE_PROTECTION_STATUS_ON = 1
''''''''''''''''''''''
'Protection Status Translation
Dim aProtectionStatusToString
aProtectionStatusToString = Array( _
gComGLR.Localize("protstatus0"),_
gComGLR.Localize("protstatus1")_
)
Function ProtectionStatusToString(nProtectionStatus)
ProtectionStatusToString = ArrayStatusToString(aProtectionStatusToString,_
nProtectionStatus)
End Function
Const kBDE_ENCRYPTION_NONE = 0
Const kBDE_ENCRYPTION_AES128_DIFFUSER = 1
Const kBDE_ENCRYPTION_AES256_DIFFUSER = 2
Const kBDE_ENCRYPTION_AES128 = 3
Const kBDE_ENCRYPTION_AES256 = 4
''''''''''''''''''''''
'Protection Status Translation
Dim aEncryptionMethodToString
aEncryptionMethodToString = Array( _
gComGLR.Localize("encstatus0"),_
gComGLR.Localize("encstatus1"),_
gComGLR.Localize("encstatus2"),_
gComGLR.Localize("encstatus3"),_
gComGLR.Localize("encstatus4")_
)
Function EncryptionMethodToString(nEncryptionMethod)
EncryptionMethodToString = ArrayStatusToString(aEncryptionMethodToString,_
nEncryptionMethod)
End Function
Const kBDE_PROTECTOR_TYPE_ANY = 0
Const kBDE_PROTECTOR_TYPE_TPM = 1
Const kBDE_PROTECTOR_TYPE_KEY = 2
Const kBDE_PROTECTOR_TYPE_PASSWORD = 3
Const kBDE_PROTECTOR_TYPE_TPM_PIN = 4
Const kBDE_PROTECTOR_TYPE_TPM_KEY = 5
Const kBDE_PROTECTOR_TYPE_TPM_PIN_KEY = 6
''''''''''''''''''''''
'Protection Status Translation
Dim aProtectorTypeToString
aProtectorTypeToString = Array( _
gComGLR.Localize("prottype0"),_
gComGLR.Localize("prottype1"),_
gComGLR.Localize("prottype2"),_
gComGLR.Localize("prottype3"),_
gComGLR.Localize("prottype4"),_
gComGLR.Localize("prottype5"),_
gComGLR.Localize("prottype6")_
)
Function ProtectorTypeToString(nProtectorType)
ProtectorTypeToString = ArrayStatusToString(aProtectorTypeToString,_
nProtectorType)
End Function
'---- Hardware test status constants ----'
Const kBDE_HARDWARE_TEST_NONE = 0
Const kBDE_HARDWARE_TEST_FAILED = 1
Const kBDE_HARDWARE_TEST_PENDING = 2
'------ BDE error codes -------'
Dim kBDE_ERROR_NOT_DATA_VOLUME
Dim kBDE_ERROR_KEY_REQUIRED
Dim kBDE_ERROR_RELATIVE_PATH
Dim kBDE_ERROR_FIPS_POLICY
Dim kBDE_ERROR_BOOTABLE_CDDVD
kBDE_ERROR_NOT_DATA_VOLUME = CLng("&H80310019")
kBDE_ERROR_KEY_REQUIRED = CLng("&H8031001D")
kBDE_ERROR_RELATIVE_PATH = CLng("&H80310032")
kBDE_ERROR_FIPS_POLICY = CLng("&H80310037")
kBDE_ERROR_BOOTABLE_CDDVD = CLng("&H80310030")
Const kPHYS_REQ_ENABLE_ACTIVATE = 10
Const kTPM_TRANSITION_SHUTDOWN = 1
Const kTPM_TRANSITION_RESTART = 2
Const kMIN_OWNER_PASSWORD_LENGTH = 8
</script>
<script language="VBScript" id="class-library">
Option Explicit
'---- Figuring out the OS volume, makes use of this global WMI object --------'
Dim g_OSobj
g_OSobj = Empty
Function GetOSVolume()
Dim oOSService,sDriveLetter
Dim WshShell,WshSysEnv
sDriveLetter = Empty
On Error Resume Next
If IsEmpty(g_OSobj) Then
Set oOSService = GetWMIObject("")
Set g_OSobj = oOSService.Get("Win32_OperatingSystem=@")
End If
If Err.Number = 0 Then
sDriveLetter = Left(g_OSobj.WindowsDirectory,2)
End If
'Resume failing on errors
On Error GoTo 0
If IsEmpty(sDriveLetter) And BdeArgs.IsSet("cn") Then
Fail GLR.Localize("no_operatingsystem")
ElseIf IsEmpty(sDriveLetter) Then
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
sDriveLetter = Left(WshSysEnv("SYSTEMDRIVE"),2)
End If
GetOSVolume = sDriveLetter
End Function
'-----------------------'
Function IsOsVolumeName(sVolName)
If GetOsVolume() = sVolName Then
IsOsVolumeName = True
Else
IsOsVolumeName = False
End If
End function
Function GetEncryptableVolume()
Dim aEncVolumes,oEncVolume,oTemp
Set aEncVolumes = GetWMIObject(skSecurityPath & ":Win32_EncryptableVolume").Instances_
oEncVolume=Empty
For Each oTemp In aEncVolumes
If( oTemp.DriveLetter = BdeArgs.GetArg("volumeletter") ) Then
Set oEncVolume = oTemp
End If
Next
Set oEncVolume = CheckEmpty(oEncVolume,_
VBsprintf(GLR.Localize("drive_invalid"),_
Array(BdeArgs.GetArg("volumeletter"))))
Set GetEncryptableVolume = oEncVolume
End Function
'--- Format using the locale ID, arguments to format
'--- Come from oVolume, and aArray
Public Function FormatStr3(sLocID,aArray,oVolume)
oVolume.SetFormatArray(aArray)
FormatStr3 = VbsprintfLookup(GLR.Localize(sLocID),oVolume)
End Function
Public Function FormatStr2(sLocID,aArray)
FormatStr2 = Vbsprintf(GLR.Localize(sLocID),aArray)
End Function
Public Function FormatStr(sLocID)
FormatStr = Vbsprintf(GLR.Localize(sLocID),empty)
End Function
Class VolumeObject
Private m_oEncVolume
Private m_oPhysVolume
Private m_aArrayLookup
Sub Class_initialize()
m_oPhysVolume = Null
m_oEncVolume = Null
End Sub
public Function SetFormatArray(aArray)
Set m_aArrayLookup = new ArrayLookup
m_aArrayLookup.SetArray(aArray)
End Function
Public Function WMIObjectReference()
Set WMIObjectReference = m_oEncVolume
End Function
'----- VBsprintf needs an object that can do a "lookup" ----
'----- This function responds to particular control characters ---'
'----- in the string and will return the appropriate text for the string ----'
Public function Lookup(i,ch)
Dim sMsg
Select Case ch
Case "c"
sMsg = ConversionStatusToString(ConversionStatus)
Case "z"
sMsg = Capacity
Case "v"
sMsg = DriveLetter
Case "l"
sMsg = Label
Case "%"
sMsg = "%"
Case Else
sMsg = m_aArrayLookup.Lookup(i,ch)
End Select
Lookup = sMsg
End Function
'-------- Constructors --------'
Public Function CreateByReference(oEncVolume)
Set m_oEncVolume = oEncVolume
On Error Resume Next
Set m_oPhysVolume = GetPhysicalFromEncryptable(oEncVolume)
On Error GoTo 0
End Function
Public Function CreateByLetter(sDrive)
Dim aEncVolumes,oEncVolume,oTemp
Set aEncVolumes = GetWMIObject(skSecurityPath & ":Win32_EncryptableVolume").Instances_
oEncVolume=Empty
For Each oTemp In aEncVolumes
If( oTemp.DriveLetter = sDrive ) Then
Set oEncVolume = oTemp
End If
Next
Set oEncVolume = CheckEmpty(oEncVolume,_
VBsprintf(GLR.Localize("drive_invalid"),_
Array(sDrive)))
CreateByReference(oEncVolume)
End Function
'------------------------------'
'--------Prints a message telling whether or not this is the OS Volume ------'
Function PrintOSVolume()
If IsOsVolumeName(DriveLetter) Then
PrintOSVolume = GLR.Localize("OSVolume")
Else
PrintOSVolume = GLR.Localize("DataVolume")
End If
End Function
'------------------------'
Function GetPassword(sKeyProtector)
Dim sPassword
CheckRC m_oEncVolume.GetKeyProtectorNumericalPassword(sKeyProtector,_
sPassword),_
GLR.Localize("getpassword_error")
GetPassword = sPassword
End Function
Public Property Get HardwareTestStatus
Dim nTestStatus,nTestError
CheckRC m_oEncVolume.GetHardwareTestStatus(nTestStatus,nTestError),_
FormatStr("error_hardware_status")
HardwareTestStatus = nTestStatus
End Property
Public Property Get HardwareTestError
Dim nTestStatus,nTestError
CheckRC m_oEncVolume.GetHardwareTestStatus(nTestStatus,nTestError),_
FormatStr("error_hardware_status")
HardwareTestError = nTestError
End Property
Public Function IsHardwareTestPending()
if HardwareTestStatus = kBDE_HARDWARE_TEST_PENDING Then
IsHardwareTestPending = True
Else
IsHardwareTestPending = False
End If
End Function
Public Function IsHardwareTestFailed()
if HardwareTestStatus = kBDE_HARDWARE_TEST_FAILED Then
IsHardwareTestFailed = True
Else
IsHardwareTestFailed = False
End If
End Function
'---- Display/Save a key protector ----'
Public Function DoKeyProtector(sKeyProtector,sKeyDir)
Dim nKeyprotType,sKeyPath,sPassword,rc,sProtID,bIsAutoUnlockEnabled
Dim bUnLocked,nLockedStatus
nKeyProtType = GetKeyProtectorType(sKeyProtector)
bIsAutoUnlockEnabled = IsAutoUnlockEnabled(sProtID)
bUnLocked = Not(IsLocked())
Select Case nKeyProtType
Case kBDE_PROTECTOR_TYPE_KEY
CheckRC m_oEncVolume.GetExternalKeyFileName(sKeyProtector,sKeyPath),_
GLR.Localize("Externalkey_error")
WScript.StdOut.WriteLine Space(4) & GLR.Localize("recoverykey")
WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
WScript.StdOut.WriteLine Space(6) & GLR.Localize("keypath_str")
WScript.StdOut.WriteLine Space(8) & sKeyPath
If bIsAutoUnlockEnabled And sProtID = sKeyProtector Then
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine Space(6) & GLR.Localize("autounlock_str")
End If
If Not(IsEmpty(sKeyDir)) Then
SaveKey sKeyProtector,sKeyDir
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine Space(4) & VBSprintf(GLR.Localize("keyprot_saved"),_
Array(sKeyDir))
End if
WScript.StdOut.WriteLine ""
Case kBDE_PROTECTOR_TYPE_TPM_KEY
CheckRC m_oEncVolume.GetExternalKeyFileName(sKeyProtector,sKeyPath),_
GLR.Localize("Externalkey_error")
WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_key")
WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
WScript.StdOut.WriteLine Space(6) & GLR.Localize("keypath_str")
WScript.StdOut.WriteLine Space(8) & sKeyPath
If Not(IsEmpty(sKeyDir)) Then
SaveKey sKeyProtector,sKeyDir
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine Space(4) & VBSprintf(GLR.Localize("keyprot_saved"),_
Array(sKeyDir))
End If
WScript.StdOut.WriteLine ""
Case kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
CheckRC m_oEncVolume.GetExternalKeyFileName(sKeyProtector,sKeyPath),_
GLR.Localize("Externalkey_error")
WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_pin_key")
WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
WScript.StdOut.WriteLine Space(6) & GLR.Localize("keypath_str")
WScript.StdOut.WriteLine Space(8) & sKeyPath
If Not(IsEmpty(sKeyDir)) Then
SaveKey sKeyProtector,sKeyDir
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine Space(4) & VBSprintf(GLR.Localize("keyprot_saved"),_
Array(sKeyDir))
End If
WScript.StdOut.WriteLine ""
Case kBDE_PROTECTOR_TYPE_TPM
WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_only")
WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
WScript.StdOut.WriteLine ""
Case kBDE_PROTECTOR_TYPE_TPM_PIN
WScript.StdOut.WriteLine Space(4) & GLR.Localize("tpm_pin")
WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
WScript.StdOut.WriteLine ""
Case kBDE_PROTECTOR_TYPE_PASSWORD
WScript.StdOut.WriteLine Space(4) & GLR.Localize("recoverypassword")
WScript.StdOut.WriteLine Space(6) & VBsprintf(GLR.Localize("id_str"),Array(sKeyProtector))
If bUnLocked Then
WScript.StdOut.WriteLine Space(6) & GLR.Localize("passw_str")
WScript.StdOut.WriteLine Space(8) & GetPassword(sKeyProtector)
End If
WScript.StdOut.WriteLine ""
Case Else
Fail GLR.Localize("unknown_prot_type") & nKeyProtType
End Select
End Function
'---- End display/save ---------'
'--- Unlock the volume given a key file ----'
Function UnlockWithKeyFile(sRecoveryFile)
Dim aKey(32)
CheckRC m_oEncVolume.GetExternalKeyFromFile(sRecoveryFile,_
aKey),_
GLR.Localize("getkey_error")
CheckRC m_oEncVolume.UnlockWithExternalKey(aKey),_
VBsprintf(GLR.Localize("unlockkey_error"),Array(sRecoveryFile,DriveLetter))
End Function
'--- Unlock the volume given raw key bytes ----'
Function UnlockWithNumericalPassword(sPassword)
CheckRC m_oEncVolume.UnlockWithNumericalPassword(sPassword),_
VBsprintf(GLR.Localize("unlockpassw_error"),_
Array(DriveLetter))
End Function
'----- Deletes a protector and produces the standard output ----'
Function DeleteKeyProtector(sKeyProtector)
Dim rc,tDisable
tDisable = False
rc = m_oEncVolume.DeleteKeyProtector(sKeyProtector)
If rc = kBDE_ERROR_KEY_REQUIRED Then
DisableKeyProtectors()
tDisable = True
rc = m_oEncVolume.DeleteKeyProtector(sKeyProtector)
End If
CheckRC rc, GLR.Localize("deleteKeyProtError")
WScript.StdOut.WriteLine VBsprintf(GLR.Localize("force_delete"),_
Array(sKeyProtector))
If tDisable Then
WScript.StdOut.WriteLine VBSprintf(GLR.Localize("disabled_warning"),empty)
End If
End Function
'------ Delete all the key protectors of a particular type ------'
'------ Doesn't fail if they don't exist ----------'
Function DeleteKeyProtectorByType(nType)
Dim aProtectors,sProtector
aProtectors = GetKeyProtectors(nType)
For Each sProtector In aProtectors
DeleteKeyProtector sProtector
Next
End Function
'---- Simple properties and wrapped methods ----'
Public Property Get DriveLetter
DriveLetter = m_oEncVolume.DriveLetter
End Property
Public Function IsOsVolume()
IsOsVolume = IsOsVolumeName(DriveLetter)
End Function
Public Function IsDataVolume()
IsDataVolume = Not(IsOsVolumeName(DriveLetter))
End Function
'---- Tells if it is bound to the OS volume, key prot placed in sProtID ---'
'---- sProtID is an out parameter ----'
Public Function IsAutoUnlockEnabled(sProtID)
Dim bIsAutoUnlockEnabled
m_oEncVolume.IsAutoUnlockEnabled bIsAutoUnlockEnabled,_
sProtID
IsAutoUnlockEnabled = bIsAutoUnlockEnabled
End Function
'----- Turn on autounlocking ----'
Function EnableAutoUnlock()
Dim sKeyProt
sKeyProt = AddExternalKey()
CheckRC m_oEncVolume.EnableAutoUnlock(sKeyProt),_
GLR.Localize("autolock_error")
EnableAutoUnlock = sKeyProt
End Function
'----- Turn on autounlocking ----'
Function DisableAutoUnlock()
CheckRC m_oEncVolume.DisableAutoUnlock(),_
GLR.Localize("disableautounlockerror")
End Function
'----- Clear all the autounlock keys------'
Function ClearAllAutoUnlockKeys()
CheckRC m_oEncVolume.ClearAllAutoUnlockKeys(),_
GLR.Localize("clearall_error")
End Function
'---- Check for stored autounlock keys -----'
Function IsAutoUnlockKeyStored()
Dim bAutoKeys
CheckRC m_oEncVolume.IsAutoUnlockKeyStored(bAutoKeys),_
GLR.Localize("autounlockkeys_error")
IsAutoUnlockKeyStored = bAutoKeys
End Function
'---- add a clear key ----'
Public Function DisableKeyProtectors()
CheckRC m_oEncVolume.DisableKeyProtectors(),_
GLR.Localize("disable_error")
End Function
'---- remove the clear key ---'
Public Function EnableKeyProtectors()
CheckRC m_oEncVolume.EnableKeyProtectors(),_
GLR.Localize("enable_error")
End Function
'----- return the label if we've got the underlying object ----'
Public Property Get Label
On Error Resume Next
If Not(IsNull(m_oPhysVolume)) and Not(IsEmpty(m_oPhysVolume)) _
And Not(IsLocked()) Then
Label = m_oPhysVolume.Label
Else
Label = GLR.Localize("status.nolabel")
End If
On Error Goto 0
End Property
'----- Size of the disk in GB ----'
Public Property Get Capacity
Dim bLogic
On Error Resume Next
bLogic = (Not IsNull(m_oPhysVolume)) And _
(Not IsEmpty(m_oPhysVolume)) And _
(Not IsLocked())
If bLogic Then
bLogic = Not IsNull(m_oPhysVolume.Capacity)
End If
If bLogic Then
Capacity = Round(m_oPhysVolume.Capacity/(1024*1024*1024),2)
Else
Capacity = GLR.Localize("status.nosize")
End If
On Error GoTo 0
End Property
Public Function GetKeyProtectorType(sProtector)
Dim nKeyProtType
CheckRC m_oEncVolume.GetKeyProtectorType(sProtector,nKeyProtType) ,_
GLR.Localize("status.keyproterror2")
GetKeyProtectorType = nKeyProtType
End Function
Public Function GetKeyProtectors(nType)
Dim aProtectors
CheckRC m_oEncVolume.GetKeyProtectors(nType,aProtectors),_
GLR.Localize("volumekeyproterror")
GetKeyProtectors = aProtectors
End Function
'--- Locked status ----'
Public Property Get LockStatus
Dim nLockStatus
CheckRC m_oEncVolume.GetLockStatus(nLockStatus) , _
GLR.Localize("LockStatusError")
LockStatus = nLockStatus
End Property
Public Function IsLocked()
If LockStatus = kBDE_LOCK_STATUS_LOCKED Then
IsLocked = True
Else
IsLocked = False
End If
End Function
'---- Lock the volume ----'
Public Function Lock(tForceDismount)
CheckRC m_oEncVolume.Lock(tForceDismount),_
GLR.Localize("disklockerror")
End Function
'-----------------'
'--- Resume conversion of the disk ---'
Public Function ResumeConversion()
CheckRC m_oEncVolume.ResumeConversion(),_
GLR.Localize("resume_failure")
End Function
'--- Pause conversion of the disk ---'
Public Function PauseConversion()
CheckRC m_oEncVolume.PauseConversion(),_
GLR.Localize("pause_failure")
End Function
'--- Conversion Status Functions----'
Public Property Get ConversionStatus
Dim nConversionStatus,nEncryptPercentage
If IsLocked() Then
nConversionStatus = -1
Else
CheckRC m_oEncVolume.GetConversionStatus( nConversionStatus, nEncryptPercentage ), _
GLR.Localize("convstatuserror")
End If
ConversionStatus = nConversionStatus
End Property
Public Function IsDecrypted()
If ConversionStatus = kBDE_CONVERSION_STATUS_DECRYPTED Then
IsDecrypted = True
Else
IsDecrypted = False
End If
End Function
Public Function IsEncrypted()
If ConversionStatus = kBDE_CONVERSION_STATUS_ENCRYPTED Then
IsEncrypted = True
Else
IsEncrypted = False
End If
End Function
Public Function IsEncrypting()
If ConversionStatus = kBDE_CONVERSION_STATUS_ENCRYPTING Or _
ConversionStatus = kBDE_CONVERSION_STATUS_ENCPAUSED Then
IsEncrypting = True
Else
IsEncrypting = False
End If
End Function
Public Function IsDecrypting()
If ConversionStatus = kBDE_CONVERSION_STATUS_DECRYPTING Or _
ConversionStatus = kBDE_CONVERSION_STATUS_DECPAUSED Then
IsDecrypting = True
Else
IsDecrypting = False
End If
End Function
Public Function IsPaused()
If ConversionStatus = kBDE_CONVERSION_STATUS_ENCPAUSED Or _
ConversionStatus = kBDE_CONVERSION_STATUS_DECPAUSED Then
IsPaused = True
Else
IsPaused = False
End If
End Function
Public Property Get EncryptionMethod
Dim nEncMethod
CheckRC m_oEncVolume.GetEncryptionMethod(nEncMethod) ,_
GLR.Localize("status.encerror")
EncryptionMethod = nEncMethod
End Property
'----- Wrapper methods for the protection status -------'
Public Property Get ProtectionStatus
Dim nProtStatus
CheckRC m_oEncVolume.GetProtectionStatus( nProtStatus ) ,_
GLR.Localize("protstaterror")
ProtectionStatus = nProtStatus
End Property
Public Function IsProtected()
If ProtectionStatus = kBDE_PROTECTION_STATUS_ON Then
IsProtected = True
Else
IsProtected = False
End If
End Function
'------------------------------'
'------ Encryption Percentage Functions -----'
Public Property Get EncryptionPercentage
Dim nConversionStatus,nEncryptPercentage
If IsLocked() Then
nEncryptPercentage = GLR.Localize("status.nosize")
Else
CheckRC m_oEncVolume.GetConversionStatus( nConversionStatus, nEncryptPercentage ), _
GLR.Localize("convstatuserror")
End if
EncryptionPercentage = nEncryptPercentage
End Property
'---- Key Protector Available Functions -------'
Private Function IsKeyProtectorAvailable(nType,bBoolRef)
Dim rc
rc = m_oEncVolume.IsKeyProtectorAvailable(nType,bBoolRef)
IsKeyProtectorAvailable = rc
End Function
'----- Start Encryption of the Disk ---------'
Public Function Encrypt(nEncryption)
CheckRC m_oEncVolume.Encrypt(nEncryption),_
GLR.Localize("encrypt_fail")
End Function
'----- Start Encryption of the Disk ---------'
Public Function EncryptAfterHardwareTest(nEncryption)
CheckRC m_oEncVolume.EncryptAfterHardwareTest(nEncryption),_
GLR.Localize("encrypt_fail")
End Function
'----- Decrypt the disk-----------'
Public Function Decrypt()
CheckRC m_oEncVolume.Decrypt(), _
GLR.Localize("DecryptFailure")
End Function
'---- Check to see if ANY tpm protector is being used ----'
Public Function UsesAnyTPM()
UsesAnyTPM = UsesTPM() Or UsesTPMAndPin() Or UsesTpmAndKey() Or UsesTpmAndPinAndKey()
End Function
Public Function UsesTPM()
Dim bTPMPresent
CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM,bTPMPresent),_
GLR.Localize("tpm_available_error")
UsesTpm = bTPMPresent
End Function
Public Function UsesPassword()
Dim bPasswordPresent
CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_PASSWORD,_
bPasswordPresent),_
GLR.Localize("passw_available_error")
UsesPassword = bPasswordPresent
End Function
Public Function UsesKey()
Dim bRecoveryKeyPresent
CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_KEY,_
bRecoveryKeyPresent),_
GLR.Localize("key_available_error")
UsesKey = bRecoveryKeyPresent
End Function
Public Function UsesTPMAndPIN()
Dim bTPM_PINPresent
CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM_PIN,_
bTPM_PINPresent),_
GLR.Localize("pin_available_error")
UsesTPMAndPIN = bTPM_PINPresent
End Function
Public Function UsesTPMAndKey()
Dim bTPM_KeyPresent
CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM_KEY,_
bTPM_KeyPresent),_
GLR.Localize("tpmsk_available_error")
UsesTPMAndKey = bTPM_KeyPresent
End Function
Public Function UsesTPMAndPINAndKey()
Dim bTPM_PIN_KeyPresent
CheckRC IsKeyProtectorAvailable(kBDE_PROTECTOR_TYPE_TPM_PIN_KEY,_
bTPM_PIN_KeyPresent),_
GLR.Localize("tpm_pin_key_available_error")
UsesTPMAndPINAndKey = bTPM_PIN_KeyPresent
End Function
'External Key
'-----------------------'
'- External Key means that we generate
'- A 32 byte key at random.
'- And this is used to protect the disk.
'- This key is meant to be stored at the root
'- Of a USB disk. BDE will prompt for the location
'- Of this key at mount time
'-----------------------'
Public Function AddExternalKey()
Dim sProtID,rc
Dim aExternalKey
aExternalKey = Empty
rc = m_oEncVolume.ProtectKeyWithExternalKey("ExternalKey",_
aExternalKey,sProtID)
CheckRC rc,GLR.Localize("ProtectKeyFail")
AddExternalKey = sProtID
End Function
'Numeric Password
'----------------------'
'- Protecting the BDE with a password means
'- That a 48 digit numeric key must be generated
'- And will have to be entered to unlock the disk
'----------------------'
Function AddPassword(sPasswd)
Dim iPasswd
Dim sProtID
Dim bIsValid,rc
If Not IsEmpty(sPasswd) Then
CheckRC m_oEncVolume.IsNumericalPasswordValid(sPasswd,bIsValid),_
GLR.Localize("CheckPasswFail")
If Not bIsValid Then
Fail(GLR.Localize("PasswNotValid"))
End If
End If
rc = m_oEncVolume.ProtectKeyWithNumericalPassword("DiskPassword",_
sPasswd,sProtID)
if rc = kBDE_ERROR_FIPS_POLICY Then
BdeArgs.FormatLine 4, GLR.Localize("fips_warning")
sProtID = Empty
Else
CheckRC rc, GLR.Localize("ProtectDiskFail")
End If
AddPassword = sProtID
End Function
Function CustomTpmErrorMessages(rc)
If rc = kBDE_ERROR_BOOTABLE_CDDVD Then
Fail FormatStr("error_dvd")
End If
End Function
'TPM BDE protection
'--------------------'
'- The TPM will be used to validate a BOOT drive
'- This is done by setting the PlatformValidationProfile
'- The numbers in this array specify what boot components to
'- Examine at boot time.
'- This function uses the default metrics.
'--------------------'
Function AddTpm()
Dim sProtID,rc
rc = m_oEncVolume.ProtectKeyWithTPM("TPM Protection",_
Empty,_
sProtID)
CustomTpmErrorMessages(rc)
CheckRC rc,GLR.Localize("tpm_fail")
AddTpm = sProtID
End Function
'TPM and PIN BDE Protection
'---------------------------'
'- The disk will only be unlocked if BOTH the TPM
'- Correctly validates the boot components
'- AND the user inputs the correct PIN
'- PIN is generated below(random)
'---------------------------'
Function AddTpmAndPin(sPasswd)
Dim iPasswd
Dim aPasswd
Dim oInParams
Dim oOutParams
Dim bIsValid,sProtID,rc
rc = m_oEncVolume.ProtectKeyWithTPMAndPIN("TPMAndPin",_
Empty,_
sPasswd,_
sProtID)
CustomTpmErrorMessages(rc)
CheckRC rc,GLR.Localize("tpm_pin_fail")
AddTpmAndPin = sProtID
End Function
'TPM and KEY BDE Protection
'---------------------------'
'- The disk will only be unlocked if BOTH the TPM
'- Correctly validates the boot components
'- AND the USB key is found.
'---------------------------'
Function AddTpmAndKey()
Dim sProtID,rc
Dim aKey
aKey = Empty
rc = m_oEncVolume.ProtectKeyWithTPMAndStartupKey(_
"TpmAndStartupKey",_
Empty,_
aKey,_
sProtID)
CustomTpmErrorMessages(rc)
CheckRC rc,GLR.Localize("tpm_key_fail")
AddTpmAndKey = sProtID
End Function
'TPM and PIN and KEY BDE Protection
'---------------------------'
'- The disk will only be unlocked if the TPM
'- Correctly validates the boot components
'- AND the user inputs the correct PIN
'- AND the USB key is found
'---------------------------'
Function AddTpmAndPinAndKey(sPasswd)
Dim sProtID,rc
Dim aKey
aKey = Empty
rc = m_oEncVolume.ProtectKeyWithTPMAndPINAndStartupKey(_
"TpmAndPinAndStartupKey",_
Empty,_
sPasswd,_
aKey,_
sProtID)
CustomTpmErrorMessages(rc)
CheckRC rc,GLR.Localize("tpm_pin_key_fail")
AddTpmAndPinAndKey = sProtID
End Function
'---- Save a Key to an external directory ----'
Function SaveKey(sProtID,sFilePath)
Dim rc
rc = m_oEncVolume.SaveExternalKeyToFile(sProtID,_
sFilePath)
If rc = kBDE_ERROR_RELATIVE_PATH Then
Fail GLR.Localize("relative_path_error")
End If
CheckRC rc, GLR.Localize("bde_save_failure")
End Function
End Class
'-------- End VolumeObject Class-----------------'
'------------------------------------------------'
</script>
<!--------------------------------------------------->
<!-- Manage-BDE MAIN Body -->
<!--------------------------------------------------->
<script id="runtime" language="VBscript">
Option Explicit
'----Important first step------------------'
'- Ensure that we're running under cscript-'
If Not IsHostCScript() Then
WScript.Echo VBsprintf(GLR.Localize("wscript_message"),empty)
WScript.Quit -1
End If
'-----Constants--------'
'2 Specifies AES 256 with Diffuser
Const nkEncryptionType = 2
Function IsAlpha( cChar )
Dim tRet
tRet = False
cChar = LCase(cChar)
If ( Asc(cChar) >= Asc("a") And _
Asc(cChar) <= Asc("z") ) Then
tRet = True
End If
IsAlpha = tRet
End Function
Function ParseVolume( oParseObj)
Dim vRetVal,volArg
volArg = oParseObj.Argument
If Len(volArg) <> 2 Or Right(volArg,1) <> ":" _
Or Not(IsAlpha(Left(volArg,1))) Then
If oParseObj.FailOnError() Then
Fail(GLR.Localize("volume_format_error"))
Else
vRetVal = Null
End If
Else
vRetVal = UCase(Left(volArg,1)) & ":"
End If
ParseVolume = vRetVal
End Function
Function ParsePassword(oParseObj)
Dim vRetVal,sArg
sArg = oParseObj.Argument
'--- need this function so we can accept empty passwords ---'
If IsEmpty(sArg) Or Len(sArg) >= 48 Then
vRetVal = sArg
Else
If oParseObj.FailOnError() Then
Fail( vbsprintf(GLR.Localize("PasswNotValid"),Array(sArg)))
Else
vRetVal = Null
End if
End If
ParsePassword = vRetVal
End Function
Function parseProtType( oParseObj )
Dim nType
'---- This will still fail, but it will be clearer why ----'
If( IsEmpty(oParseObj.Argument)) Then
oParseObj.Argument = "(Empty)"
End If
Select Case LCase(oParseObj.Argument)
Case "recoverypassword"
nType = kBDE_PROTECTOR_TYPE_PASSWORD
Case "externalkey"
nType = kBDE_PROTECTOR_TYPE_KEY
Case "tpm"
nType = kBDE_PROTECTOR_TYPE_TPM
Case "tpmandstartupkey"
nType = kBDE_PROTECTOR_TYPE_TPM_KEY
Case "tpmandpin"
nType = kBDE_PROTECTOR_TYPE_TPM_PIN
Case "tpmandpinandstartupkey"
nType = kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
Case Else
If oParseObj.FailOnError() Then
Fail(VBsprintf(GLR.Localize("key_type_invalid"),Array(oParseObj.Argument)))
Else
nType = Null
End If
End Select
parseProtType = nType
End Function
Function parseEncryption( oParseObj )
Dim nEncryptionType
Select Case LCase(oParseObj.Argument)
Case "none"
nEncryptionType = kBDE_ENCRYPTION_NONE
Case "aes128_diffuser"
nEncryptionType = kBDE_ENCRYPTION_AES128_DIFFUSER
Case "aes256_diffuser"
nEncryptionType = kBDE_ENCRYPTION_AES256_DIFFUSER
Case "aes128"
nEncryptionType = kBDE_ENCRYPTION_AES128
Case "aes256"
nEncryptionType = kBDE_ENCRYPTION_AES256
Case Else
If oParseObj.FailOnError() Then
Fail(VBsprintf(GLR.Localize("encryption_invalid"),Array(oParseObj.Argument)))
Else
nEncryptionType = Null
End If
End Select
parseEncryption = nEncryptionType
End Function
Function AddVolumeParameter()
Dim oVolParam
Set oVolParam = new BdeArgElem
oVolParam.Init kPARAM_FREE, "volumeletter" , "v", kARG_FUNC, GetRef("ParseVolume"), Empty, True, True
oVolParam.SetUsage kUSAGE_CMN, GLR.Localize("volusage_req"), GLR.Localize("volusage_required")
oVolParam.ShortDescription = FormatStr("volusage_short")
BdeArgs.AddParam oVolParam
End Function
Function AddProtectorParameters()
Dim oTPMStartupkeyParam,oRecoveryKeyParam,oPasswordParam
Dim oTPMPinParam,oSKParam,oTPMPinKeyParam
Set oTPMStartupkeyParam = new BdeArgElem
Set oRecoveryKeyParam = new BdeArgElem
Set oPasswordParam = new BdeArgElem
Set oTPMPinParam = new BdeArgElem
Set oSKParam = new BdeArgElem
Set oTPMPinKeyParam = new BdeArgElem
'---OBJECT PARAM_TYPE PARAMETER_NAME SYNONYM ARG_TYPE CALLBACK_FUNCTION DEFAULT VALUE Required Argument Required
oTPMStartupkeyParam.Init kPARAM_PRM, "tpmandstartupkey" ,"tsk" ,kARG_STR ,Empty ,Empty , False ,True
oRecoveryKeyParam.Init kPARAM_PRM, "recoverykey" ,"rk" ,kARG_STR ,Empty ,Empty , False ,True
oSKParam.Init kPARAM_PRM, "startupkey" ,"sk" ,kARG_STR ,Empty ,Empty , False ,True
oPasswordParam.Init kPARAM_PRM, "recoverypassword" ,"rp" ,kARG_FUNC ,GetRef("ParsePassword") ,Empty , False ,True
oTPMPinParam.Init kPARAM_PRM, "tpmandpin" ,"tp" ,kARG_STR ,Empty ,Empty , False ,True
oTPMPinKeyParam.Init kPARAM_PRM, "tpmandpinandstartupkey","tpsk" ,kARG_STR ,Empty ,Empty , False ,False
oTPMStartupkeyParam.SetUsage kUSAGE_CMN,"-TPMAndStartupKey or -tsk" ,GLR.Localize("tsk_desc")
oRecoveryKeyParam.SetUsage kUSAGE_CMN,"-RecoveryKey or -rk" ,GLR.Localize("rk_desc")
oSKParam.SetUsage kUSAGE_CMN,"-StartupKey or -sk" ,GLR.Localize("sk_desc")
oPasswordParam.SetUsage kUSAGE_CMN,"-RecoveryPassword or -rp" ,GLR.Localize("rp_desc")
oTPMPinParam.SetUsage kUSAGE_CMN,"-TPMAndPIN or -tp" ,GLR.Localize("tp_desc")
oTPMPinKeyParam.SetUsage kUSAGE_CMN,"-TPMAndPINAndStartupKey or -tpsk",GLR.Localize("tpsk_desc")
oTPMStartupkeyParam.ShortDescription = FormatStr("tsk_desc_short")
oRecoveryKeyParam.ShortDescription = FormatStr("rk_desc_short")
oSKParam.ShortDescription = FormatStr("sk_desc_short")
oPasswordParam.ShortDescription = FormatStr("rp_desc_short")
oTPMPinParam.ShortDescription = FormatStr("tp_desc_short")
oTPMPinKeyParam.ShortDescription = FormatStr("tpsk_desc_short")
BdeArgs.AddParam oPasswordParam
BdeArgs.AddParam oRecoveryKeyParam
BdeArgs.AddParam oSKParam
BdeArgs.AddParam oTPMPinParam
BdeArgs.AddParam oTPMStartupkeyParam
BdeArgs.AddParam oTPMPinKeyParam
End Function
Function Cmd_Status(arg)
Dim oVolParam,oProtStatusParam
Set oVolParam = new BdeArgElem
Set oProtStatusParam = new BdeArgElem
oVolParam.Init kPARAM_FREE, "volumeletter" , "v", kARG_FUNC, GetRef("ParseVolume"), Empty, False, True
oProtStatusParam.Init kPARAM_PRM, "protectionaserrorlevel", "p", kARG_BOOL, Empty , False, False, False
oVolParam.SetUsage kUSAGE_CMN, GLR.Localize("volusage_req"), GLR.Localize("vol_usage")
oProtStatusParam.SetUsage kUSAGE_CMN, "-ProtectionAsErrorLevel or -p", GLR.Localize("proterror_usage")
oVolParam.ShortDescription = FormatStr("volusage_short")
oProtStatusParam.ShortDescription = FormatStr("pusage_short")
BdeArgs.ClearCommands()
BdeArgs.AddParam oVolParam
BdeArgs.AddParam oProtStatusParam
BdeArgs.SetPreamble 8, FormatStr("status_preamble")
BdeArgs.SetDescription(GLR.Localize("status_desc"))
BdeArgs.AddExample("manage-bde -status")
BdeArgs.AddExample("manage-bde -status e:")
BdeArgs.AddExample("manage-bde -status e: -ProtectionAsErrorLevel")
BdeArgs.SetContinuation GetRef("DoStatus"), Empty
End Function
Function Cmd_On(arg)
Dim oEncryptionParam,oHardwareTestParam
Set oEncryptionParam = new BdeArgElem
Set oHardwareTestParam = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 8,FormatStr("on_preamble")
BdeArgs.SetDescription(GLR.Localize("on_desc"))
BdeArgs.ShortDescription = FormatStr("on_desc_short")
oEncryptionParam.Init kPARAM_PRM, "encryptionmethod" ,"em" ,kARG_FUNC ,GetRef("parseEncryption") ,0, False ,True
oEncryptionParam.SetUsage kUSAGE_CMN,"-EncryptionMethod or -em" ,GLR.Localize("em_desc")
oEncryptionParam.ShortDescription = FormatStr("em_desc_short")
oHardwareTestParam.Init kPARAM_PRM, "skiphardwaretest" ,"s" ,kARG_BOOL ,False ,Empty, False ,False
oHardwareTestParam.SetUsage kUSAGE_CMN,"-SkipHardwareTest or -s" ,GLR.Localize("hardware_desc")
oHardwareTestParam.ShortDescription = FormatStr("hardware_desc_short")
AddVolumeParameter()
AddProtectorParameters()
BdeArgs.AddParam oEncryptionParam
BdeArgs.AddParam oHardwareTestParam
BdeArgs.AddExample("manage-bde -on C: -RecoveryPassword")
BdeArgs.AddExample("manage-bde -on C: -RecoveryKey e:\ -RecoveryPassword")
BdeArgs.AddExample("manage-bde -on C: -rp -rk ""f:\Folder"" -SkipHardwareTest")
BdeArgs.AddExample("manage-bde -on C: -rp -StartupKey ""f:\""")
BdeArgs.AddExample("manage-bde -on C: -rp -TPMAndPIN 1234 -em aes128_diffuser")
BdeArgs.SetContinuation GetRef("DoOn"), Empty
End Function
Function Cmd_Pause(arg)
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 8,FormatStr("pause_preamble")
BdeArgs.SetDescription(GLR.Localize("pause_desc"))
AddVolumeParameter()
BdeArgs.AddExample("manage-bde -pause C:")
BdeArgs.SetContinuation GetRef("DoPause"), Empty
End Function
Function Cmd_Resume(arg)
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 8,FormatStr("resume_preamble")
BdeArgs.SetDescription(GLR.Localize("resume_desc"))
AddVolumeParameter()
BdeArgs.AddExample("manage-bde -resume C:")
BdeArgs.SetContinuation GetRef("DoResume"), Empty
End Function
Function Cmd_Unlock(arg)
Dim oKeyParam,oPasswordParam
Set oKeyParam = new BdeArgElem
Set oPasswordParam = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 8,FormatStr("unlock_preamble")
BdeArgs.SetDescription(GLR.Localize("unlock_desc"))
oKeyParam.Init kPARAM_PRM, "recoverykey" ,"rk" ,kARG_STR ,Empty ,Empty, False ,True
oPasswordParam.Init kPARAM_PRM, "recoverypassword" ,"rp" ,kARG_STR ,Empty ,Empty, False ,True
oKeyParam.SetUsage kUSAGE_CMN,"-RecoveryKey or -rk" ,GLR.Localize("rk_unlock_desc")
oPasswordParam.SetUsage kUSAGE_CMN,"-RecoveryPassword or -rp" ,GLR.Localize("rp_unlock_desc")
oKeyParam.ShortDescription = FormatStr("rk_unlock_short")
oPasswordParam.ShortDescription = FormatStr("rp_unlock_short")
AddVolumeParameter()
BdeArgs.AddParam oPasswordParam
BdeArgs.AddParam oKeyParam
BdeArgs.AddExample("manage-bde -unlock -?")
BdeArgs.AddExample("manage-bde -unlock e: -RecoveryPassword ...")
BdeArgs.AddExample("manage-bde -unlock e: -RecoveryKey ""f:\File Folder\Filename""")
BdeArgs.SetContinuation GetRef("DoUnlock"), Empty
End Function
Function Cmd_Off(arg)
BdeArgs.ClearCommands()
AddVolumeParameter()
BdeArgs.SetPreamble 8,FormatStr("off_preamble")
BdeArgs.SetDescription(GLR.Localize("off_desc"))
BdeArgs.AddExample("manage-bde -off C:")
BdeArgs.SetContinuation GetRef("DoOff"), Empty
End Function
Function Cmd_Protectors_Add(arg)
Dim oTPMParam
Set oTPMParam = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 12,FormatStr("add_preamble")
BdeArgs.SetDescription(GLR.Localize("add_desc_full"))
BdeArgs.ShortDescription = FormatStr("add_desc_short")
'---OBJECT PARAM_TYPE PARAMETER_NAME SYNONYM ARG_TYPE CALLBACK_FUNCTION DEFAULT VALUE Required Argument Required
oTPMParam.Init kPARAM_PRM, "tpm" ,"" ,kARG_BOOL ,Empty ,Empty , False ,False
oTPMParam.SetUsage kUSAGE_CMN,"-tpm" ,GLR.Localize("tpm_desc")
oTPMParam.ShortDescription = FormatStr("tpm_short")
AddProtectorParameters()
BdeArgs.AddParam oTpmParam
BdeArgs.AddExample("manage-bde -protectors -add e: -RecoveryPassword")
BdeArgs.AddExample("manage-bde -protectors -add e: -rp -rk h:\")
BdeArgs.AddExample("manage-bde -protectors -add e: -TPMAndPIN 1234")
BdeArgs.AddExample("manage-bde -protectors -add e: -TPMAndPINAndStartupKey -tp 1234 -tsk h:\")
BdeArgs.SetContinuation GetRef("DoProtectors"), "add"
End Function
Function Cmd_Protectors_Dis(arg)
Cmd_Protectors_DisEn("disable")
End Function
Function Cmd_Protectors_En(arg)
Cmd_Protectors_DisEn("enable")
End Function
Function Cmd_Protectors_DisEn(sArg)
BdeArgs.SetContinuation GetRef("DoProtectors"), sArg
End Function
Function AddParametersIDType(sPrefix)
Dim oTypeParam,oGUIDParam
Set oTypeParam = new BdeArgElem
Set oGUIDParam = new BdeArgElem
oTypeParam.Init kPARAM_PRM, "type" ,"t" ,kARG_FUNC ,GetRef("ParseProtType") ,Empty, False, True
oGUIDParam.Init kPARAM_PRM, "id" ,"" ,kARG_STR ,Empty ,Empty, False, True
oTypeParam.SetUsage kUSAGE_CMN,"-Type or -t" ,GLR.Localize(sPrefix & "." & "type_desc")
oGUIDParam.SetUsage kUSAGE_CMN,"-id" ,GLR.Localize(sPrefix & "." & "id_desc")
BdeArgs.AddParam oTypeParam
BdeArgs.AddParam oGUIDParam
End Function
Function Cmd_Protectors_Get(arg)
Dim oSaveParam
Set oSaveParam = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 12,FormatStr("get_preamble")
BdeArgs.SetDescription(GLR.Localize("get_full_desc"))
oSaveParam.Init kPARAM_PRM, "saveexternalkey","sek" ,kARG_STR ,Empty ,Empty, False, True
oSaveParam.SetUsage kUSAGE_CMN,"-SaveExternalKey or -sek" ,GLR.Localize("sek_desc")
AddParametersIDType("get")
BdeArgs.AddParam oSaveParam
BdeArgs.AddExample("manage-bde -protectors -get C:")
BdeArgs.AddExample("manage-bde -protectors -get C: -Type recoverypassword")
BdeArgs.AddExample("manage-bde -protectors -get C: -SaveExternalKey ""f:\Folder""")
BdeArgs.SetContinuation GetRef("DoProtectors"), "get"
End Function
Function Cmd_Protectors_Del(arg)
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 12,FormatStr("prot_delete_preamble")
BdeArgs.SetDescription(GLR.Localize("del_full_desc"))
AddParametersIDType("del")
BdeArgs.AddExample("manage-bde -protectors -delete C: -id {84E151C1...7A62067A512}")
BdeArgs.AddExample("manage-bde -protectors -delete C: -Type TPMAndStartupKey")
BdeArgs.AddExample("manage-bde -protectors -delete C: -Type TPMAndPinAndStartupKey")
BdeArgs.SetContinuation GetRef("DoProtectors"), "del"
End Function
Function Cmd_Protectors(arg)
Dim oDeleteCmd,oGetCmd,oDisableCmd,oEnableCmd,oAddCmd
Set oDeleteCmd = new BdeArgElem
Set oGetCmd = new BdeArgElem
Set oDisableCmd = new BdeArgElem
Set oEnableCmd = new BdeArgElem
Set oAddCmd = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 12,FormatStr("prot_preamble")
BdeArgs.SetDescription(GLR.Localize("prot_desc"))
oDeleteCmd.Init kPARAM_CMD, "delete" ,"" ,kARG_FUNC ,GetRef("Cmd_Protectors_Del") ,Empty, False, False
oGetCmd.Init kPARAM_CMD, "get" ,"" ,kARG_FUNC ,GetRef("Cmd_Protectors_Get") ,Empty, False, False
oDisableCmd.Init kPARAM_CMD, "disable" ,"" ,kARG_FUNC ,GetRef("Cmd_Protectors_Dis") ,Empty, False, False
oEnableCmd.Init kPARAM_CMD, "enable" ,"" ,kARG_FUNC ,GetRef("Cmd_Protectors_En") ,Empty, False, False
oAddCmd.Init kPARAM_CMD, "add" ,"" ,kARG_FUNC ,GetRef("Cmd_Protectors_add") ,Empty, False, False
oDeleteCmd.SetUsage kUSAGE_CMN,"-delete" ,GLR.Localize("del_desc")
oGetCmd.SetUsage kUSAGE_CMN,"-get" ,GLR.Localize("get_desc")
oDisableCmd.SetUsage kUSAGE_CMN,"-disable" ,GLR.Localize("disable_desc")
oEnableCmd.SetUsage kUSAGE_CMN,"-enable" ,GLR.Localize("enable_desc")
oAddCmd.SetUsage kUSAGE_CMN,"-add" ,GLR.Localize("add_desc")
AddVolumeParameter()
BdeArgs.AddParam oGetCmd
BdeArgs.AddParam oAddCmd
BdeArgs.AddParam oDeleteCmd
BdeArgs.AddParam oDisableCmd
BdeArgs.AddParam oEnableCmd
BdeArgs.AddExample("manage-bde -protectors -add -?")
BdeArgs.AddExample("manage-bde -protectors -get -?")
BdeArgs.AddExample("manage-bde -protectors -disable C:")
BdeArgs.SetContinuation GetRef("DoProtectors"), Empty
End Function
Function Cmd_Autounlock(arg)
Dim oDisableCmd,oEnableCmd,oClearAllCmd
Set oDisableCmd = new BdeArgElem
Set oEnableCmd = new BdeArgElem
Set oClearAllCmd = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 12,FormatStr("autounlock_preamble")
BdeArgs.SetDescription(GLR.Localize("autounlock_desc"))
oDisableCmd.Init kPARAM_CMD, "disable" ,"" , kARG_BOOL, False ,Empty, False, False
oEnableCmd.Init kPARAM_CMD, "enable" ,"" , kARG_BOOL, False ,Empty, False, False
oClearAllCmd.Init kPARAM_CMD, "clearallkeys" ,"" , kARG_BOOL, False ,Empty, False, False
oDisableCmd.SetUsage kUSAGE_CMN,"-disable", GLR.Localize("disable_auto_desc")
oEnableCmd.SetUsage kUSAGE_CMN,"-enable", GLR.Localize("enable_auto_desc")
oClearAllCmd.SetUsage kUSAGE_CMN,"-ClearAllKeys", GLR.Localize("clearall_desc")
oDisableCmd.ShortDescription = FormatStr("disable_auto_short")
oEnableCmd.ShortDescription = FormatStr("enable_auto_short")
oClearAllCmd.ShortDescription = FormatStr("clearall_auto_short")
AddVolumeParameter()
BdeArgs.AddParam oEnableCmd
BdeArgs.AddParam oDisableCmd
BdeArgs.AddParam oClearAllCmd
BdeArgs.AddExample("managee-bde -autounlock -enable E:")
BdeArgs.AddExample("managee-bde -autounlock -disable E:")
BdeArgs.AddExample("managee-bde -autounlock -ClearAllKeys C:")
BdeArgs.SetContinuation GetRef("DoAutounlock"), Empty
End Function
Function Cmd_Force(arg)
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 8,FormatStr("force_preamble")
BdeArgs.SetDescription(GLR.Localize("fr_desc"))
AddVolumeParameter()
BdeArgs.AddExample("manage-bde -fr")
BdeArgs.AddExample("manage-bde -forcerecovery x:")
BdeArgs.SetContinuation GetRef("DoForce"), Empty
End Function
Function Cmd_Lock(arg)
Dim oForceParam
Set oForceParam = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 8,FormatStr("lock_preamble")
BdeArgs.SetDescription(GLR.Localize("lock_desc"))
oForceParam.Init kPARAM_PRM, "forcedismount","fd" ,kARG_BOOL ,Empty ,False, False ,False
oForceParam.SetUsage kUSAGE_CMN, "-ForceDismount or -fd" ,GLR.Localize("fdusage_lock")
AddVolumeParameter()
BdeArgs.AddParam oForceParam
BdeArgs.AddExample("manage-bde -lock e:")
BdeArgs.AddExample("manage-bde -lock e: -ForceDismount")
BdeArgs.SetContinuation GetRef("DoLock"), Empty
End Function
Function Cmd_Tpm(arg)
Dim oOnParam,oOwnParam
Set oOnParam = new BdeArgElem
Set oOwnParam = new BdeArgElem
BdeArgs.ClearCommands()
BdeArgs.SetPreamble 12,FormatStr("tpm_preamble")
BdeArgs.SetDescription(GLR.Localize("tpmcmd_desc"))
BdeArgs.ShortDescription = FormatStr("tpm_desc_upper")
oOnParam.Init kPARAM_CMD, "TurnOn" , "t", kARG_BOOL, Empty, False, False, False
oOwnParam.Init kPARAM_CMD, "TakeOwnership" , "o", kARG_STR , Empty, False, False, True
oOnParam.SetUsage kUSAGE_CMN, "-TurnOn or -t" , GLR.Localize("turnon_usage")
oOwnParam.SetUsage kUSAGE_CMN, "-TakeOwnership or -o", GLR.Localize("own_usage")
oOnParam.ShortDescription = FormatStr("turnon_short")
oOwnParam.ShortDescription = FormatStr("own_short")
BdeArgs.AddParam oOnParam
BdeArgs.AddParam oOwnParam
BdeArgs.AddExample("manage-bde -tpm -TurnOn")
BdeArgs.AddExample("manage-bde -tpm -TakeOwnership test_password")
BdeArgs.SetContinuation GetRef("DoTpm"), Empty
End Function
'------------------- MAIN BODY -----------------------'
Dim oStatusCmd,oOffCmd,oOnCmd,oUnLockCmd
Dim oLockCmd,oProtCmd,oAutoCmd,oForceCmd
Dim oPauseCmd,oResumeCmd,oTpmCmd
Set oStatusCmd = new BdeArgElem
Set oOffCmd = new BdeArgElem
Set oOnCmd = new BdeArgElem
Set oUnlockCmd = new BdeArgElem
Set oLockCmd = new BdeArgElem
Set oProtCmd = new BdeArgElem
Set oAutoCmd = new BdeArgElem
Set oUnlockCmd = new BdeArgElem
Set oForceCmd = new BdeArgElem
Set oPauseCmd = new BdeArgElem
Set oResumeCmd = new BdeArgElem
Set oTpmCmd = new BdeArgElem
oStatusCmd.Init kPARAM_CMD , "status" ,"" ,kARG_FUNC, GetRef("Cmd_Status") ,Empty, False,False
oOffCmd.Init kPARAM_CMD , "off" ,"" ,kARG_FUNC, GetRef("Cmd_Off") ,Empty, False,False
oOnCmd.Init kPARAM_CMD , "on" ,"" ,kARG_FUNC, GetRef("Cmd_On") ,Empty, False,False
oUnlockCmd.Init kPARAM_CMD , "unlock" ,"" ,kARG_FUNC, GetRef("Cmd_Unlock") ,Empty, False,False
oLockCmd.Init kPARAM_CMD , "lock" ,"" ,kARG_FUNC, GetRef("Cmd_Lock") ,Empty, False,False
oProtCmd.Init kPARAM_CMD ,"protectors","" ,kARG_FUNC, GetRef("Cmd_Protectors"),Empty, False,False
oAutoCmd.Init kPARAM_CMD ,"autounlock","" ,kARG_FUNC, GetRef("Cmd_Autounlock"),Empty, False,False
oForceCmd.Init kPARAM_CMD ,"fr","forcerecovery",kARG_FUNC, GetRef("Cmd_Force") ,Empty, False,False
oPauseCmd.Init kPARAM_CMD ,"pause" ,"" ,kARG_FUNC, GetRef("Cmd_Pause") ,Empty, False,False
oResumeCmd.Init kPARAM_CMD ,"resume" ,"" ,kARG_FUNC, GetRef("Cmd_Resume") ,Empty, False,False
oTpmCmd.Init kPARAM_CMD ,"tpm" ,"" ,kARG_FUNC, GetRef("Cmd_Tpm") ,Empty, False,False
oStatusCmd.SetUsage kUSAGE_CMN,"-status", GLR.Localize("status_desc")
oOffCmd.SetUsage kUSAGE_CMN,"-off", GLR.Localize("off_desc_upper")
oOnCmd.SetUsage kUSAGE_CMN,"-on", GLR.Localize("on_desc_upper")
oUnlockCmd.SetUsage kUSAGE_CMN,"-unlock", GLR.Localize("unlock_short")
oLockCmd.SetUsage kUSAGE_CMN,"-lock", GLR.Localize("lock_desc_upper")
oProtCmd.SetUsage kUSAGE_CMN,"-protectors", GLR.Localize("prot_desc_upper")
oAutoCmd.SetUsage kUSAGE_CMN,"-autounlock", GLR.Localize("auto_desc_upper")
oForceCmd.SetUsage kUSAGE_CMN,"-ForceRecovery or -fr",GLR.Localize("fr_desc_upper")
oPauseCmd.SetUsage kUSAGE_CMN,"-pause", GLR.Localize("pause_desc_upper")
oResumeCmd.SetUsage kUSAGE_CMN,"-resume", GLR.Localize("resume_desc_upper")
oTpmCmd.SetUsage kUSAGE_CMN,"-tpm", GLR.Localize("tpm_desc_upper")
'---- Common Parameters ---'
BdeArgs.AddParam(oStatusCmd)
BdeArgs.AddParam(oOnCmd)
BdeArgs.AddParam(oOffCmd)
BdeArgs.AddParam(oPauseCmd)
BdeArgs.AddParam(oResumeCmd)
BdeArgs.AddParam(oLockCmd)
BdeArgs.AddParam(oUnlockCmd)
BdeArgs.AddParam(oAutoCmd)
BdeArgs.AddParam(oProtCmd)
BdeArgs.AddParam(oTpmCmd)
BdeArgs.AddParam(oForceCmd)
BdeArgs.SetPreamble 4, Vbsprintf(GLR.Localize("main_args"),Array("manage-bde[.wsf]"))
BdeArgs.SetDescription(GLR.Localize("main_desc"))
BdeArgs.AddExample("manage-bde -status")
BdeArgs.AddExample("manage-bde -on C: -RecoveryPassword -RecoveryKey F:\")
BdeArgs.AddExample("manage-bde -unlock E: -RecoveryKey F:\84E151C1...7A62067A512.bek")
BdeArgs.ParseArgs()
'-----------------------------------------'
'--------------- ON ------------------'
'-----------------------------------------'
Function DoOn(arg)
Dim bTPM,bTPMPresent,bTPMAvailable
Dim sRecoveryKey,bRecoveryKey,bRecoveryKeyPresent
Dim sTPM_Key,bTPM_Key,bTPM_KeyPresent
Dim sExtraKey,bExtraKey
Dim sTPM_PIN,bTPM_PIN,bTPM_PINPresent
Dim bAutoUnlock
Dim sPassword,bPasswordPresent,bPassword
Dim nEncryption
Dim oVolume
Dim nLockStatus,nConversionStatus,nEncryptPercentage
Dim nProtectionStatus
Dim rc,sKeyProtector,sVolName
Dim aKeyProtectors
Dim bWasDecrypted
Dim bDoHardwareTest
BdeCommonStartup()
nEncryption = BdeArgs.GetArg("em")
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
WScript.StdOut.WriteLine FormatStr2("bdeexamine",Array(BdeArgs.GetArg("volumeletter")))
WScript.StdOut.WriteLine oVolume.PrintOSVolume()
'Ensure that the disk is unlocked before proceeding
If oVolume.IsLocked() Then
Fail FormatStr("disklock_fail")
End If
If oVolume.IsDecrypted() Then
bWasDecrypted = True
'------ ProtectorsAdd REQUIRES that there be a -tpm parameter -------'
Dim oTPMParam
Set oTPMParam = new BdeArgElem
oTPMParam.Init kPARAM_PRM, "tpm", "", kARG_BOOL , Empty, Empty, False, False
BdeArgs.AddParam(oTpmParam)
'--------------------------'
'---- Check availability of TPM on OS volume only ----'
If oVolume.IsOsVolume() Then
bTpmAvailable = BdeCommonCheckTpmCapability()
'---- Default behavior, if nothing is specified use the TPM -----'
If bTPMAvailable Then
If Not(BdeArgs.IsSet("tsk")) And _
Not(BdeArgs.IsSet("tp")) And _
Not(BdeArgs.IsSet("tpsk")) And _
Not( oVolume.UsesAnyTPM() ) Then
BdeArgs.SetArg "tpm",True
End If
Else
If Not(BdeArgs.IsSet("sk")) And _
Not(oVolume.UsesKey()) Then
Fail FormatStr("sk_required")
End If
End If
End If
'--- If no password is set for this volume error out to the user ---'
If Not(BdeArgs.IsSet("rp")) _
And Not( oVolume.UsesPassword() ) Then
If BdePolicyAllowsPassword() Then
Fail FormatStr("no_recovery_password")
ElseIf Not BdeArgs.IsSet("rk") _
And Not oVolume.UsesKey() Then
Fail FormatStr("no_recovery_key")
End If
End If
ProtectorsAdd(oVolume)
bDoHardwareTest = Not(BdeArgs.IsSet("s")) And oVolume.IsOsVolume()
If bDoHardwareTest Then
oVolume.EncryptAfterHardwareTest nEncryption
Else
oVolume.Encrypt nEncryption
End If
Else
bWasDecrypted = False
oVolume.Encrypt nEncryption
WScript.StdOut.WriteLine GLR.Localize("no_key_protectors")
End If
If bWasDecrypted Then
If bDoHardwareTest Then
ProduceHardwareTestOutput(oVolume)
Else
WScript.StdOut.WriteLine FormatStr("encrypt_started")
End If
ElseIf oVolume.IsEncrypted() Then
WScript.StdOut.WriteLine GLR.Localize("encrypt_complete")
Else
WScript.StdOut.WriteLine GLR.Localize("encrypt_progress")
End If
If oVolume.IsEncrypted() Then
If oVolume.IsProtected() Then
WScript.StdOut.WriteLine FormatStr("on_already")
Else
WScript.StdOut.WriteLine FormatStr("on_enabled")
End If
End If
oVolume.EnableKeyProtectors()
End Function
Function ProtectorsAdd(oEncVolume)
ProtectorsAddFlag oEncVolume,False
End Function
Function ProtectorsAddFlag(oVolume,tFail)
Dim bTPM,bTPMPresent,bTPMAvailable
Dim sRecoveryKey,bRecoveryKey,bRecoveryKeyPresent
Dim sTPM_Key,bTPM_Key,bTPM_KeyPresent
Dim sExtraKey,bExtraKey
Dim sTPM_PIN,bTPM_PIN,bTPM_PINPresent
Dim sTPM_PIN_Key,bTPM_PIN_Key,bTPM_PIN_KeyPresent
Dim bAutoUnlock
Dim sPassword,bPasswordPresent,bPassword
Dim nEncryption
Dim nLockStatus,nConversionStatus,nEncryptPercentage
Dim nProtectionStatus
Dim rc,sKeyProtector,sVolName
Dim aKeyProtectors,nDeleteType
sRecoveryKey = BdeArgs.GetArg("recoverykey")
bRecoveryKey = BdeArgs.IsSet( "recoverykey")
bRecoveryKeyPresent = oVolume.UsesKey()
sTPM_Key = BdeArgs.GetArg("tsk")
bTPM_Key = BdeArgs.IsSet( "tsk")
bTPM_KeyPresent = oVolume.UsesTPMAndKey()
sExtraKey = BdeArgs.GetArg("startupkey")
bExtraKey = BdeArgs.IsSet( "startupkey")
sPassword = BdeArgs.GetArg("recoverypassword")
bPassword = BdeArgs.IsSet( "recoverypassword")
bPasswordPresent = oVolume.UsesPassword()
sTPM_PIN = BdeArgs.GetArg("tp")
bTPM_PIN = BdeArgs.IsSet( "tp")
bTPM_PINPresent = oVolume.UsesTPMAndPIN()
sTPM_PIN_Key = BdeArgs.GetArg("tpsk")
bTPM_PIN_Key = BdeArgs.IsSet( "tpsk")
bTPM_PIN_KeyPresent = oVolume.UsesTPMAndPINAndKey()
bTPM = BdeArgs.GetArg("tpm")
bTPMPresent = oVolume.UsesTPM()
bTPMAvailable = False
sVolName = BdeArgs.GetArg("volumeletter")
nDeleteType = Empty
If (bTPM Or bTPM_PIN Or bTPM_Key Or bTPM_PIN_Key) And Not oVolume.IsOSVolume() Then
Fail(GLR.Localize("not_os_volume_error"))
End if
If (bTPM Or bTPM_PIN Or bTPM_Key Or bTPM_PIN_Key) Then
If Not(BdeCommonCheckTpmCapability()) Then
Fail(GLR.Localize("no_tpm_error"))
End If
End If
If (bTPM_PIN_Key And ((Not bTPM_PIN) Or (Not bTPM_Key))) Then
Fail(GLR.Localize("tpsk_parameters_missing"))
End if
If bRecoveryKey Or bExtraKey Or bPassword Or bTPM Or bTPM_PIN _
Or bTPM_Key Or bTPM_PIN_Key Then
WScript.StdOut.WriteLine GLR.Localize("key_protectors_added") & vbCrLf
End If
'Now set up the drive to be protected via the
'Specified Method
'--------------------------'
If bRecoveryKey Then
sKeyProtector = oVolume.AddExternalKey()
oVolume.DoKeyProtector sKeyProtector,sRecoveryKey
End If
If bExtraKey Then
sKeyProtector = oVolume.AddExternalKey()
oVolume.DoKeyProtector sKeyProtector,sExtraKey
End If
If bPassword Then
sKeyProtector = oVolume.AddPassword(sPassword)
If IsEmpty(sKeyProtector) Then
If Not(bRecoveryKey Or bRecoveryKeyPresent) Then
Fail GLR.Localize("no_recovery_key")
End If
'---- We're not failing, so we need to indicate that this wasn't done ---'
bPassword = False
Else
oVolume.DoKeyProtector sKeyProtector,empty
sPassword = oVolume.GetPassword(sKeyProtector)
End If
End If
'TPM only
'----------------------'
If bTPM Then
sKeyProtector = oVolume.AddTpm()
oVolume.DoKeyProtector sKeyProtector,empty
End If
'------------------------'
'TPM and Numeric PIN
'----------------------'
If (Not bTPM_PIN_Key) And bTPM_PIN Then
sKeyProtector = oVolume.AddTpmAndPIN(sTPM_PIN)
oVolume.DoKeyProtector sKeyProtector,empty
End If
'TPM and External Key
'-----------------------'
If (Not bTPM_PIN_Key) And bTPM_Key Then
sKeyProtector = oVolume.AddTpmAndKey()
oVolume.DoKeyProtector sKeyProtector,sTPM_Key
End If
'TPM and Numeric PIN and External Key
'-----------------------'
If bTPM_PIN_Key and bTPM_PIN and bTPM_Key Then
sKeyProtector = oVolume.AddTpmAndPINAndKey(sTPM_PIN)
oVolume.DoKeyProtector sKeyProtector,sTPM_Key
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_KEY
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM
End If
If (Not bTPM_PIN_Key) And (bTPM_PIN Or bTPM_Key) Then
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
End If
If bTPM Then
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_KEY
oVolume.DeleteKeyProtectorByType kBDE_PROTECTOR_TYPE_TPM_PIN_KEY
End If
If bPassword Then
ProduceRecoveryPasswordOutput oVolume,sPassword
End If
If Not(bRecoveryKey Or bExtraKey Or bPassword Or bTpm _
Or bTPM_PIN Or bTPM_Key Or bTPM_PIN_Key Or bExtraKey) and tFail Then
Fail GLR.Localize("protectors_not_added")
End If
End Function
'--------------------------------------------'
'------------------ autounlock --------------'
'--------------------------------------------'
Function DoAutounlock(arg)
Dim oVolume,bEnable,bDisable,nLockStatus,bClearAll
Dim sKeyProtector,bIsAutoUnlockEnabled
bIsAutoUnlockEnabled = False
bEnable = BdeArgs.GetArg("enable")
bDisable = BdeArgs.GetArg("disable")
bClearAll = BdeArgs.IsSet("clearallkeys")
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
If bEnable And bDisable Then
Fail GLR.Localize("both_enable_dis_error")
End If
If oVolume.IsLocked() Then
Fail FormatStr("disklock_fail")
End If
If bEnable Or bDisable Then
If Not(oVolume.IsDataVolume()) Then
Fail FormatStr("not_data_volume_error")
End If
bIsAutoUnlockEnabled = oVolume.IsAutoUnlockEnabled(sKeyProtector)
If bEnable Then
If bIsAutoUnlockEnabled Then
Fail GLR.Localize("volume_bound_error")
End If
sKeyProtector = oVolume.EnableAutoUnlock()
WScript.StdOut.WriteLine GLR.Localize("key_protectors_added")
oVolume.DoKeyProtector sKeyProtector,Empty
Else
If Not(bIsAutoUnlockEnabled) Then
Fail GLR.Localize("volumedisabled_error")
End If
oVolume.DisableAutoUnlock()
BdeArgs.FormatLine 0,VBsprintf(GLR.Localize("autounlock_disable_msg"),_
Array(sKeyProtector))
End If
End If
If bClearAll Then
If Not(oVolume.IsOsVolume()) Then
Fail FormatStr("clearall_notos")
End If
oVolume.ClearAllAutoUnlockKeys()
BdeArgs.FormatLine 0,VBSprintf(GLR.Localize("clearall_msg"),_
Array(oVolume.DriveLetter))
End If
End Function
'--------------------------------------------'
'------------------ unlock ------------------'
'--------------------------------------------'
Function DoUnlock(arg)
Dim oVolume
Dim sRecoveryFile,sPassword
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
sRecoveryFile = BdeArgs.GetArg("recoverykey")
sPassword = BdeArgs.GetArg("recoverypassword")
If Not(oVolume.IsLocked()) Then
Fail GLR.Localize("diskunlocked_error")
End If
If IsEmpty(sRecoveryFile) And IsEmpty(sPassword) Then
Fail GLR.Localize("recovery_data_needed")
End If
If Not(IsEmpty(sRecoveryFile)) Then
oVolume.UnlockWithKeyFile(sRecoveryFile)
WScript.StdOut.WriteLine VBsprintf(GLR.Localize("unlock_succ_key"),_
Array(sRecoveryFile,oVolume.DriveLetter))
End If
If Not(IsEmpty(sPassword)) Then
oVolume.UnlockWithNumericalPassword(sPassword)
WScript.StdOut.WriteLine VBsprintf(GLR.Localize("unlock_succ_passw"),_
Array(oVolume.DriveLetter))
End If
End Function
'--------------------------------------------'
'------------------ Lock ------------------'
'--------------------------------------------'
Function DoLock(arg)
Dim oVolume,tForceDismount
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
tForceDismount = BdeArgs.GetArg("forcedismount")
If oVolume.IsLocked() Then
Fail FormatStr("diskunlock_fail")
End If
If oVolume.IsOsVolume() Then
Fail FormatStr("os_not_lockable")
End If
oVolume.Lock(tForceDismount)
WScript.StdOut.WriteLine(VBsprintf(GLR.Localize("lock_msg"),_
Array(BdeArgs.GetArg("volumeletter"))))
End Function
'--------------------------------------------'
'------------------ Pause ------------------'
'--------------------------------------------'
Function DoPause(arg)
Dim oVolume
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
If oVolume.IsLocked() Then
Fail GLR.Localize("diskunlock_fail")
End If
If oVolume.IsPaused() Then
If oVolume.IsEncrypting() Then
WScript.StdOut.WriteLine GLR.Localize("disk_enc_already_paused")
Else
WScript.StdOut.WriteLine GLR.Localize("disk_dec_already_paused")
End If
Else
If Not(oVolume.IsDecrypting() Or oVolume.IsEncrypting()) Then
Fail FormatStr("disk_unpauseable")
End If
oVolume.PauseConversion()
If oVolume.IsEncrypting() Then
WScript.StdOut.WriteLine GLR.Localize("encryption_paused")
Else
WScript.StdOut.WriteLine(GLR.Localize("decryption_paused"))
End If
End If
WScript.StdOut.WriteLine GLR.Localize("pause_moreinfo")
End Function
'--------------------------------------------'
'------------------ Resume ------------------'
'--------------------------------------------'
Function DoResume(arg)
Dim oVolume
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
If oVolume.IsLocked() Then
Fail GLR.Localize("diskunlock_fail")
End If
If oVolume.IsPaused() Then
oVolume.ResumeConversion()
If oVolume.IsEncrypting() Then
WScript.StdOut.WriteLine(GLR.Localize("encryption_resumed"))
Else
WScript.StdOut.WriteLine(GLR.Localize("decryption_resumed"))
End If
ElseIf oVolume.IsEncrypting() Then
WScript.StdOut.WriteLine( GLR.Localize("disk_already_encrypting"))
ElseIf oVolume.IsDecrypting() Then
WScript.StdOut.WriteLine( GLR.Localize("disk_already_decrypting"))
Else
Fail( FormatStr("disk_unresumeable") )
End If
WScript.StdOut.WriteLine GlR.Localize("on_moreinfo")
End Function
'-----------------------------------------'
'------------------ OFF ------------------'
'-----------------------------------------'
Function DoOff(arg)
Dim nLockStatus,oVolume,bAutoKeys
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
If oVolume.IsLocked() Then
Fail GLR.Localize("disklock_fail")
End If
If oVolume.IsOsVolume() Then
bAutoKeys = oVolume.IsAutoUnlockKeyStored()
If bAutoKeys Then
Fail VBsprintf(GLR.Localize("os_contains_keys"),Array(oVolume.DriveLetter))
End If
End If
oVolume.Decrypt()
WScript.StdOut.WriteLine GLR.Localize("bde_off_done")
End Function
'-----------------------------------------'
'-------------- TPM initialization--------'
'-----------------------------------------'
Function DoTpm(arg)
Dim oTpm,oTpmService
Dim bTurnOn,bOwn,sOwnerPassword
Dim bActivated,bEnabled,bOwnerAllowed
Dim bPhysicalPresenceEnabled,nPhysicalPresenceTrans
Dim bOwned,abOwnerAuthDigest
bActivated = False
bEnabled = False
bOwnerAllowed = False
bPhysicalPresenceEnabled = False
bOwned = False
bTurnOn = BdeArgs.IsSet("turnon")
bOwn = BdeArgs.IsSet("takeownership")
sOwnerPassword = BdeArgs.GetArg("TakeOwnership")
BdeCommonStartup()
Set oTpmService = GetWMIObject(skTpmPath)
On Error Resume Next
Set oTpm = oTpmService.Get("Win32_Tpm=@")
If Err.Number<>0 Then
Fail GLR.Localize("no_tpm_detected")
End If
On Error GoTo 0
CheckRC oTPM.IsActivated( bActivated ) ,_
gComGLR.Localize("check_active_fail")
If bActivated Then
CheckRC oTPM.IsEnabled( bEnabled ) ,_
gComGLR.Localize("check_enable_fail")
If bEnabled Then
CheckRC oTPM.IsOwnershipAllowed( bOwnerAllowed ) ,_
gComGLR.Localize("check_owner_fail")
End If
End If
'---- Turn on the TPM via a physical presence command ----'
If bTurnOn Then
'----- bOwnerAllowed indicates that the TPM is already on ---'
If bOwnerAllowed Then
Finish GLR.Localize("tpm_is_on")
End If
If IsEmpty(oTpm.PhysicalPresenceVersionInfo) Or _
oTpm.PhysicalPresenceVersionInfo = "Not supported" Or _
oTpm.PhysicalPresenceVersionInfo = "Unknown" Then
Finish GLR.Localize("no_physical_presence")
End If
CheckRC oTPM.SetPhysicalPresenceRequest(kPHYS_REQ_ENABLE_ACTIVATE),_
GLR.Localize("phys_pres_req_error")
CheckRC oTpm.GetPhysicalPresenceTransition(nPhysicalPresenceTrans),_
GLR.Localize("phys_pres_resp_error")
If nPhysicalPresenceTrans = kTPM_TRANSITION_SHUTDOWN Then
Finish VBsprintf(GLR.Localize("tpm_shutdown_req"),Empty)
ElseIf nPhysicalPresenceTrans = kTPM_TRANSITION_RESTART Then
Finish VBsprintf(GLR.Localize("tpm_restart_req"),Empty)
Else
Fail GLR.Localize("tpm_transition_error")
End If
End If
'------- END Tpm On ----'
'----- Ownership, convert to owner auth digest
'----- Then take ownership
If bOwn Then
If Not(bOwnerAllowed) Then
Fail VBsprintf(GLR.Localize("tpm_not_on"),empty)
End If
CheckRC oTPM.IsOwned(bOwned),_
GLR.Localize("isowned_error")
If bOwned Then
Finish VBsprintf(GLR.Localize("tpm_already_owned"),empty)
End If
If Len(sOwnerPassword) < kMIN_OWNER_PASSWORD_LENGTH Then
Fail VBsprintf(GLR.Localize("password_length_bad"),_
Array(kMIN_OWNER_PASSWORD_LENGTH))
End If
CheckRC oTPM.ConvertToOwnerAuth(sOwnerPassword,abOwnerAuthDigest),_
GLR.Localize("convert_auth_error")
CheckRC oTPM.TakeOwnership(abOwnerAuthDigest),_
GLR.Localize("take_owner_error")
Finish VBsprintf(GLR.Localize("owner_success"),Empty)
End If
End Function
'-----------------------------------------'
'-------------- ForceRecovery ------------'
'-----------------------------------------'
Function DoForce(arg)
Dim oVolume,aProtectors,sKeyProtector
Dim bDeleted : bDeleted = False
Dim rc,nKeyProtType,bRpPresent,bRkPresent
Dim nProtectionStatus
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
If Not( oVolume.UsesPassword() Or oVolume.UsesKey()) Then
Fail VBSprintf(GLR.Localize("no_recovery"),Array(oVolume.DriveLetter))
End If
If Not(oVolume.IsProtected()) Then
Fail VBSprintf(GLR.Localize("force_noton"),Array(oVolume.DriveLetter))
End If
aProtectors = oVolume.GetKeyProtectors(0)
If UBound(aProtectors) < 0 Then
Fail(GLR.Localize("nokeyprots"))
End If
For Each sKeyProtector In aProtectors
nKeyProtType = oVolume.GetKeyProtectorType(sKeyProtector)
If nKeyProtType = kBDE_PROTECTOR_TYPE_TPM Or _
nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN Or _
nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_KEY Or _
nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN_KEY Then
oVolume.DoKeyProtector sKeyProtector,Empty
End If
Next
For Each sKeyProtector In aProtectors
nKeyProtType = oVolume.GetKeyProtectorType(sKeyProtector)
If nKeyProtType = kBDE_PROTECTOR_TYPE_TPM Or _
nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN Or _
nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_KEY Or _
nKeyProtType = kBDE_PROTECTOR_TYPE_TPM_PIN_KEY Then
oVolume.DeleteKeyProtector( sKeyProtector)
bDeleted = True
End If
Next
If bDeleted Then
WScript.StdOut.WriteLine ""
Else
BdeArgs.FormatLine 0,VBsprintf(GLR.Localize("force_unable"),Array(oVolume.DriveLetter))
End If
BdeArgs.FormatLine 0,Vbsprintf(GLR.Localize("force_warning"),Array(oVolume.DriveLetter))
End Function
'-----------------------------------------'
'-------------- PROTECTORS ---------------'
'-----------------------------------------'
Function DoProtectors(sCommand)
Dim oVolume,aProtectors
Dim bDelete,bGet,bDisable,bEnable,rc
Dim sProtector,nType,sGUID,sKeyDir
Dim bIsAutoUnlockEnabled,sProtID
Dim sKeyProtector,bAdd
BdeCommonStartup()
Set oVolume = new VolumeObject
oVolume.CreateByReference(GetEncryptableVolume())
bDelete = False
bGet = False
bAdd = False
bDisable= False
bEnable = False
aProtectors = Array()
Select Case sCommand
Case "del"
bDelete = True
Case "get"
bGet = True
Case "add"
bAdd = True
Case "disable"
bDisable = True
Case "enable"
bEnable = True
Case Else
WScript.StdOut.WriteLine VbSprintf(GLR.Localize("protector.bad_command"),Array(sCommand))
End Select
If bGet Or bDelete Then
nType = BdeArgs.GetArg("type")
sGUID = BdeArgs.GetArg("id")
If Not(IsEmpty(nType)) And Not(IsEmpty(sGUID)) Then
Fail GLR.Localize("protector.both_error")
End If
'---- Determine which protectors we're using ---'
If IsEmpty(nType) Then
nType = kBDE_PROTECTOR_TYPE_ANY
End If
If Not(IsEmpty(sGUID)) Then
aProtectors = Array(sGUID)
ElseIf IsEmpty(sGUID) Then
aProtectors = oVolume.GetKeyProtectors(nType)
End If
'------------'
WScript.StdOut.WriteLine FormatStr3("protector.preamble",empty,oVolume)
'------ Produce preamble output info------'
If IsEmpty(sGUID) Then
If nType = kBDE_PROTECTOR_TYPE_ANY Then
WScript.StdOut.WriteLine FormatStr("protector.all")
Else
WScript.StdOut.WriteLine FormatStr2("protector.type",_
ProtectorTypeToString(nType))
End If
Else
WScript.StdOut.WriteLine FormatStr2("protector.guid",sGUID)
End If
If UBound(aProtectors) < 0 Then
Fail GLR.Localize("protector.none")
End If
'-------------'
'-------- Do the actual deletion --------'
If bDelete Then
For Each sProtector In aProtectors
oVolume.DoKeyProtector sProtector,Empty
Next
For Each sProtector In aProtectors
oVolume.DeleteKeyProtector sProtector
Next
End If
'--------------'
'------- Display the Key Protectors ------'
If bGet Then
sKeyDir = BdeArgs.GetArg("saveexternalkey")
For Each sKeyProtector In aProtectors
oVolume.DoKeyProtector sKeyProtector,sKeyDir
next
End If
'-----------------'
End If
If bDisable Then
'----------Disable all BDE Keys -------------'
oVolume.DisableKeyProtectors()
WScript.StdOut.WriteLine VBsprintf(GLR.Localize("protector.disable"),empty)
End If
If bEnable Then
'----------Enable all BDE Keys -------------'
oVolume.EnableKeyProtectors()
WScript.StdOut.WriteLine VBsprintf(GLR.Localize("protector.enable"),empty)
End If
If bAdd Then
ProtectorsAddFlag oVolume,True
End If
End function
Dim g_RecoveryPasswordOutputProduced
g_RecoveryPasswordOutputProduced = False
'----- This function produces the warning message for saving
'----- the password provided. If sPassword is empty it finds the first
'----- password on the disk and uses that for the message. If none
'----- are found, no message is produced.
Function ProduceRecoveryPasswordOutput(oVolume,sPassword)
Dim aProtectors
If Not g_RecoveryPasswordOutputProduced Then
If IsEmpty(sPassword) Then
aProtectors = oVolume.GetKeyProtectors(kBDE_PROTECTOR_TYPE_PASSWORD)
If UBound(aProtectors) > -1 Then
sPassword = oVolume.GetPassword(aProtectors(0))
End If
End If
If Not(IsEmpty(sPassword)) Then
g_RecoveryPasswordOutputProduced = True
WScript.StdOut.WriteLine FormatStr("on_warning")
BdeArgs.FormatLine 4, FormatStr2("hardware_test_1",_
Array(1,sPassword))
End If
End If
ProduceRecoveryPasswordOutput = g_RecoveryPasswordOutputProduced
End Function
Function ProduceHardwareTestOutput(oVolume)
Dim aProtectors,iHardware
If oVolume.IsHardwareTestPending() Then
iHardware = 1
If ProduceRecoveryPasswordOutput(oVolume,Empty) Then
iHardware = iHardware +1
Else
WScript.StdOut.WriteLine FormatStr("on_warning")
End If
If oVolume.UsesKey() Or oVolume.UsesTpmAndKey() Then
WScript.StdOut.WriteLine FormatStr2("hardware_test_2",iHardware)
iHardware = iHardware+1
End If
WScript.StdOut.WriteLine FormatStr2("hardware_test_3",iHardware)
WScript.StdOut.WriteLine FormatStr2("hardware_test_4",iHardware+1)
End If
If oVolume.IsHardwareTestFailed() Then
WScript.StdOut.WriteLine FormatStr2("hardware_fail",oVolume.HardwareTestError)
End If
End Function
'-----------------------------------------'
'------------------ STATUS ---------------'
'-----------------------------------------'
Function DoStatus(arg)
Dim aEncVolumes
Dim oEncVolume
Dim oVolume
Dim oTemp
Dim nTotalSizeGB
Dim aTemp
Dim oProperty
Dim rc
Dim sVolName
Dim sWhere
Dim oOutParams
Dim bIsAutoUnlockEnabled
Dim VolumeLabel
sVolName = BdeArgs.GetArg("v")
'--------Main Script------------'
BdeCommonStartup()
If IsEmpty(sVolName) Then
'Examine all Win32 Encryptable Volumes
Set aEncVolumes = objWMIServiceSecurity.ExecQuery("Select * from Win32_EncryptableVolume")
If aEncVolumes.Count < 1 Then
Fail GLR.Localize("status.execquery_error")
End If
WScript.StdOut.WriteLine FormatStr("status.statusdisp")
Else
aEncVolumes = Array(GetEncryptableVolume())
End If
For Each oEncVolume in aEncVolumes
Set oVolume = new VolumeObject
oVolume.CreateByReference(oEncVolume)
'- Find the physical volume object associated with the encryptable one.
'- THIS SHOULD NOT BE DONE IN THE OPPOSITE MANNER
'- All encryptable volumes are associated with a physical volume
'- However, not all physical volumes are associated with an encryptable
'- So if you change this loop to find the physical volume first, you
'- will get null object errors on this association.
VolumeLabel = oVolume.Label
nTotalSizeGB = oVolume.Capacity
Dim aProtectors, sProtector, nKeyProtType, sProtName,sprotID
sprotID = Empty
WScript.StdOut.WriteLine FormatStr3("status.vol",Empty,oVolume)
WScript.StdOut.WriteLine oVolume.PrintOSVolume()
WScript.StdOut.WriteLine("")
WScript.StdOut.WriteLine FormatStr3("status.sizedisp",Empty,oVolume)
WScript.StdOut.WriteLine FormatStr3("status.convstat",_
ConversionStatusToString(oVolume.ConversionStatus),_
oVolume)
WScript.StdOut.WriteLine FormatStr3("status.encdisp",_
oVolume.EncryptionPercentage,_
oVolume)
WScript.StdOut.WriteLine FormatStr3("status.encmethdisp",_
EncryptionMethodToString(oVolume.EncryptionMethod),_
oVolume)
WScript.StdOut.WriteLine FormatStr3("status.protstatus",_
ProtectionStatusToString(oVolume.ProtectionStatus),_
oVolume)
WScript.StdOut.WriteLine FormatStr3("status.lockstat",_
LockStatusToString(oVolume.LockStatus),_
oVolume)
'-------'
aProtectors = oVolume.GetKeyProtectors(0)
If Not(oVolume.IsOsVolume()) Then
bIsAutoUnlockEnabled = oVolume.IsAutoUnlockEnabled(sProtID)
If bIsAutoUnlockEnabled Then
WScript.StdOut.WriteLine FormatStr2("status.autounlockstateon",empty)
Else
WScript.StdOut.WriteLine FormatStr2("status.autounlockstateoff",empty)
End If
End if
If UBound(aProtectors) < 0 Then
WScript.StdOut.WriteLine GLR.Localize("status.nokeyprots")
Else
WScript.StdOut.WriteLine GLR.Localize("status.keyprot1")
For Each sProtector In aProtectors
nKeyProtType = oVolume.GetKeyProtectorType(sProtector)
If sProtID = sProtector Then
WScript.StdOut.WriteLine Space(8) & ProtectorTypeToString(nKeyProtType) & " "_
& GLR.Localize("status.required_auto")
Else
WScript.StdOut.WriteLine Space(8) & ProtectorTypeToString(nKeyProtType)
End If
Next
End If
WScript.StdOut.WriteLine " "
ProduceHardwareTestOutput(oVolume)
If BdeArgs.GetArg("p") And Not(IsEmpty(sVolName)) Then
If oVolume.IsProtected() Then
WScript.Quit 0
Else
WScript.Quit 1
End If
End if
Next
End Function
'-------------------------------------------------------------'
'---------------- END STATUS ---------------------------------'
'-------------------------------------------------------------'
</script>
</job>
</package>