把下面目录写通 目前选中123 再按0 就出错直接退出- @echo off
- title 批处理脚本分区
- :: Date: 2024-05-16
-
- :: 以管理员权限运行
- if /i "%systemdrive%"=="C:" reg query HKU\S-1-5-20>nul 2>nul || echo;CreateObject^("Shell.Application"^).ShellExecute "%~f0", "%*", "", "runas", 1 > "%temp%\getadmin.vbs" && cscript //b "%temp%\getadmin.vbs" && exit /b & del "%temp%\getadmin.vbs" /f /q>nul
-
- :main
- SetLocal EnableDelayedExpansion
- :: 跳转到批处理所在目录
- set DIR_CUR=%~dp0
- cd %DIR_CUR%
- :: 设置时间
- set ETR=30
- :: 确保choice在系统中,部分pe精简掉了
- copy %DIR_CUR%_DESKTOP\choice.exe %windir%\sysWOW64\ /y
- copy %DIR_CUR%_DESKTOP\choice.exe %windir%\system32\ /y
- cls
- color 2F
- echo.
- echo =========================选择分区方案=============================
- echo.
- echo [ 1 ] 1分区,全部分配给C盘
- echo [ 2 ] 2分区,C盘150G,其他给D盘 【默认选项】
- echo [ 3 ] 3分区,C盘200G,D盘500G,其他给E盘
- echo [ 0 ] 返回 重新选择
- echo.
- echo =================================================================
- echo 请输入硬盘分区方案 [1230],%ETR%秒后默认分区方案: 2
- choice /c 1230 /n>nul /t %ETR% /d 2
- echo 选择方案: %errorlevel%
- if %errorlevel%==4 (goto main)
- if %errorlevel%==3 (set "CRT_PART_NAME=3分区,C盘200G D盘500G 其他给E盘" & set "CRT_PART=CP3")
- if %errorlevel%==2 (set "CRT_PART_NAME=2分区,C盘100G,其他给D盘 " & set "CRT_PART=CP2")
- if %errorlevel%==1 (set "CRT_PART_NAME=1分区,全部分配给C盘 " & set "CRT_PART=CPAll")
-
- :: 显示磁盘分区情况,测试盘符被修改后此部分会出错,待修复
- cls
- echo.
- echo =====================磁盘分区详情=====================
- echo.
- :: 磁盘总数,从0开始
- set /a "dn=0"
- for /f "delims=" %%i in ('echo list disk^|diskpart^|findstr /i "联机"') do (set /a dn+=1)
- set /a DSK_NO=%dn%-1
-
-
- :: 生成磁盘信息
- if exist dp_t.txt del dp_t.txt
- for /l %%i in (0,1,!DSK_NO!) do (
- (echo sel disk %%i & echo detail disk & echo list part)|diskpart>>dp_t.txt
- )
-
- ::解析内容,生成硬盘分区文件 [序号,磁盘号,分区号,大小,文件系统, 盘符,标签]
- SetLocal EnableDelayedExpansion
- for /f "delims=" %%j in (dp_t.txt) do (
- set "oneline=%%j"
- ::行号
- set /a l+=1
- ::echo 第!l!行: !oneline:~38,4!
- if "!oneline:~0,5!"=="在计算机上" (set /a n=!l!+2 & set /a t=!l!+4 & set /a p=!l!+6)
- if !l!==!n! (set nn=!oneline:~3,1!)
- if !l!==!t! (set tt=!oneline!)
- if !l!==!p! (set pp=!oneline:~7! & (echo [ !nn! ] -磁盘- !tt! - !pp!))
- if "!oneline:~0,7!"==" 分区 " (set /a b+=1 & (echo !oneline:~10,1! !oneline:~15,3! !oneline:~33,7!))
- )
- del dp_t.txt
-
- echo.
- echo ======================================================
- echo 采用分区 %CRT_PART_NAME%
- echo ======================================================
- echo 请输入目标硬盘 [012...],%ETR%秒后默认硬盘: 0
- choice /c 012 /n>nul /t %ETR% /d 0
- if %errorlevel%==3 (set "SEL_DSK=2")
- if %errorlevel%==2 (set "SEL_DSK=1")
- if %errorlevel%==1 (set "SEL_DSK=0")
- echo 选择硬盘: %SEL_DSK%
-
- :: 检查所有硬盘是否已分区,不包括U盘
- (@echo list volume & @echo exit)|diskpart|find /i "磁盘分区">nul
- if %errorlevel%==0 (set DSK_STAT=1) else (set DSK_STAT=0)
-
- :: 获取硬盘参数
- ((@echo select disk %SEL_DSK% & @echo detail disk & @echo exit)|diskpart)>a.txt
- for /f "skip=10 delims=" %%a in (a.txt) do (set DSK_TYP=%%~a & goto Show)
- :Show
- for /f "tokens=3 skip=12 delims= " %%a in (a.txt) do (set DSK_PROT=%%~a & goto sss1)
- :sss1
- del a.txt
- goto conf
-
- :://conf
- cls
- echo.
- echo.
- echo ______________________确认安装方案_____________________
- echo ^| ^|
- echo ^| 目标: %SEL_OS_NAME% ^|
- :: 应答文件: %UNATT%
- echo ^| 目标: %DSK_TYP:~0,15% 磁盘协议:%DSK_PROT% ^|
- echo ^| 分区: %CRT_PART_NAME% ^|
- echo ^| ^|
- if %DSK_STAT%==0 (echo ^| 硬盘未分区 ^|) else (color 4f & echo ^| ★★★ 硬盘已分区-请注意数据安全 ★★★ ^|)
- echo ^| ^|
- echo ^| [ Y ] 确认上述方案 [ X ] 返回 重新选择 ^|
- echo ^|_______________________________________________________^|
- echo.
- echo 请确认方案 [ X / Y ]:
- choice /c xy /n>nul
- if %errorlevel%==2 (goto way)
- if %errorlevel%==1 (goto main)
-
- :way
- :: 跳转到相应方案
- if %CRT_PART%==CPAll goto x%CRT_PART%
- if %CRT_PART%==CP3 goto x%CRT_PART%
- if %CRT_PART%==CP2 goto x%CRT_PART%
-
- :xCPAll
- color 2f
- echo =======================开始硬盘分区=======================
- (
- echo select disk %SEL_DSK%
- echo clean
- echo convert gpt
- :: 创建EFI分区,大小为200M
- echo create partition efi size=200
- echo format quick fs=fat32 label="System"
- echo assign letter=z
- :: 创建MSR分区,大小为128M
- echo create partition msr size=16
- echo format quick fs=fat32
- :: 创建主分区
- echo create partition primary
- echo format fs=ntfs quick
- echo assign letter=c
- echo list volume
- echo exit
- )|diskpart
- goto DepOS
-
- :xCP2
- color 2f
- echo =======================开始硬盘分区=======================
- (
- ... 字数限制 省略部分
- )|diskpart
- goto main
-
- :xCP3
- color 2f
- echo =======================开始硬盘分区=======================
- (
- echo select disk %SEL_DSK%
- echo clean
- echo convert gpt
- :: 创建EFI分区,大小为350M
- echo create partition efi size=350
- echo format quick fs=fat32 label="System"
- echo assign letter=z
- :: 创建MSR分区,大小为128M
- echo create partition msr size=128
- echo format quick fs=fat32
- :: 创建主分区, 大小为150G,如需修改大小,请直接替换下面size=[ 204806 ]
- echo create partition primary size=204806
- echo format fs=ntfs quick
- echo assign letter=c
- :: 创建第二个主分区, 大小为500G
- echo create partition primary size=512002
- echo format fs=ntfs quick
- echo assign letter=d
- :: 创建第三个主分区, 大小为剩余容量
- echo create partition primary
- echo format fs=ntfs quick
- echo assign letter=e
- echo list volume
- echo exit
- )|diskpart
- goto main
复制代码 30红包 |