batch-file - 我用于安装程序的批处理文件崩溃了
问题描述
我制作了这个批处理文件,目的是在一些我经常需要重新格式化的 Windows 机器之间自动安装程序,但是当我运行它时,它只是关闭了 CMD 而没有任何错误,我尝试了很多不同的东西,比如 BatCodeCheck 但我不能找出它崩溃的原因。我对批处理文件没有经验,所以我现在非常努力。
我的批处理文件背后的想法是只需要运行一个文件并安装普通 Joe 所需的所有基本软件。
这是我的AIO 安装 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
如果有人能指出错误在哪里,我将不胜感激,非常感谢。
解决方案
以管理员身份运行更改当前目录。查看下面的链接以向自己证明这一点。
推荐阅读
- google-analytics - 为什么 Analytics Data API V1 Beta 不符合 REST 规范?
- javascript - 我无法从我的 REACT 应用程序中读取 azure 应用程序服务配置中的环境变量
- javascript - Intersection Observer API 滚动感知导航
- python - discord.py bot 连接到语音通道但 OpusNotLoaded,以及 discord.opus.load_opus() 的问题
- netlogo - 如何使本地列表在程序中起作用?
- python - Discord PY TypeError:只能将str(不是“int”)连接到str
- raspberry-pi - Raspberry Pi 串口未找到,.NET
- countdown - 60 秒倒计时计时器,根据系统时间和日期显示,计时器结束时将不可见
- ios - 无法在 Safari 上检查 webview
- python - 如何使用管道将一个进程传递给另一个进程(读取文件内容-获取内容-创建新文件)?