So I've been searching for a few days now and have come up with a solution that runs outside of my company's K1000 without error. But I'm trying to have a managed installation in place that will check the version of a specific software and if it doesn't match the current version it will uninstall and install the latest MSI. I'm attempting to do this with a zip file that includes a batch file and the MSI for the new installation. The goal with this is to have an easily updatable script for newer versions of this software as the vendor releases new version frequently. When I run it through KACE currently on my test pc (Windows 7) I get zero results. No logs or anything the install just says working and then skips straight to complete with no real results. 

The Contents of my Batch File:

@ECHO off
SET LOGFILE=C:\Temp\Mimcast_install.log
call :logit >> %LOGFILE%
exit /b 0

:logit 
@ECHO OFF 
TASKKILL /IM Outlook.exe
for /f %%a in ('wmic product where 'name like "%%Mimecast for Outlook 32-bit%%"' get version /value^|find /i "Version"') do set "%%~a"
if defined Version (echo %Version%)
if not defined Version (msiexec.exe /quiet /qn /norestart /i "Mimecast for Outlook 7.3.2061.19940 (32 bit).msi")
if "%Version%"=="7.3.2061.19940" (echo Mimecast Current Version Installed) 
echo Not Current Version Installed! Uninstalling Old Version and Installing 7.3.2061.19940!
wmic product where name="Mimecast for Outlook 32-bit" call uninstall
msiexec.exe /quiet /qn /norestart /i "Mimecast for Outlook 7.3.2061.19940 (32 bit).msi" 


Managed Installation Setup:

0QUC3o.jpeg
Answer Summary:
Batch File to uninstall old versions via GUID and install via msiexec at the end is the best method I've found. Props to Chucksteel for pointing it out. Notes: Make sure your .zip archive is not creating a folder on extraction in C:\ProgramData\Dell\KACE\Downloads\{MI FOLDER}
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answer Chosen by the Author

2
We have handled uninstalls by calling the msiexec /qn /x {GUID} for all previous versions. If that version doesn't exist on the system then the command fails silently and moves onto the next version. The installation batch file then becomes the series of uninstall commands followed by the install command. When a new version is released, just add another uninstall line and update the install line.

As for the MI not creating the log file are the contents of the zip file being expanded correctly? Also, when you say "the install just says working" what do you mean? Does the KDeploy process run? Does your batch file show up in the process list?
Answered 10/26/2017 by: chucksteel
Red Belt

  • Yes, the KDeploy process runs but the batch file never shows up in the process list and it's almost as if the .zip file including the msi and batch files are never actually transferred to the remote computer. Sorry if I was vague in my explanation of that my mind was in a bit of a fog when i made this..

    I like your idea alot about using the GUID for uninstalling older version. Such a simple solution.. I think i was severly over thinking this. Would you know of a good way to check if the application is installed at all first? I was thinking about writing a redirection statement that checks if the program exists then uninstall via GUID like you suggested and if not just install it outright. I'm relatively new to batch but I'm fluent in several other languages so it's (slowly) coming to me.. I appreciate your response though.
    • Did the zip file get downloaded to C:\ProgramData\Dell\KACE\downloads? There should be a folder named for the ID of the software title (not the ID of the managed install, the associated software title). Check for that folder and its contents.

      You can check for the program by looking for one of the files that it installs first, but in my opinion that just adds another layer of complexity.
      • I'll run some tests now and let you know. I agree that does add complexity just trying to shave off some run time if possible but I'm just going to focus on getting it working correctly then maybe add that in later.
      • After rewriting the batch file and uploading the new .zip file to K1000 I tested and it is downloading and extracting the files to the download folder but i'm still not seeing the bat file run in the processes but do see the KDeploy process.

        Here is my updated batch file:

        @ECHO off
        ::Mimecast for Outlook Install Batch file
        SET LOGFILE=C:\PrgramData\dell\KACE\Mimcast_install.log
        call :logit >> %LOGFILE%
        exit /b 0

        :logit
        ::Close Outlook
        TASKKILL /IM Outlook.exe

        ::Uninstall earlier Versions

        :: 32 Bit

        ::7.0.1762.17740
        MsiExec.exe /qn /X{008134CC-B4AD-47AB-8D4A-E1626749547B}

        ::7.1.1853.18350
        MsiExec.exe /qn /X{D8885878-E4DC-4D84-A5D0-682BEB34F208}

        ::6.3.1671.16210
        MsiExec.exe /qn /X{3204F788-6F8D-44B1-80E7-DC459A67DD52}

        ::6.0.1301.14110
        MsiExec.exe /qn /X{5EF4F25A-BB0D-4C98-987C-BE5B2CD7B190}

        ::7.3.2061.19940
        MsiExec.exe /qn /X{A5C7145D-8E1B-44CD-99A3-AC242628C115}

        ::6.1.1434.14830
        MsiExec.exe /qn /X{9EC219FE-A5E1-4E18-B975-C84207ECF383}

        ::6.3.1608.16170
        MsiExec.exe /qn /X{39208598-361E-47D7-AC86-7800C956BD23}

        :: 64 Bit

        ::7.1.1853.18350
        MsiExec.exe /qn /X{E732103C-060A-46F0-BF27-B1E3490423D5}

        ::6.3.1671.16210
        MsiExec.exe /qn /X{EE6A70FD-714D-4A05-ABD8-818053504351}

        ::6.0.1301.14110
        MsiExec.exe /qn /X{19077201-CBDB-434A-A151-85C62248A471}

        ::7.0.1762.17740
        MsiExec.exe /qn /X{6D9219BB-9A0A-4172-8D7D-02B0A77ECF9A}

        ::Install Latest Version

        ::7.3.2061.19940
        msiexec.exe /i "Mimecast for Outlook 7.3.2061.19940 (32 bit).msi" /qn /norestart

        I think this is what you were getting at in your first response. Let me know if I'm missing the mark. Again I'm relatively new to writing bat files... I wish I could use powershell :(
    • Are the extracted files at the root of the created folder? Depending on how you created the zip archive they may be inside of another folder and that causes problems.

      I would simplify your batch file further and not use the call command, just in case. You should also be able to specify your command line in the MI as Mimecast_Install.bat > c:\ProgramData\Dell\KACE\mimecast_install.log and that should output everything to that file.
      • They are indeed being extracted into a folder named after the .zip archive. Thanks for that advice on logging I didn't know you could do that. I'll add that into the MI now. As for the .zip archive creating a folder let me see if I can fix that and reupload to test.
      • That did it! The log file was created but nothing was logged. I'll tinker with that some more while testing but this is perfect! I can't thank you enough for your assistance with this I would have spent days trying to figure that out before i realized it was the folder extraction that was causing the issue.
Please log in to comment

Community Chosen Answer

1
I would never rely on version data returned by an MSI, purely because vendors are lazy about that kind of thing. A current project has 2 old-version MSIs and 1 current MSI all delivering the exact same version!

It'd be much better to check either the ProductCode or for non-MSI installations, find an executable file or DLL which you know gets updated and get that file's version information. If you want to switch to more robust scripting, the '.GetDetailsOf' method of the FileSystemObject object returns file properties (38 of them!) including version information. Sticking with WMIC in batch, you can use 'datafile', 'get' and 'version'.
Answered 10/26/2017 by: VBScab
Red Belt

  • I think this was the exact issue I was having with my initial script. It was giving me all sorts of weird results trying to match Version types. I'll have to look into the '.GetDetailsOf' method 38 items compared to what WMIC provides sounds much more manageable. Got any good reading resource on the topic by chance??
Please log in to comment

Answers

0
Do as others have said and use a zip with the MSI and a .BAT file with the GUID to uninstall older versions, but add a way in your script to check for the latest version if you want. Modify the script below to find the registry path of your software, and version number. You can get the product GUID with this command run in PowerShell:
 get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize

Install Bat file contents.
*************
@echo off
REM Check registry for latest product version, parse the output to get only the number, and set it as variable
for /f "tokens=3" %%R in ('reg query "HKEY_LOCAL_MACHINE\software\wow6432node\microsoft\windows\currentversion\uninstall\{*****GUID**of**Product**Here*****}" /v DisplayVersion 2^>NUL') do (  set reg_value=%%R
)
REM If version is "PutLatestVersionHere" then goto the END. If it is not then go to install section
if "%reg_value%"=="PutLatestVersionNumberHereInTheQuotes" (
 goto :END
 ) else (
 goto :INSTALL
)
:INSTALL
REM Uninstall Older version 1 
start /wait msiexec.exe /x {*****GUID**of**Product**Here*****} /qn

REM Uninstall Older version 2
start /wait msiexec.exe /x {*****GUID**of**Product**Here*****} /qn

REM Uninstall Older version 3
start /wait msiexec.exe /x {*****GUID**of**Product**Here*****} /qn

REM Install latest version
start /wait msiexec.exe /i productpackage.msi /qn /l*v C:\Windows\Temp\ProductNameInstall.log /quiet

:END
Answered 11/20/2017 by: john.skinner
White Belt

Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja

Share