I'have用DOS批處理,我要用來安裝java一個問題:DOS子和變量
REM SCRIPT FOR UPDATING JAVA... THERE'S NOTHING TO EDIT, ONLY COPY THE JRE EXE INSTALLATION FILES INTO THE SAME DIR OF THE SCRIPT
@echo off
set ProductName=jre
set OS=windows
set FileType=exe
set LogLocation=.\log
set Parameters=/s INSTALL_SILENT=1 WEB_JAVA_SECURITY_LEVEL=H AUTO_UPDATE=0 WEB_ANALYTICS=0 REBOOT=0 /L %LogLocation%\%COMPUTERNAME%_Install.log
set Uninstall=%SystemRoot%\system32\msiexec.exe /qn /norestart /l* %LogLocation%\%COMPUTERNAME%_Uninstall.log /x
set Version=
set Maj=
set Min=
Pushd "%~dp0"
mkdir %LogLocation%
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
IF NOT "%ProgramFiles(x86)%"=="" (
echo This is a 64bit system. Installing both 32bit and 64bit version....
call :SETVAR64
call :INSTALL
call :SETVAR32
set Wow=WOW6432NODE\
call :INSTALL
call :UNSETVAR
goto End
) else (
echo This is a 32bit system. Installing only 32bit version....
call :SETVAR32
call :INSTALL
call :UNSETVAR
goto End
)
:SETVAR64
set Arch=64
call :SETVERSION
set ProductRegKey={26A24AE4-039D-4CA4-87B4-2F8%Arch%1%Maj%0%Min%F0}
set ExeArch=x64
set Wow=
GOTO:EOF
:SETVAR32
set Arch=32
call :SETVERSION
set ProductRegKey={26A24AE4-039D-4CA4-87B4-2F8%Arch%1%Maj%0%Min%F0}
set ExeArch=i586
set Wow=
GOTO:EOF
:SETVERSION
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`dir /B %ProductName%*`) DO (
SET var!count!=%%F
SET /a count=!count!+1
)
set Version=!var1:~4,-18!
set Maj=%var1:~4,-21%
set Min=%var1:~6,-17%
ENDLOCAL & set Version=%Version% & set Maj=%Maj% & set Min=%Min%
GOTO:EOF
:INSTALL
echo "--------------------------------------------------------"
reg query HKLM\SOFTWARE\%Wow%Microsoft\Windows\CurrentVersion\Uninstall\%ProductRegKey% /z
if %errorlevel%==0 (
echo %ProductName% %Version% %Arch%bit is already installed or another error occurred...
) else (
echo %ProductName% %Version% %Arch%bit is not installed.
call :KILLPROC
call :UNINSTALLOLD
call :DEPLOY
call :CONFIGFILES
call :REGKEYS
)
GOTO:EOF
:KILLPROC
echo "--------------------------------------------------------"
echo Killing browsers and unwanted running processes:
for %%P in (iexplore.exe firefox.exe chrome.exe jqs.exe jusched.exe jucheck.exe) do (
cmd /c "taskkill /IM %%P /F"
)
GOTO:EOF
:UNINSTALLOLD
echo "--------------------------------------------------------"
echo Uninstall the installed %ProductName% versions for %Arch%bit arch...
SETLOCAL enabledelayedexpansion
for /L %%A in (4,1,9) do (
set "Maj=%%A"
for /L %%B in (0,1,100) do (
set "Min=%%B"
set ProductRegKey={26A24AE4-039D-4CA4-87B4-2F8%Arch%1%Maj%0%Min%F0}
reg query HKLM\SOFTWARE\%Wow%Microsoft\Windows\CurrentVersion\Uninstall\!ProductRegKey!
if !errorlevel!==0 (
echo Found the installation of !ProductName! with key !ProductRegKey!.... Uninstalling...
cmd /c "%Uninstall% !ProductRegKey!"
) else (
echo The installation of %ProductName% with key !ProductRegKey! not found... Skipping
)
)
)
Endlocal
GOTO:EOF
:DEPLOY
echo "--------------------------------------------------------"
echo Deploying %ProductName% %Version% %Arch%bit
.\%ProductName%-%Version%-%OS%-%ExeArch%.%FileType% %Parameters%
GOTO:EOF
:CONFIGFILES
echo "--------------------------------------------------------"
echo Copying configuration files
robocopy ..\CONFIG %Windir%\ *.* /E /IS
GOTO:EOF
:REGKEYS
echo "--------------------------------------------------------"
REG DELETE "HKLM\SOFTWARE\%Wow%Microsoft\Windows\CurrentVersion\Run" /v SunJavaUpdateSched /f
for %%R in (EnableJavaUpdate NotifyDownload EnableAutoUpdate Frequency NotifyInstall UpdateSchedule EnableJavaUpdate NotifyDownload EnableAutoUpdate Frequency SunJavaUpdateSched) do (
cmd /c "REG ADD "HKLM\SOFTWARE\%Wow%JavaSoft\Java Update\Policy" /v %%R /t REG_DWORD /d 0 /f"
)
GOTO:EOF
:UNSETVAR
set ProductName=
set OS=
set FileType=
set LogLocation=
set Parameters=
set Uninstall=
set Version=
set Maj=
set Min=
GOTO:EOF
:End
echo "--------------------------------------------------------"
echo Installation completed
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
GOTO:EOF
Endlocal
的問題是與增值經銷商:
版本,少校,閔
我通過在安裝程序(i586和x64)所在的目錄中使用dir來獲得:SETVERSION函數。
這些都是空的,我不明白爲什麼,也許是因爲我在批處理結束時未設置它們?如果是,爲什麼?
非常感謝!
Gret @Magoo !!!它的工作原理!!!謝謝你的澄清! – S4rg0n