bat 条件分岐して、install/uninstall と一部の文字だけ色を変更

情シス

bat 条件分岐して、install/uninstall と一部の文字だけ色を変更

@echo off

set 赤=[31m
set 緑=[32m
set 白=[37m
set デフォルト=[0m

:INPUT_START
set exe_Path=C:\Users\test\Downloads\picture\
set f32bit=32bit
set f64bit=64bit

echo *****************************************
echo 1. %1%白%ポリシー指定でインストール%デフォルト%
echo 2. %1%緑%Defaultポリシー指定でインストール%デフォルト%
echo 3. %1%赤%アンインストール%デフォルト%
echo *****************************************
set /p ui=1~3を選択してください:

echo +-------------------------------------------------------+
echo  入力した文字は%緑%[%ui%]%デフォルト%でよろしいですか?
echo (Y / N)
echo +-------------------------------------------------------+
SET CONF_SELECT=
SET /P CONF_SELECT=

IF "%CONF_SELECT%"== SET CONF_SELECT=Y
IF /I NOT "%CONF_SELECT%"=="Y"  GOTO :INPUT_START

if "%PROCESSOR_ARCHITECTURE%" EQU "x86"   goto :WIN32
if "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" goto :WIN64
echo %赤%手動でインストールを行ってください。%デフォルト% & goto :FINISH

:WIN32
set f32bitPath=%exe_Path%%f32bit%
pushd %f32bitPath%

rem echo where /r %f32bitPath% /f *.exe
FOR /F %%i in ('where /r %f32bitPath% /f *.exe') DO @SET oput_exe=%%i

if exist %oput_exe% (
 Call :Main %oput_exe%
) else (
 echo "32bitのexeファイルは見つかりませんでした。"
)
rem 切断
popd
goto :FINISH

:WIN64
set f64bitPath=%exe_Path%%f64bit%
pushd %f64bitPath%

rem echo where /r %f64bitPath% /f *.exe
FOR /F %%i in ('where /r %f64bitPath% /f *.exe') DO @SET oput_exe=%%i
if exist %oput_exe% (
 Call :Main %oput_exe%
) else (
 echo "64bitのexeファイルは見つかりませんでした。"
)
rem 切断
popd

goto :FINISH

:FINISH

:Main
echo %oput_exe%
if %ui%==1 (
  rem ポリシー指定でインストール
  %oput_exe% /install /norestart ポリシー指定
) else if %ui%==2 (
  rem Defaultでインストール
  %oput_exe% /install /norestart
) else if %ui%==3 (
  rem アンインストール
  %oput_exe% /uninstall
) else (
  echo %赤%1~3のどれかを選択してください。%デフォルト%
)

pause
exit

設定できる色の一覧

@echo off
echo [30m黒[0m
echo [31m赤[0m
echo [32m緑[0m
echo [33m黄[0m
echo [34m青[0m
echo [35mマゼンダ[0m
echo [36mシアン[0m
echo [37m白[0m
echo [90m明るい黒[0m
echo [91m明るい赤[0m
echo [92m明るい緑[0m
echo [93m明るい黄[0m
echo [94m明るい青[0m
echo [95m明るいマゼンダ[0m
echo [96m明るいシアン[0m
echo [97m明るい白[0m
pause

コメント