JB Blanco
asked on
Need a Batch script that will check the version of a file-and Uninstall if exist
Basically i need a batch script that will first check if a particular file version exists., And if it does, it will uninstall it. If it does'nt exist, than it will do nothing and exit.
in this case its the file named "BmaSearch.exe"
Here is a work in progress script that i put together. I just need help with the check version part of it.
"@echo off
REM check if Barracuda Add-In is already installed
if exist "C:\Program Files (x86)\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe" (
GOTO UNINSTALL
) else (
if exist "C:\Program Files\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe" (
GOTO UNINSTALL
))
:UNINSTALL
REM UINSTALL ADDON
echo UnInstalling
msiexec /x \\mydomain.local\sysvol\my domain.loc al\Policie s\{B7D55D1 D-7D20-46E B-92F9-FEB 42BABC41E} \Machine\A pplication s\BmaOutlo okAddIn-3. 6.20.0_x86 .msi /quiet
exit"
Please help
thanks
in this case its the file named "BmaSearch.exe"
Here is a work in progress script that i put together. I just need help with the check version part of it.
"@echo off
REM check if Barracuda Add-In is already installed
if exist "C:\Program Files (x86)\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe" (
GOTO UNINSTALL
) else (
if exist "C:\Program Files\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe" (
GOTO UNINSTALL
))
:UNINSTALL
REM UINSTALL ADDON
echo UnInstalling
msiexec /x \\mydomain.local\sysvol\my
exit"
Please help
thanks
This should do the trick; it's currently in test mode and will only display the uninstall command it would normally run.
Remove the uppercase ECHO on front of msiexec to run it for real.
Remove the uppercase ECHO on front of msiexec to run it for real.
@echo off
setlocal
call :GetFileVersion FileVersion "C:\Program Files (x86)\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe"
if "%FileVersion%"=="3.6.20.0" goto Uninstall
call :GetFileVersion FileVersion "C:\Program Files\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe"
if "%FileVersion%"=="3.6.20.0" goto Uninstall
echo BmaSearch.exe not found in a version that needs uninstalling.
goto :eof
:Uninstall
echo Uninstalling Barracuda Add-In ...
ECHO msiexec.exe /x "\\mydomain.local\sysvol\mydomain.local\Policies\{B7D55D1D-7D20-46EB-92F9-FEB42BABC41E}\Machine\Applications\BmaOutlookAddIn-3.6.20.0_x86.msi" /quiet
goto :eof
:GetFileVersion <ByRef Variable> <Path>
set __FilePath=%~2
if not exist "%__FilePath%" (
set %1=
goto :eof
)
set TempFile=%Temp%\wmic.tmp
wmic.exe DataFile WHERE Name='%__FilePath:\=\\%' GET Version /format:list >"%TempFile%"
for /f "delims=" %%a in ('type "%TempFile%" ^| find.exe "="') do (
for /f "tokens=1* delims==" %%u in ("%%a") do set __FileVersion=%%v
)
echo '%~2': %__FileVersion%
set %1=%__FileVersion%
goto :eof
ASKER
Thanks oBdA!
just a quick question,
goto :eof
:GetFileVersion <ByRef Variable> <Path>
set __FilePath=%~2
if not exist "%__FilePath%" (
set %1=
goto :eof
)
set TempFile=%Temp%\wmic.tmp
wmic.exe DataFile WHERE Name='%__FilePath:\=\\%' GET Version /format:list >"%TempFile%"
for /f "delims=" %%a in ('type "%TempFile%" ^| find.exe "="') do (
for /f "tokens=1* delims==" %%u in ("%%a") do set __FileVersion=%%v
)
echo '%~2': %__FileVersion%
set %1=%__FileVersion%
goto :eof
what does all this do?
is this really necessary?
just a quick question,
goto :eof
:GetFileVersion <ByRef Variable> <Path>
set __FilePath=%~2
if not exist "%__FilePath%" (
set %1=
goto :eof
)
set TempFile=%Temp%\wmic.tmp
wmic.exe DataFile WHERE Name='%__FilePath:\=\\%' GET Version /format:list >"%TempFile%"
for /f "delims=" %%a in ('type "%TempFile%" ^| find.exe "="') do (
for /f "tokens=1* delims==" %%u in ("%%a") do set __FileVersion=%%v
)
echo '%~2': %__FileVersion%
set %1=%__FileVersion%
goto :eof
what does all this do?
is this really necessary?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THANKS!!! that script worked perfectly!!!
wow!!
I wish i could come up with stuff like that!
wow!!
I wish i could come up with stuff like that!
"@echo off
REM check if Barracuda Add-In is already installed
if exist "C:\Program Files (x86)\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe" (GOTO UNINSTALL) else (
if exist "C:\Program Files\Barracuda\Message Archiver\Outlook Add-In\BmaSearch.exe" (GOTO UNINSTALL)) else (
GOTO END )
:UNINSTALL
REM UINSTALL ADDON
echo UnInstalling
msiexec /x \\mydomain.local\sysvol\my
:END
exit"