Advertisement
JacobPaulin

Get Device BitLocker Key

Mar 16th, 2023
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2.  
  3. @rem Checking & Prompting for run as administrator
  4. @rem --------------------------------------------------------------------------
  5. @rem Checking for permissions...
  6.  
  7. if "%PROCESSOR_ARCHITECTURE%" equ "amd64" (
  8.     "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system">nul 2>&1
  9. ) else (
  10.     "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system">nul 2>&1
  11. )
  12.  
  13. if '%errorlevel%' neq '0' (
  14.     @rem Administrator permissions not found
  15.  
  16.     echo Requesting administrative privileges...
  17.     goto UACPrompt
  18. ) else (
  19.     @rem Administrator permissions found
  20.    
  21.     goto gotAdmin
  22. )
  23.  
  24. :UACPrompt
  25.     echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  26.     set params= %*
  27.     echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
  28.  
  29.    "%temp%\getadmin.vbs"
  30.    del "%temp%\getadmin.vbs"
  31.    exit /B
  32.  
  33. :gotAdmin
  34.    pushd "%CD%"
  35.    CD /D "%~dp0"
  36. @rem --------------------------------------------------------------------------  
  37.  
  38. title Get BitLocker Key
  39.  
  40. set tempFile=%TEMP%\BitLockerKey.txt
  41.  
  42. if exist %tempFile% del %tempFile%
  43.  
  44. PowerShell -command "Get-BitLockerVolume -MountPoint C:| Select-Object -ExpandProperty KeyProtector | Where-Object KeyProtectorType -eq RecoveryPassword | Select-Object KeyProtectorID, RecoveryPassword | Format-List" > %tempFile%
  45.  
  46. for /f "usebackq skip=1 tokens=2 delims=: " %%i in (%tempFile%) do set key=%%i
  47.  
  48. echo:
  49. echo Your BitLocker Key Is: %key%
  50. echo:
  51.  
  52. set /p doCopy="Would you like copy the key to your clipboard? (y/n) "
  53.  
  54. if %doCopy%==y (
  55.     echo | set /p=%key%| clip
  56.     echo Key successfully copied!
  57. )
  58.  
  59. if exist %tempFile% del %tempFile%
  60.  
  61. echo:
  62. echo [Press any key to close this window]
  63. pause >nul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement