Export Windows 7 Bitlocker key package to a file
Hello, I am trying to export windows 7 bitlocker key package to a file by use the following script (This script from Microsoft), some computer is OK, but on some computers, it was failed, the error message is: Script: D:\GetBitLockerKeyPackage.vbs Line: 236 Char: 3 Error: Invalid procedure call or argument Code: 800A0005 Source: Microsoft VBScript runtime error Here is the script, could you please help me? ' The following sample script exports a new key package from an unlocked, encrypted volume. ' To run this script, start by saving the code into a VBS file (for example, GetBitLockerKeyPackage.vbs). ' Then, open an administrator command prompt and use “cscript” to run the saved file (for example, type "cscript GetBitLockerKeyPackage.vbs -?"). ' -------------------------------------------------------------------------------- ' Usage ' -------------------------------------------------------------------------------- Sub ShowUsage Wscript.Echo "USAGE: GetBitLockerKeyPackage [VolumeLetter/DriveLetter:] [Path To Saved Key Package]" Wscript.Echo Wscript.Echo "Example: GetBitLockerKeyPackage C: E:\bitlocker-backup-key-package" WScript.Quit End Sub ' -------------------------------------------------------------------------------- ' Parse Arguments ' -------------------------------------------------------------------------------- Set args = WScript.Arguments Select Case args.Count Case 2 If args(0) = "/?" Or args(0) = "-?" Then ShowUsage Else strDriveLetter = args(0) strFilePath = args(1) End If Case Else ShowUsage End Select ' -------------------------------------------------------------------------------- ' Other Inputs ' -------------------------------------------------------------------------------- ' Target computer name ' Use "." to connect to the local computer strComputerName = "." ' Default key protector ID to use. Specify "" to let the script choose. strDefaultKeyProtectorID = "" ' strDefaultKeyProtectorID = "{001298E0-870E-4BA0-A2FF-FC74758D5720}" ' sample ' -------------------------------------------------------------------------------- ' Connect to the BitLocker WMI provider class ' -------------------------------------------------------------------------------- strConnectionStr = "winmgmts:" _ & "{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" _ & strComputerName _ & "\root\cimv2\Security\MicrosoftVolumeEncryption" On Error Resume Next 'handle permission errors Set objWMIService = GetObject(strConnectionStr) If Err.Number <> 0 Then WScript.Echo "Failed to connect to the BitLocker interface (Error 0x" & Hex(Err.Number) & ")." Wscript.Echo "Ensure that you are running with administrative privileges." WScript.Quit -1 End If On Error GoTo 0 strQuery = "Select * from Win32_EncryptableVolume where DriveLetter='" & strDriveLetter & "'" Set colTargetVolumes = objWMIService.ExecQuery(strQuery) If colTargetVolumes.Count = 0 Then WScript.Echo "FAILURE: Unable to find BitLocker-capable drive " & strDriveLetter & " on computer " & strComputerName & "." WScript.Quit -1 End If ' there should only be one volume found For Each objFoundVolume in colTargetVolumes set objVolume = objFoundVolume Next ' objVolume is now our found BitLocker-capable disk volume ' -------------------------------------------------------------------------------- ' Perform BitLocker WMI provider functionality ' -------------------------------------------------------------------------------- ' Collect all possible valid key protector ID's that can be used to get the package ' ---------------------------------------------------------------------------------- nNumericalKeyProtectorType = 3 ' type associated with "Numerical Password" protector nRC = objVolume.GetKeyProtectors(nNumericalKeyProtectorType, aNumericalKeyProtectorIDs) If nRC <> 0 Then WScript.Echo "FAILURE: GetKeyProtectors failed with return code 0x" & Hex(nRC) WScript.Quit -1 End If nExternalKeyProtectorType = 2 ' type associated with "External Key" protector nRC = objVolume.GetKeyProtectors(nExternalKeyProtectorType, aExternalKeyProtectorIDs) If nRC <> 0 Then WScript.Echo "FAILURE: GetKeyProtectors failed with return code 0x" & Hex(nRC) WScript.Quit -1 End If ' Get first key protector of the type "Numerical Password" or "External Key", if any ' ---------------------------------------------------------------------------------- if strDefaultKeyProtectorID = "" Then ' Save first numerical password, if exists If UBound(aNumericalKeyProtectorIDs) <> -1 Then strDefaultKeyProtectorID = aNumericalKeyProtectorIDs(0) End If ' No numerical passwords exist, save the first external key If strDefaultKeyProtectorID = "" and UBound(aExternalKeyProtectorIDs) <> -1 Then strDefaultKeyProtectorID = aExternalKeyProtectorIDs(0) End If ' Fail case: no recovery key protectors exist. If strDefaultKeyProtectorID = "" Then WScript.Echo "FAILURE: Cannot create backup key package because no recovery passwords or recovery keys exist. Check that BitLocker protection is on for this drive." WScript.Echo "For help adding recovery passwords or recovery keys, type ""manage-bde -protectors -add -?""." WScript.Quit -1 End If End If ' Get some information about the chosen key protector ID ' ---------------------------------------------------------------------------------- ' is the type valid? nRC = objVolume.GetKeyProtectorType(strDefaultKeyProtectorID, nDefaultKeyProtectorType) If Hex(nRC) = "80070057" Then WScript.Echo "The key protector ID " & strDefaultKeyProtectorID & " is not valid." WScript.Echo "This ID value may have been provided by the script writer." ElseIf nRC <> 0 Then WScript.Echo "FAILURE: GetKeyProtectorType failed with return code 0x" & Hex(nRC) WScript.Quit -1 End If ' what's a string that can be used to describe it? strDefaultKeyProtectorType = "" Select Case nDefaultKeyProtectorType Case nNumericalKeyProtectorType strDefaultKeyProtectorType = "recovery password" Case nExternalKeyProtectorType strDefaultKeyProtectorType = "recovery key" Case Else WScript.Echo "The key protector ID " & strDefaultKeyProtectorID & " does not refer to a valid recovery password or recovery key." WScript.Echo "This ID value may have been provided by the script writer." End Select ' Save the backup key package using the chosen key protector ID ' ---------------------------------------------------------------------------------- nRC = objVolume.GetKeyPackage(strDefaultKeyProtectorID, oKeyPackage) If nRC <> 0 Then WScript.Echo "FAILURE: GetKeyPackage failed with return code 0x" & Hex(nRC) WScript.Quit -1 End If ' Validate file path Set fso = CreateObject("Scripting.FileSystemObject") If (fso.FileExists(strFilePath)) Then WScript.Echo "The file " & strFilePath & " already exists. Please use a different path." WScript.Quit -1 End If Dim oKeyPackageByte, bKeyPackage For Each oKeyPackageByte in oKeyPackage 'WScript.echo "key package byte: " & oKeyPackageByte bKeyPackage = bKeyPackage & ChrB(oKeyPackageByte) Next ' Save binary data to the file SaveBinaryDataText strFilePath, bKeyPackage ' Display helpful information ' ---------------------------------------------------------------------------------- WScript.Echo "The backup key package has been saved to " & strFilePath & "." WScript.Echo "IMPORTANT: To use this key package, the " & strDefaultKeyProtectorType & " must also be saved." ' Display the recovery password or a note about saving the recovery key file If nDefaultKeyProtectorType = nNumericalKeyProtectorType Then nRC = objVolume.GetKeyProtectorNumericalPassword(strDefaultKeyProtectorID, sNumericalPassword) If nRC <> 0 Then WScript.Echo "FAILURE: GetKeyProtectorNumericalPassword failed with return code 0x" & Hex(nRC) WScript.Quit -1 End If WScript.Echo "Save this recovery password: " & sNumericalPassword ElseIf nDefaultKeyProtectorType = nExternalKeyProtectorType Then WScript.Echo "The saved key file is named " & strDefaultKeyProtectorID & ".BEK" WScript.Echo "For help re-saving this external key file, type ""manage-bde -protectors -get -?""" End If '---------------------------------------------------------------------------------------- ' Utility functions to save binary data '---------------------------------------------------------------------------------------- Function SaveBinaryDataText(FileName, ByteArray) 'Create FileSystemObject object Dim FS: Set FS = CreateObject("Scripting.FileSystemObject") 'Create text stream object Dim TextStream Set TextStream = FS.CreateTextFile(FileName) 'Convert binary data To text And write them To the file TextStream.Write BinaryToString(ByteArray) End Function Function BinaryToString(Binary) Dim I, S For I = 1 To LenB(Binary) S = S & Chr(AscB(MidB(Binary, I, 1))) Next BinaryToString = S End Function Regards, Bruce Li_China
October 29th, 2010 5:47am

Hi, For script related questions, I suggest you discuss in our Script Center forum. Script Center Home Page Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2010 5:23am

Bruce Did you run this script ?? if yes please reply because I have to get key package file thank you mkady7
April 21st, 2011 1:35pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics