윈 도 우 2개의 bat 파일 합치는 방법?
2022.08.15 11:31
안녕하세요?
bat 파일을 합치는 거 공부 중인데요.
두 개 명령어를 하나의 파일로 합치려면 어떻게 해야 할까요?
하나는 아래 내용이고요. -----------------------------
@echo off
reg query HKU\S-1-5-19 1>nul 2>nul || (
echo ==== Error ====
echo Right click on this file and select 'Run as administrator'
echo Press any key to exit...
pause >nul
exit /b
)
call "%~dp0HWID_Activation.cmd" /u
cd /d "%SystemRoot%\Setup\"
if exist "%SystemRoot%\Setup\Scripts\" @RD /S /Q "%SystemRoot%\Setup\Scripts\"
exit /b
두 번째는 아래 내용입니다. ------------------------------
@echo off
color 1f
cls
echo.
:ReservedStorage
for /f "tokens=3 delims=.]" %%a in ('ver') do set build=%%a
if %build% GEQ 18362 (reg add HKLM\Software\Microsoft\Windows\CurrentVersion\ReserveManager /v ShippedWithReserves /t reg_dword /d 0 /f)
GOTO CheckOS
:CheckOS
IF EXIST "%PROGRAMFILES(X86)%" (GOTO ContextMx64) ELSE (GOTO ContextMx86)
:ContextMx64
cd %WINDIR%\Setup\Scripts
regedit /s win10x64.reg
GOTO VisualCppRedist
:ContextMx86
cd %WINDIR%\Setup\Scripts
regedit /s win10x86.reg
GOTO VisualCppRedist
:VisualCppRedist
cd %WINDIR%\Setup\Scripts
VisualCppRedist.exe /y
GOTO DefenderControl
:DefenderControl
cd %WINDIR%\Setup\Scripts
DefenderControl.exe
GOTO NumlockEnable
:NumlockEnable
cd %WINDIR%\Setup\Scripts
numlock_enable.cmd
GOTO END
:END
exit
두번째 내용이 HWID_Activation.cmd 라고 가정하고 작성한 것입니다.
첫번째 배치파일 이름과 두번째 배치파일 이름이 뭔지 모르는 상태이기도 하고
저도 자세히는 모르겠지만 HKU\S-1-5-19 1 레지값이 있으면 넘어가고 없으면
echo 문 출력과 함께 스크립트가 종료되며 값이 존재하면 원래는 HWID_Activation.cmd 를
불러와야 하지만 스크립트 두개를 합칠려면 call 문쪽에 HWID_Activation.cmd 의 내용을
보강해주면 될거 같습니다. 배치파일에 대해서 자세히는 모르지만 이렇게 될거 같습니다.
@echo off
reg query HKU\S-1-5-19 1>nul 2>nul || (
echo ==== Error ====
echo Right click on this file and select 'Run as administrator'
echo Press any key to exit...
pause >nul
exit /b
)
if not exist "%WINDIR%\Setup\Scripts" md "%WINDIR%\Setup\Scripts"
cls
echo.
:ReservedStorage
for /f "tokens=3 delims=.]" %%a in ('ver') do set build=%%a
if %build% GEQ 18362 (reg add HKLM\Software\Microsoft\Windows\CurrentVersion\ReserveManager /v ShippedWithReserves /t reg_dword /d 0 /f)
GOTO CheckOS
:CheckOS
IF EXIST "%PROGRAMFILES(X86)%" (GOTO ContextMx64) ELSE (GOTO ContextMx86)
:ContextMx64
cd %WINDIR%\Setup\Scripts
regedit /s win10x64.reg
GOTO VisualCppRedist
:ContextMx86
cd %WINDIR%\Setup\Scripts
regedit /s win10x86.reg
GOTO VisualCppRedist
:VisualCppRedist
cd %WINDIR%\Setup\Scripts
VisualCppRedist.exe /y
GOTO DefenderControl
:DefenderControl
cd %WINDIR%\Setup\Scripts
DefenderControl.exe
GOTO NumlockEnable
:NumlockEnable
cd %WINDIR%\Setup\Scripts
numlock_enable.cmd
GOTO END
:End
cd /d "%SystemRoot%\Setup\"
if exist "%SystemRoot%\Setup\Scripts\" @RD /S /Q "%SystemRoot%\Setup\Scripts\"
exit /b