Windows自动挂载vhd和vhdx

Windows自动挂载vhd和vhdx

@echo off
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof
:Admin

(
  echo select vdisk file="E:\VHD\Penetration.vhd"
  echo attach vdisk
  echo list disk
) > vhdsel

(
  echo select vdisk file="E:\VHD\VirtualDisk.vhd"
  echo attach vdisk
  echo list disk
) > vhdsel1

diskpart /s vhdsel
diskpart /s vhdsel1

del /f /q vhdsel
del /f /q vhdsel1

exit

打开计划任务 taskschd.msc 更具需求添加任务计划,将脚本添加到计划即可