dos时代菜鸟 发表于 2018-3-8 17:28:00

新的挂/ 卸载 vhd 脚本

本帖最后由 dos时代菜鸟 于 2018-3-8 21:47 编辑

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

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

echo 正在装载 %file%

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

diskpart /s %temp%\vhd.txt >%temp%\vhd2.txt
>"%temp%\vhd.txt"echo select vdisk file=%file%
for /f "tokens=2" %%c in (%temp%\vhd2.txt) do (
if "!begin!"=="ok" (
    echo select partition %%c      >>%temp%\vhd.txt
    echo assignnoerr    >>%temp%\vhd.txt
)
set l=%%c
if "!l:~0,1!"=="-" set begin=ok
)

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





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

卸载
@echo off
setlocal ENABLEDELAYEDEXPANSION

if *%1*==** goto end
echo %1
>%temp%\vhd.txt   echo select vdisk file=%1
>>%temp%\vhd.txtecho list partition

diskpart /s %temp%\vhd.txt >%temp%\vhd2.txt
for /f "tokens=2" %%c in (%temp%\vhd2.txt) do (
if "!begin!"=="ok" (
    echo select partition %%c      >>%temp%\vhd.txt
    echo remove dismountnoerr    >>%temp%\vhd.txt
)
set l=%%c
if "!l:~0,1!"=="-" set begin=ok
)
>>"%temp%\vhd.txt" echo DETACH vdisk

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


:end

因为一些 vhd 有esp 等分区,挂载分配盘符以后可能需要先 remove 盘符卷再 卸载vhd文件。所以更新了一下这个脚本。

hellour 发表于 2018-3-8 18:11:20

传说中的沙发。。。。

dos时代菜鸟 发表于 2018-3-8 22:51:05

vhd 挂载以后 ,如果vhd 中的 esp 分区 被 分配了盘符,卸载 vhd 以后,盘符仍然会被占用。这个可能是 win 10 的一个 bug 吧
为了稳妥起见,考虑 ,循环找出 vhd 中的每一个卷,统统 先移除盘符,再整体卸载vhd

freesoft00 发表于 2018-3-9 01:09:21

顶起支持。
评分的比较少。没有办法,浏览dos区的人少。

窄口牛 发表于 2018-3-9 08:57:27

用vhd的也有限。

dos时代菜鸟 发表于 2018-3-9 09:33:55

vhd-onekey 出来的时候,我用过一段时间,后来,就 不用了。
这玩意儿 ,就是虚拟机 比较 方便,先挂载 复制好文件,在挂到虚拟机里面。
还有就是 系统还原 的时候 方便些。
现在系统维护 都要在 winpe 下了,就算 只是为了 覆盖一个几百 k 的 vhd 也要 pe ,总觉得 ,进入pe 的时间 比 用 pe 干活儿的时间 还长。呵呵。
uefi ,pe ,呵呵。
uefi 下 用 shell 复制覆盖文件 应该 也可以吧。

zqjiang 发表于 2018-3-10 14:53:05

不错 顶起支持。

幻天雨 发表于 2019-11-12 10:15:20

怎么改成直接挂载指定位置vhd

谪仙 发表于 2020-3-3 18:55:26

怎么用啊 不懂
页: [1]
查看完整版本: 新的挂/ 卸载 vhd 脚本