我做了这个批处理文件,目的是为了在我经常要重新格式化的一些Windows机器之间自动安装程序,但当我运行它时,它只是关闭CMD,没有任何错误,我试过许多不同的东西,如BatCodeCheck,但我无法找到它崩溃的原因。我是 不 经验丰富的批处理文件,所以我现在真的很辛苦。
我的批处理文件背后的想法是,只需要运行一个文件,就可以安装一般人所需要的所有基本软件。
下面是我的 AIO install everything.bat 文件。
@echo off
SETLOCAL EnableExtensions
::##################################################################
:: Elevate this script #
::##################################################################
(
:: Check Admin rights and create VBS Script to elevate
>nul fsutil dirty query %SYSTEMDRIVE% 2>&1 || (
:: Very little red console
mode con cols=80 lines=3
color cf
:: Message
title Please wait...
echo[
echo Requesting elevated shell...
:: Create VBS script
echo Set UAC = CreateObject^("Shell.Application"^)>"%TEMP%\elevate.vbs"
echo UAC.ShellExecute "%~f0", "%TEMP%\elevate.vbs", "", "runas", 1 >>"%TEMP%\elevate.vbs"
if exist "%TEMP%\elevate.vbs" start /b /wait >nul cscript /nologo "%TEMP%\elevate.vbs" 2>&1
:: Delete elevation script if exist
if exist "%TEMP%\elevate.vbs" >nul del /f "%TEMP%\elevate.vbs" 2>&1
exit /b
)
)
pushd "%~dp0"
::##################################################################
:: Finished elevation #
::##################################################################
set "javafolder=jre1.8.0_251"
set "java32installer=jre-8u251-windows-i586"
set "java64installer=jre-8u251-windows-x64"
set "winrar32installer=winrar-x32-590br"
set "winrar64installer=winrar-x64-590br"
set "libreoffice32installer=LibreOffice_6.4.3_Win_x86"
set "libreoffice64installer=LibreOffice_6.4.3_Win_x64"
set "chromesetup=ChromeSetup"
set "firefoxsetup=Firefox Installer"
set "klite=K-Lite_Codec_Pack_1544_Mega"
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
set "PF86=%ProgramFiles(x86)%"
set "is64=1"
) ELSE (
set "PF86=%ProgramFiles%"
set "is64=0"
)
IF "%is64%"=="1" (
set "nircmd=%CD%\nircmd64.exe"
) ELSE (
set "nircmd=%CD%\nircmd32.exe"
)
REM --> Verifying dependances
IF NOT EXIST "%nircmd%" (
echo Error
goto END
)
REM --> Getting Windows version and saving in "windowsversion" variable
for /f "tokens=4-7 delims=[.] " %%i in ('ver') do (if %%i==Version (set windowsversion=%%j.%%k) else (set windowsversion=%%i.%%j))
REM --> Installing programs
IF NOT EXIST "%ProgramFiles%\WinRAR" (
IF "%is64%"=="1" (
start /d "%CD%" %winrar64installer%.exe -s
%nircmd% cmdwait 200 waitprocess %winrar64installer%.exe
) ELSE (
start /d "%CD%" %winrar32installer%.exe -s
%nircmd% cmdwait 200 waitprocess %winrar32installer%.exe
)
IF NOT EXIST "%ProgramFiles%\WinRAR\WinRAR_goods.exe" start /d "%CD%" /wait cmd /c "winrar tweaks.bat"
echo WinRAR installed
)
IF NOT EXIST "%PF86%\Google\Chrome" (
start /d "%CD%" %chromesetup%.exe -silent -install
%nircmd% cmdwait 200 waitprocess %chromesetup%.exe
echo Google Chrome installed
)
IF NOT EXIST "%PF86%\K-Lite Codec Pack" (
start /d "%CD%" %klite%.exe -verysilent -norestart
%nircmd% cmdwait 200 waitprocess %klite%.exe
echo K-Lite Codec Pack installed
)
IF NOT EXIST "%ProgramFiles%\Mozilla Firefox" (
start /d "%CD%" "%firefoxsetup%.exe" -ms
%nircmd% cmdwait 200 waitprocess "%firefoxsetup%.exe"
echo Firefox installed
)
IF NOT EXIST "%PF86%\Java\%javafolder%" (
start /d "%CD%" %java32installer%.exe
%nircmd% cmdwait 200 waitprocess %java32installer%.exe
echo Java 32 bits installed
)
IF "%is64%"=="1" (
IF NOT EXIST "%ProgramFiles%\Java\%javafolder%" (
start /d "%CD%" %java64installer%.exe
%nircmd% cmdwait 200 waitprocess %java64installer%.exe
echo Java 64 bits installed
)
)
IF "%windowsversion%" NEQ "10.0" (
IF NOT EXIST "%ProgramFiles%\LibreOffice" (
IF "%is64%"=="1" (
%SystemRoot%\system32\msiexec.exe /i "%CD%\%libreoffice64installer%.msi" /QN
%nircmd% cmdwait 200 waitprocess %libreoffice64installer%.msi
) ELSE (
%SystemRoot%\system32\msiexec.exe /i "%CD%\%libreoffice32installer%.msi" /QN
%nircmd% cmdwait 200 waitprocess %libreoffice32installer%.msi
)
echo LibreOffice installed
)
)
echo EVERYTHING WAS SUCCESSFULLY INSTALLED!
:END
pause
endlocal
exit
如果有人能给我指出错误所在,我将非常感激,非常感谢。
以管理员身份运行改变当前目录。看看下面的链接,以证明自己。