@echo off & color 0a & setlocal ENABLEDELAYEDEXPANSION
set volumeListFile=%Random%_%Random%_卷信息.txt
set 分区信息文件=%Random%_%Random%_分区信息.txt
rem 显示所有卷信息
echo list volume | diskpart >%volumeListFile%
for /f "tokens=2,3" %%a in (%volumeListFile%) do (
for %%I in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) do (
if "%%I"=="%%a" if not exist %%b: (
(
echo select volume %%a
echo det part
)>"!分区信息文件!"
set "m_分区类型="
set /a m_分区类型_行计数=0
call :DiskPart文件命令 "分区信息文件" "解释分区类型"
if /i "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" EQU "!m_分区类型!" call :挂在卷号 "%%a"
)
)
)
( del /f /q "%volumeListFile%" )>nul 2>nul
( del /f /q "%分区信息文件%" )>nul 2>nul
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:解释分区类型
if 2 EQU !m_分区类型_行计数! goto :eof
for /f "tokens=2 delims=:" %%a in ("!%~1!") do if "" NEQ "%%a" (
set "m_分区类型=%%a"
set "m_分区类型=!m_分区类型: =!"
set /a m_分区类型_行计数=!m_分区类型_行计数! + 1
)
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:获取卷号的分区类型
(
echo select volume %~1
echo det part
)|diskpart
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:挂在卷号
(
echo select volume %~1
echo assign
)|diskpart
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
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::