|
@echo off
setlocal enabledelayedexpansion
::CMD窗口字体绿色
title %~n0
color 0a
set "m_目录=%~1"
if "" EQU "%~1" goto :安装脚本
if "*" EQU "!m_目录:~0,1!" goto :安装脚本
if "?" EQU "!m_目录:~0,1!" goto :安装脚本
if "|" EQU "!m_目录:~0,1!" goto :安装脚本
if "挂载目录" EQU "%~2" goto :挂载目录
if "卸载盘符" EQU "%~2" goto :卸载盘符
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:安装脚本
(
rem 驱动器右键
Reg Add "HKEY_CLASSES_ROOT\Drive\shell\卸载盘符" /ve /t REG_SZ /d "卸载盘符" /f
Reg Add "HKEY_CLASSES_ROOT\Drive\shell\卸载盘符" /v "icon" /t REG_SZ /d "imageres.dll,-78" /f
Reg Add "HKEY_CLASSES_ROOT\Drive\shell\卸载盘符\command" /ve /t REG_SZ /d "\"%~dpnx0\" \"%%1\" \"卸载盘符\"" /f
rem 目录右键
Reg Add "HKEY_CLASSES_ROOT\Directory\shell\挂载为可用盘符" /ve /t REG_SZ /d "挂载为可用盘符" /f
Reg Add "HKEY_CLASSES_ROOT\Directory\shell\挂载为可用盘符" /v "icon" /t REG_SZ /d "imageres.dll,-78" /f
Reg Add "HKEY_CLASSES_ROOT\Directory\shell\挂载为可用盘符\command" /ve /t REG_SZ /d "\"%~dpnx0\" \"%%1\" \"挂载目录\"" /f
) >nul 2>nul
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:挂载目录
set "挂载目录_空闲盘符="
for %%a in ( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ) do if not exist "%%a:" set "挂载目录_空闲盘符=%%a:"
if "" NEQ "!挂载目录_空闲盘符!" subst !挂载目录_空闲盘符! !m_目录!
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:卸载盘符
if "" NEQ "!m_目录:~3,1!" goto :eof
( subst !m_目录:~0,2! /d )>nul 2>nul
if 0 EQU %errorlevel% goto :eof
set "卸载盘符_卸载VHD盘符="
( call :卸载VHD盘符 !m_目录:~0,1! "卸载盘符_卸载VHD盘符" )>nul 2>nul
if "0" EQU "!卸载盘符_卸载VHD盘符!" goto :eof
( call :DiskPart卸载盘符 !m_目录:~0,2! )>nul 2>nul
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DiskPart卸载盘符
rem :DiskPart卸载盘符 "In"
(
echo Sel Vol %~1
echo ReMove
) | DiskPart
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:卸载VHD盘符
if "" NEQ "%~2" set "%~2="
set "卸载VHD盘符_VHD文件="
set "卸载VHD盘符_磁盘号="
set "卸载VHD盘符_磁盘类型="
set "卸载VHD盘符_命令文件=%~dp0%Random%_%Random%"
echo sel vol %~1:>"!卸载VHD盘符_命令文件!"
echo det disk>>"!卸载VHD盘符_命令文件!"
echo det vol>>"!卸载VHD盘符_命令文件!"
call :DiskPart文件命令 "卸载VHD盘符_命令文件" ":卸载VHD盘符_001"
if "" EQU "!卸载VHD盘符_磁盘类型!" goto :eof
echo list vdisk>"!卸载VHD盘符_命令文件!"
call :DiskPart文件命令 "卸载VHD盘符_命令文件" ":卸载VHD盘符_002"
if " " EQU "!卸载VHD盘符_VHD文件:~0,1!" set "卸载VHD盘符_VHD文件=!卸载VHD盘符_VHD文件:~1!"
if not exist "!卸载VHD盘符_VHD文件!" goto :eof
:分离VHD
(
echo select vdisk file="%卸载VHD盘符_VHD文件%"
echo detach vdisk
) | DiskPart >nul 2>nul
set "卸载VHD盘符_磁盘类型=%errorlevel%"
if "" NEQ "%~2" set "%~2=!卸载VHD盘符_磁盘类型!"
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:卸载VHD盘符_001
set "卸载VHD盘符_临时变量=!%~1!"
if "!%~1!" NEQ "!卸载VHD盘符_临时变量:虚拟备份的文件=!" set "卸载VHD盘符_磁盘类型=1"
if "!%~1!" NEQ "!卸载VHD盘符_临时变量:File Backed Virtual=!" set "卸载VHD盘符_磁盘类型=1"
for /f "tokens=1,2,3,4 delims= " %%a in ( "!卸载VHD盘符_临时变量!" ) do if "*" EQU "%%a" set "卸载VHD盘符_磁盘号=%%c"
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:卸载VHD盘符_002
for /f "tokens=1,2,3,4 delims= " %%a in ( "!%~1!" ) do if "!卸载VHD盘符_磁盘号!" EQU "%%d" set "卸载VHD盘符_VHD文件=!%~1:~56!"
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DiskPart文件命令
rem :DiskPart文件命令 "In_Ptr" "In_Code" "In_ptr"
rem :参数列表 文件变量名 回调标签 回调参数 "In_ptr" 字符串行变量名
if "" EQU "%~1" goto :eof
if not exist "!%~1!" goto :eof
set "DiskPart文件命令_回调标签=%~2"
if "" NEQ "%~2" if ":" NEQ "!DiskPart文件命令_回调标签:~0,1!" set "DiskPart文件命令_回调标签=:%~2"
for /f "delims=" %%a in ('DiskPart.exe /s "!%~1!"') do (
if "" NEQ "%%a" if "" NEQ "%~2" (
if "" EQU "%~3" (
set "DiskPart文件命令_临时行=%%a"
call !DiskPart文件命令_回调标签! "DiskPart文件命令_临时行"
)
if "" NEQ "%~3" (
set "%~3=%%a"
call !DiskPart文件命令_回调标签! "%~3"
)
)
if "" NEQ "%%a" if "" EQU "%~2" echo %%a
if exist "!%~1!" ( del /f /q !%~1! ) >nul 2>nul
)
if exist "!%~1!" ( del /f /q !%~1! ) >nul 2>nul
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|