无忧启动论坛

标题: 新的挂/ 卸载 vhd 脚本 [打印本页]

作者: dos时代菜鸟    时间: 2018-3-8 17:28
标题: 新的挂/ 卸载 vhd 脚本
本帖最后由 dos时代菜鸟 于 2018-3-8 21:47 编辑

挂载,有的  vhd 里面有 隐藏的分区,所以 用这个 可以 挂载并一起分配盘符。

  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. if *%1*==** goto :eof
  4. set file=%~dpnx1

  5. echo 正在装载 %file%

  6. >"%temp%\vhd.txt"  echo select vdisk file=%file%
  7. >>"%temp%\vhd.txt" echo attach vdisk
  8. >>%temp%\vhd.txt  echo list partition

  9. diskpart /s %temp%\vhd.txt >%temp%\vhd2.txt
  10. >"%temp%\vhd.txt"  echo select vdisk file=%file%
  11. for /f "tokens=2" %%c in (%temp%\vhd2.txt) do (
  12.   if "!begin!"=="ok" (
  13.     echo select partition %%c      >>%temp%\vhd.txt  
  14.     echo assign  noerr    >>%temp%\vhd.txt  
  15.   )
  16.   set l=%%c
  17.   if "!l:~0,1!"=="-" set begin=ok
  18. )

  19. diskpart  /s "%temp%\vhd.txt"
复制代码






把 要卸载的 vhd 拖放到这个 批处理,就可以了。
如果需要 管理员权限,可以建立一个 管理员权限的 快捷方式,再把 vhd 拖放到 这个快捷方式上。

卸载
  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION

  3. if *%1*==** goto end
  4. echo %1
  5. >%temp%\vhd.txt   echo select vdisk file=%1
  6. >>%temp%\vhd.txt  echo list partition

  7. diskpart /s %temp%\vhd.txt >%temp%\vhd2.txt
  8. for /f "tokens=2" %%c in (%temp%\vhd2.txt) do (
  9.   if "!begin!"=="ok" (
  10.     echo select partition %%c      >>%temp%\vhd.txt  
  11.     echo remove dismount  noerr    >>%temp%\vhd.txt  
  12.   )
  13.   set l=%%c
  14.   if "!l:~0,1!"=="-" set begin=ok
  15. )
  16. >>"%temp%\vhd.txt" echo DETACH vdisk

  17. diskpart /s "%temp%\vhd.txt"


  18. :end
复制代码


因为一些 vhd 有esp 等分区,挂载分配盘符以后可能需要先 remove 盘符卷再 卸载vhd文件。所以更新了一下这个脚本。
作者: hellour    时间: 2018-3-8 18:11
传说中的沙发。。。。
作者: dos时代菜鸟    时间: 2018-3-8 22:51
vhd 挂载以后 ,如果  vhd 中的 esp 分区 被 分配了盘符,卸载 vhd 以后,盘符仍然会被占用。这个可能是 win 10 的一个 bug 吧
为了稳妥起见,考虑 ,循环找出 vhd 中的每一个卷,统统 先移除盘符,再整体卸载vhd
作者: freesoft00    时间: 2018-3-9 01:09
顶起支持。
评分的比较少。没有办法,浏览dos区的人少。
作者: 窄口牛    时间: 2018-3-9 08:57
用vhd的也有限。
作者: dos时代菜鸟    时间: 2018-3-9 09:33
vhd-onekey 出来的时候,我用过一段时间,后来,就 不用了。
这玩意儿 ,就是  虚拟机 比较 方便,先挂载 复制好文件,在挂到虚拟机里面。
还有就是 系统还原 的时候 方便些。
现在系统维护 都要在 winpe 下了,就算 只是为了 覆盖一个  几百 k 的 vhd 也要 pe ,总觉得 ,进入pe 的时间 比 用 pe 干活儿的时间 还长。呵呵。
uefi ,pe ,呵呵。
uefi 下 用 shell 复制覆盖文件 应该 也可以吧。
作者: zqjiang    时间: 2018-3-10 14:53
不错 顶起支持。
作者: 幻天雨    时间: 2019-11-12 10:15
怎么改成直接挂载指定位置vhd
作者: 谪仙    时间: 2020-3-3 18:55
怎么用啊 不懂




欢迎光临 无忧启动论坛 (http://wuyou.net/) Powered by Discuz! X3.3