MRocha
MRocha

Reputation: 11

Software removal / new installation using batch file

I need to remove a program from all my branch computers (32bit & 64bit) and reinstall and update version of the software with registry fix for all machine. doesnt seem difficult but i trying to use a batch file (probably easiest) to do this, and i'm stuck on the checking the OS version part.

could i get some assistance? here is the batch; Few pointers;

The code:

echo off

:CheckOS (this part not done)
IF EXIST "%PROGRAMFILES(X86)%" (GOTO disconnect) ELSE (GOTO Fincentric check)

if exist r:\ goto disconnect

:disconnect
net use r: /d

net use r: \\a0363sfp06\rfsnt
pause

:check
if exist c:\%programfiles%\Fincentric\CAMNet            goto remove01 else
if exist c:\%programfiles%\Fincentric\BridgeNET v2.3.0  goto remove02 else
if exist c:\%programfiles%\Fincentric\CAMPlugins        goto remove03 else
if exist c:\%programfiles%\Fincentric\Canvas            goto remove04 else
if exist c:\%programfiles%\Fincentric\Platform          goto remove05 else
if exist c:\%programfiles%\Fincentric\SupportLibraries  goto remove06 else


:remove01
start /wait msiexec /quiet /qr /uninstall R:\WBDK\WBCAMNet_CGI.msi
if %ERRORLEVEL% EQU 1721 (
   echo Failure Reason Given is %errorlevel%
   exit /b %errorlevel%
)
:remove02
start /wait msiexec /quiet /qr /uninstall R:\WBDK\WBBridgeNET.msi
if %ERRORLEVEL% EQU 1721 (
   echo Failure Reason Given is %errorlevel%
   exit /b %errorlevel%
)
:remove03
start /wait msiexec /quiet /qr /uninstall R:\WBDK\WBCAMPlugins.msi
if %ERRORLEVEL% EQU 1721 (
   echo Failure Reason Given is %errorlevel%
   exit /b %errorlevel%
)
:remove04
start /wait msiexec /quiet /qr /uninstall R:\WBDK\WBCanvas.msi
if %ERRORLEVEL% EQU 1721 (
   echo Failure Reason Given is %errorlevel%
   exit /b %errorlevel%
)
:remove05
start /wait msiexec /quiet /qr /uninstall R:\WBDK\WBPlatform.msi
if %ERRORLEVEL% EQU 1721 (
   echo Failure Reason Given is %errorlevel%
   exit /b %errorlevel%
)
:remove06
start /wait msiexec /quiet /qr /uninstall R:\WBDK\WBSupportLibraries.msi
if %ERRORLEVEL% EQU 1721 (
   echo Failure Reason Given is %errorlevel%
   exit /b %errorlevel%
)

:Fincentric check
cls
echo Checking if Fincentric folder still exist....
if exist c:\%PROGRAMFILES(X86)%\Fincentric
TIMEOUT /T 3 /NOBREAK
del /S /Q "c:\Program Files"\fincentric goto alldone
pause

:alldone
echo WDBK 5 has been remove...
TIMEOUT /T 1
exit
rem :remove07
rem :remove
rem :remove

Upvotes: 1

Views: 83

Answers (1)

Wes Larson
Wes Larson

Reputation: 1062

The problem isn't with the :CheckOS section, but with the :Fincentric check section.

The if statement is incomplete and has some errors. This line:

if exist c:\%PROGRAMFILES(X86)%\Fincentric

will expand to

if exist c:\C:\ProgramFiles (x86)\Fincentric

Remove the leading c: and put the path name in quotes to ensure that it doesn't have a problem with spaces. It should look like this:

if exist "%PROGRAMFILES(X86)%\Fincentric" (
    echo do stuff
    echo do more stuff
) 

Incorrect quotes around your path is also part of the same problem you have with your del line. The other part is that you're missing the concatenation symbol & (ampersand) between your two commands:

del /S /Q "c:\Program Files\fincentric" & goto alldone

Also, section labels are only recognized up to a space, so :Fincentric check is really only being recognized as :Fincentric. This doesn't look like it's currently causing you any trouble, but it potentially could in some situations. Just to be safe, I'd rename it and remove the space (something line :Fincentric_Check or :FincentricCheck)

Upvotes: 1

Related Questions