BloodyFoxy

VHD [un]mount CMD menu

Oct 6th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2.  
  3. :: BatchGotAdmin
  4. :-------------------------------------
  5. REM  --> Check for permissions
  6. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  7.  
  8. REM --> If error flag set, we do not have admin.
  9. if '%errorlevel%' NEQ '0' (
  10.     echo Requesting administrative privileges...
  11.     goto UACPrompt
  12. ) else ( goto gotAdmin )
  13.  
  14. :UACPrompt
  15.     echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  16.     echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
  17.  
  18.     "%temp%\getadmin.vbs"
  19.     exit /B
  20.  
  21. :gotAdmin
  22.     if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
  23.     pushd "%CD%"
  24.     CD /D "%~dp0"
  25. :--------------------------------------
  26.  
  27. REM.-- Prepare the Command Processor
  28. SETLOCAL ENABLEEXTENSIONS
  29. SETLOCAL ENABLEDELAYEDEXPANSION
  30.  
  31.  
  32. :menuLOOP
  33. echo.
  34. echo.= Menu =================================================
  35. echo.
  36. for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.  %%B  %%C
  37. set choice=
  38. echo.&set /p choice=Make a choice or hit ENTER to quit: ||GOTO:EOF
  39. echo.&call:menu_%choice%
  40. GOTO:menuLOOP
  41.  
  42. ::-----------------------------------------------------------
  43. :: menu functions follow below here
  44. ::-----------------------------------------------------------
  45.  
  46. :menu_1   Mount DOS.vhd
  47. @echo off
  48. SET DiskPartScript="%TEMP%DiskpartScript.txt"
  49. :: You may use
  50. :: set /p pathtovhd=Enter path to VHD:
  51. :: variable to enter path to file in script or play with it as you wish
  52. :: Maybe make a menu with filelist?
  53. ECHO SELECT VDISK FILE "C:\Users\Alexander\VirtualBox VMs\DOS\DOS.vhd" > %DiskPartScript%
  54. ECHO ATTACH VDISK >> %DiskPartScript%
  55. DiskPart /s %DiskPartScript%
  56. TIMEOUT /T 5
  57. CLS
  58. GOTO:EOF
  59.  
  60. :menu_2   UnMount DOS.vhd
  61. @echo off
  62. SET DiskPartScript="%TEMP%DiskpartScript.txt"
  63. ECHO SELECT VDISK FILE "C:\Users\Alexander\VirtualBox VMs\DOS\DOS.vhd" > %DiskPartScript%
  64. ECHO DETACH VDISK >> %DiskPartScript%
  65. DiskPart /s %DiskPartScript%
  66. CLS
  67. GOTO:EOF
Advertisement
Add Comment
Please, Sign In to add comment