复制代码
- @echo off & cd /d "%~dp0" & setlocal enabledelayedexpansion
- color 07
- mode con: cols=80 lines=40
- chcp 936 >nul
- set file=%~fx1
- set filegs=%file:~-3%
- set wfiles=%file%
- if %filegs% NEQ wim (echo 安装文件仅支持Wim格式镜像,执行即将退出。 & timeout -t 5 & exit)
- @for /f "skip=6 tokens=*" %%a in ('echo list disk ^|diskpart') do echo %%a
- echo.
- echo.
- echo =======================================================
- echo.请根据磁盘容量,选择要操作的磁盘(例如0或1),回车继续。
- echo =======================================================
- echo.
- echo.
- set /p user_input=请输入数字:
- echo.
- echo.
- echo =======================================================
- if %user_input% equ 0 echo 您选择了磁盘0为目标系统盘,请输入系统分区大小,回车继续。
- if %user_input% equ 1 echo 您选择了磁盘1为目标系统盘,请输入系统分区大小,回车继续。
- if %user_input% equ 2 echo 您选择了磁盘2为目标系统盘,请输入系统分区大小,回车继续。
- echo =======================================================
- echo.
- echo.
- set /p Sys_Dev=请输入系统分区大小(例如:100GB,只需要输入"100"即可):
- for /f %%d in ('powershell -command " %Sys_Dev% * 1024 + 1 "') do set Sys_DevMb=%%d
- (
- echo select disk %user_input%
- echo clean
- echo convert mbr
- echo create partition primary size 350
- echo create partition primary size %Sys_DevMb%
- echo create partition primary
- echo select partition 2
- echo remove noerr
- echo format fs=ntfs quick
- echo assign
- echo select partition 3
- echo format fs=ntfs quick
- echo assign
- echo select partition 1
- echo remove noerr
- echo format fs=fat32 quick
- echo active
- echo assign
- echo exit
- )>diskset
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- diskpart.exe /s "diskset"
- cls
- for /f "tokens=3,10" %%a in ('echo list volume ^| diskpart ^|find/i "FAT32" ^| find /i "350 MB"') do set ESP=%%a
- echo.
- echo.
- if %ESP% equ F (set Sysd=D)
- if %ESP% equ G (set Sysd=E)
- if %ESP% equ H (set Sysd=F)
- if %ESP% equ I (set Sysd=G)
- if %ESP% equ J (set Sysd=H)
- if %ESP% equ K (set Sysd=I)
- if %ESP% equ L (set Sysd=J)
- if %ESP% equ M (set Sysd=K)
- if %ESP% equ N (set Sysd=L)
- if %ESP% equ O (set Sysd=M)
- if %ESP% equ P (set Sysd=N)
- if %ESP% equ Q (set Sysd=O)
- if %ESP% equ R (set Sysd=P)
- if %ESP% equ S (set Sysd=Q)
- if %ESP% equ T (set Sysd=R)
- for /f "tokens=3" %%a in ('echo list volume ^| diskpart ^|find/i "NTFS" ^| find /i "!Sys_Dev!" ^| find /i "%Sysd%"') do (if %%a equ %Sysd% (set "SysDv=%%a" & call :dvok))
- echo =======================================================
- echo 系统分区盘符获取异常,请手动输入盘符后回车继续。
- echo =======================================================
- echo.
- echo.
- set /p SysDv=请根据容量输入系统安装盘符(例如“E”不带冒号):
- :dvok
- echo =======================================================
- echo 系统引导分区:%ESP% 350MB
- echo 系统数据分区:%SysDv% !Sys_Dev!GB
- echo =======================================================
- echo.
- (
- echo select volume %ESP%
- echo remove
- echo exit
- )>diskmov
- echo 当前要安装的系统包信息如下:
- Dism.exe /Get-Wiminfo /WimFile:"%wfiles%"
- echo.
- echo.
- set /p Wim_input=请输入索引数字,回车确认系统安装版本:
- echo.
- echo.
- if %Wim_input% equ 1 echo 您当前选择了版本1为目标系统,回车继续。
- if %Wim_input% equ 2 echo 您当前选择了版本2为目标系统,回车继续。
- if %Wim_input% equ 3 echo 您当前选择了版本3为目标系统,回车继续。
- if %Wim_input% equ 4 echo 您当前选择了版本4为目标系统,回车继续。
- if %Wim_input% equ 5 echo 您当前选择了版本5为目标系统,回车继续。
- if %Wim_input% equ 6 echo 您当前选择了版本6为目标系统,回车继续。
- if %Wim_input% equ 7 echo 您当前选择了版本7为目标系统,回车继续。
- :installs
- Dism.exe /Apply-Image /ImageFile:"!wfiles!" /ApplyDir:!SysDv!: /Index:!Wim_input!
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::添加引导::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- bcdboot.exe %SysDv%:\windows /s %ESP%: /f all /l zh-CN /v
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::设置引导盘符::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- bcdedit.exe /store %ESP%:\EFI\Microsoft\Boot\BCD /set {bootmgr} device partition=%ESP%:
- bcdedit.exe /store %ESP%:\EFI\Microsoft\Boot\BCD /set {default} osdevice partition=%SysDv%:
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::卸载引导盘符::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- diskpart.exe /s "diskmov"
- ::卸载多余ESP挂载分区
- for %%a in (e f g h i j k l m n o p q r s t u v w h y z) do (
- if exist "%%a:\EFI\Boot" (if exist "%%a:\EFI\Microsoft\Boot" (if exist "%%a:\EFI\Microsoft\Recovery" (set qxesp=%%a)))
- )
- mountvol %qxesp%: /D
- cls
- echo.
- echo.
- echo 系统安装完毕,请从托盘处安全移除磁盘!
- if exist diskset (del diskset)
- if exist diskmov (del diskmov)
- pause>nul
- exit
复制代码
- @echo off
- :menu
- echo -----------菜单选项-----------
- echo 1.磁盘分区
- echo 2.安装系统
- set /p choice=请输入选项:
- if "%choice%"=="1" goto partition
- if "%choice%"=="2" goto install
- goto menu
- :partition
- echo 打开 diskgen...
- start diskgen.exe
- echo 等待 10 秒
- ping 127.0.0.1 -n 10 > nul
- echo diskgen 已关闭
- goto install
- :install
- setlocal enabledelayedexpansion
- set /a count=0
- for %%d in (C: D: E: F:) do (
- for /r %%f in (%%d\*.iso %%d\*.win %%d\*.esd %%d\*.gho) do (
- if not "%%~xf"=="ghoj" (
- set /a count+=1
- set "path!count!=%%~dpf"
- echo !count!. %%~dpf
- echo %%~dpf>>1.txt
- )
- )
- )
- set /p x=请输入要安装的系统编号:
- set y=
- for /f "tokens=1,2 delims=." %%a in ("!path%x%!") do (
- set "drive=%%a"
- set "path=%%b"
- )
- if "%%~xf"==".gho" (
- for %%d in (%drive%) do (
- if exist %%d\%path% (
- set /a count+=1
- set "path!count!=%%~dpd"
- echo 请为还原目录输入编号y:
- set /p y=
- echo ghost32 -clone,mode=load,src=!path%x%!,dst=!path%y%! -sure -rb
- pause
- ) else (
- echo 目录不存在: %%d\%path%
- pause
- )
- )
- ) else (
- if "%%~xf"==".iso" (
- set install_cmd=dism /Apply-Image /ImageFile:!path%x%! /Index:1 /ApplyDir:!path%y%!
- ) else (
- set install_cmd=dism /Online /Add-Package /PackagePath:!path%x%!
- )
- for %%d in (%drive%) do (
- if exist %%d\%path% (
- set /a count+=1
- set "path!count!=%%~dpd"
- echo 请为安装目录输入编号y:
- set /p y=
- echo %install_cmd%
- pause
- ) else (
- echo 目录不存在: %%d\%path%
- pause
- )
- )
- )
- exit
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |