我有这个脚本,但由于某种原因,我一直在遇到问题。其中一个问题是语法不正确。我重新运行它并且问题不同但是它说“N此时出乎意料”然后它有“如果EQU N(”它在哪里断了。
这是脚本:
SET LOG_FILE="D:\SmCpm\ElektronTMS\%PCN_NUM%_RollbackLog.txt"
SET UNINSTALL5012=N
SET UNINSTALL5013=N
SET UNINSTALL5014=N
SET UNINSTALL5015=N
SET UNINSTALL5017=N
SET UNINSTALL5018=N
SET UNINSTALLV131=N
SET UNINSTALLV140=N
SET UNINSTALLV141=N
SET INST=""
SET ETMSFILENAME="ElektronTMS.msi"
:: *******************************************
:: Stop the SMF Service.
ECHO Rolling back installation of %PCN_NUM%
net stop smf
ping 127.0.0.1 -n 5 > nul
:: *******************************************
:: determine which PCNs need to be uninstalled.
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKLM\SOFTWARE\Wow6432Node\Reuters\TMS" /v PCN5021') DO (
set INST=%%B
)
if not x%INST:5012=%==x%INST% (
SET UNINSTALL5012=Y
)
if not x%INST:5013=%==x%INST% (
SET UNINSTALL5013=Y
)
if not x%INST:5014=%==x%INST% (
SET UNINSTALL5014=Y
)
if not x%INST:5015=%==x%INST% (
SET UNINSTALL5015=Y
)
if not x%INST:5017=%==x%INST% (
SET UNINSTALL5017=Y
)
if not x%INST:5018=%==x%INST% (
SET UNINSTALL5018=Y
)
if not x%INST:V131=%==x%INST% (
SET UNINSTALLV131=Y
)
if not x%INST:V140=%==x%INST% (
SET UNINSTALLV140=Y
)
if not x%INST:V141=%==x%INST% (
SET UNINSTALLV141=Y
)
:: ***********************
:: Uninstall the packages.
ECHO Rolling back patch
IF %UNINSTALLV131% EQU Y (
FOR /F "tokens=3*" %%C IN ('c:\windows\system32\reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\48AB8A7CAE88C33488B5F1498871520C\InstallProperties /v LocalPackage') DO (
SET LOCALPACKAGE=%%C
)
FOR /F "tokens=3*" %%S IN ('c:\windows\system32\reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\48AB8A7CAE88C33488B5F1498871520C\InstallProperties /v InstallSource') DO (
SET SOURCEINSTALL=%%S
)
if not exist %SOURCEINSTALL% (
md "%SOURCEINSTALL%"
SET SOURCEEXISTS=N
)
if exist %SOURCEINSTALL% (
SET SOURCEEXISTS=Y
)
SET COPYTODIR=%SOURCEINSTALL%%ETMSFILENAME%
copy /y %LOCALPACKAGE% %COPYTODIR%
msiexec -package {C7A8BA84-88EA-433C-885B-1F94881725C0} -uninstall {F732939E-ED57-43FC-B298-83F933E1F950} -quiet -norestart -lv+ %LOG_FILE%
ping 127.0.0.1 -n 5 > nul
if %SOURCEEXISTS% EQU N (
rd /s /q "%SOURCEINSTALL%"
) else (
del /F %COPYTODIR%
)
)
IF %UNINSTALLV140% EQU Y (
FOR /F "tokens=3*" %%C IN ('c:\windows\system32\reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\98AF25D0FB734FC4BA465843970476B6\InstallProperties /v LocalPackage') DO (
SET LOCALPACKAGE=%%C
)
FOR /F "tokens=3*" %%S IN ('c:\windows\system32\reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\98AF25D0FB734FC4BA465843970476B6\InstallProperties /v InstallSource') DO (
SET SOURCEINSTALL=%%S
)
if not exist %SOURCEINSTALL% (
md "%SOURCEINSTALL%"
SET SOURCEEXISTS=N
)
if exist %SOURCEINSTALL% (
SET SOURCEEXISTS=Y
)
SET COPYTODIR=%SOURCEINSTALL%%ETMSFILENAME%
copy /y %LOCALPACKAGE% %COPYTODIR%
msiexec -package {0D52FA89-37BF-4CF4-AB64-85347940676B} -uninstall {C845F8AE-6935-42D9-AE8C-2564E2A82C71} -quiet -norestart -lv+ %LOG_FILE%
ping 127.0.0.1 -n 5 > nul
if %SOURCEEXISTS% EQU N (
rd /s /q "%SOURCEINSTALL%"
) else (
del /F %COPYTODIR%
)
)
IF %UNINSTALLV141% EQU Y (
FOR /F "tokens=3*" %%C IN ('c:\windows\system32\reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\DFFF30F7568D1D144B5B7B785F32638D\InstallProperties /v LocalPackage') DO (
SET LOCALPACKAGE=%%C
)
echo %LOCALPACKAGE%
FOR /F "tokens=3*" %%S IN ('c:\windows\system32\reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\DFFF30F7568D1D144B5B7B785F32638D\InstallProperties /v InstallSource') DO (
SET SOURCEINSTALL=%%S
)
if not exist %SOURCEINSTALL% (
md "%SOURCEINSTALL%"
SET SOURCEEXISTS=N
)
if exist %SOURCEINSTALL% (
SET SOURCEEXISTS=Y
)
SET COPYTODIR=%SOURCEINSTALL%%ETMSFILENAME%
copy /y %LOCALPACKAGE% %COPYTODIR%
msiexec -package {7F03FFFD-D865-41D1-B4B5-B787F52336D8} -uninstall {464FBA62-6FA9-4744-BDA7-68284B61B6DB} -quiet -norestart -lv+ %LOG_FILE%
ping 127.0.0.1 -n 5 > nul
if %SOURCEEXISTS% EQU Y (
rd /s /q "%SOURCEINSTALL%"
) else (
del /F %COPYTODIR%
)
)
我查询了所有注册表值详细信息,我可以看到有源安装值和本地包值。起初它抱怨语法错误与我的“如果不存在”但现在我得到另一个错误,我不知道我的批次有什么问题!
有人可以帮忙吗?
由于
答案 0 :(得分:0)
通过使用子程序可以简化所提供的批次代码,这也避免了使用延迟扩展的需要。
@ECHO OFF
SETLOCAL
SET "LOG_FILE=D:\SmCpm\ElektronTMS\%PCN_NUM%_RollbackLog.txt"
SET "UNINSTALL5012=N"
SET "UNINSTALL5013=N"
SET "UNINSTALL5014=N"
SET "UNINSTALL5015=N"
SET "UNINSTALL5017=N"
SET "UNINSTALL5018=N"
SET "UNINSTALLV131=N"
SET "UNINSTALLV140=N"
SET "UNINSTALLV141=N"
SET "INST=x"
SET "ETMSFILENAME=ElektronTMS.msi"
:: *******************************************
:: Stop the SMF Service.
ECHO Rolling back installation of %PCN_NUM%
%SystemRoot%\System32\net.exe stop smf
REM %SystemRoot%\System32\ping.exe 127.0.0.1 -n 5 > nul
:: *******************************************
:: determine which PCNs need to be uninstalled.
FOR /F "tokens=2*" %%A IN ('%SystemRoot%\System32\reg.exe QUERY "HKLM\SOFTWARE\Wow6432Node\Reuters\TMS" /v PCN5021 2^>nul') DO SET "INST=%%B"
IF NOT "%INST:5012=%" == "%INST%" SET "UNINSTALL5012=Y"
IF NOT "%INST:5013=%" == "%INST%" SET "UNINSTALL5013=Y"
IF NOT "%INST:5014=%" == "%INST%" SET "UNINSTALL5014=Y"
IF NOT "%INST:5015=%" == "%INST%" SET "UNINSTALL5015=Y"
IF NOT "%INST:5017=%" == "%INST%" SET "UNINSTALL5017=Y"
IF NOT "%INST:5018=%" == "%INST%" SET "UNINSTALL5018=Y"
IF NOT "%INST:5019=%" == "%INST%" SET "UNINSTALL5019=Y"
IF NOT "%INST:V131=%" == "%INST%" SET "UNINSTALLV131=Y"
IF NOT "%INST:V140=%" == "%INST%" SET "UNINSTALLV140=Y"
IF NOT "%INST:V141=%" == "%INST%" SET "UNINSTALLV141=Y"
:: ***********************
:: Uninstall the packages.
ECHO Rolling back patch
IF %UNINSTALLV131% == Y CALL :UnInstallPatch "48AB8A7CAE88C33488B5F1498871520C" "C7A8BA84-88EA-433C-885B-1F94881725C0" "F732939E-ED57-43FC-B298-83F933E1F950"
IF %UNINSTALLV140% == Y CALL :UnInstallPatch "98AF25D0FB734FC4BA465843970476B6" "0D52FA89-37BF-4CF4-AB64-85347940676B" "C845F8AE-6935-42D9-AE8C-2564E2A82C71"
IF %UNINSTALLV141% == Y CALL :UnInstallPatch "DFFF30F7568D1D144B5B7B785F32638D" "7F03FFFD-D865-41D1-B4B5-B787F52336D8" "464FBA62-6FA9-4744-BDA7-68284B61B6DB"
ENDLOCAL
GOTO :EOF
:: *********************************
:: Subfunction to uninstall a patch.
:UnInstallPatch
set "ProductID=%~1"
set "PackageID=%~2"
set "UninstallID=%~3"
FOR /F "tokens=3*" %%C IN ('%SystemRoot%\System32\reg.exe query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\%ProductID%\InstallProperties /v LocalPackage') DO SET "LOCALPACKAGE=%%~C"
FOR /F "tokens=3*" %%S IN ('%SystemRoot%\System32\reg.exe query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\%ProductID%\InstallProperties /v InstallSource') DO SET "SOURCEINSTALL=%%~S"
MD "%SOURCEINSTALL%" 2>nul
IF EXIST "%SOURCEINSTALL%" ( SET "SOURCEEXISTS=Y" ) ELSE ( SET "SOURCEEXISTS=N" )
SET "COPYTODIR=%SOURCEINSTALL%%ETMSFILENAME%"
COPY /Y "%LOCALPACKAGE%" "%COPYTODIR%"
START "" /WAIT %SystemRoot%\System32\msiexec.exe -package {%PackageID%} -uninstall {%UninstallID%} -quiet -norestart -lv+ "%LOG_FILE%"
REM %SystemRoot%\System32\ping.exe 127.0.0.1 -n 5 > nul
IF %SOURCEEXISTS% == Y (
RD /S /Q "%SOURCEINSTALL%"
) ELSE (
DEL /F "%COPYTODIR%"
)
GOTO :EOF
如果使用
,请查看set environment variables with spaces上的答案set "variable=value"
而不是
set variable=value
或
set variable="value"
嗯,包含引号的变量LOG_FILE
已设置并使用正确,但不包含变量ETMSFILENAME
,其中包含引号并与变量SOURCEINSTALL
的值连接。
我认为在继续处理之前,没有任何 ping 执行等待5秒是非常必要的,这是将它们注释掉的原因。但这并没有得到我的证实。