0

I am trying to install a new version of a program, already installed on some machines, via GPO. Currently, the policy is user based and works correctly if there is no previous version of the program installed. If there is an older version of the program installed, the policy does nothing, but is still consider a success. The older version of the program was installed manually on each machine, so I can’t do an upgrade.

Is there an easy way to have either the old version replaced or removed? I thought of having another policy remove the old version, but that seems a bit sloppy.

1
  • 3
    You can't use Group Policy to upgrade a program that wasn't installed with Group Policy. If you want to upgrade the program with Group Policy then it needs to be installed with Group Policy. Your best bet is to uninstall it and then install it with GP. Have a look at my answer here as to the why - serverfault.com/questions/760985/…
    – joeqwerty
    Apr 11, 2016 at 18:41

2 Answers 2

1

if the app is listed on Add/remove programs, you can identify the msi command to execute previous to do a fresh install. Commonly the entry is on HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall , and specific UninstallString like MsiExec.exe /I{23170F69-40C1-2702-0920-000001000000}.

So, you can do a GPO to run previously a CMD executing that command con Computer starts, and after push the new app.

This is one example for reinstall my Jabber with the last version with VBS:

On Error Resume Next
DIM fso    
Dim version
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell") 
x86=wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")&"\Cisco Systems\Cisco Jabber\CiscoJabber.exe"
x64=wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")&"\Cisco Systems\Cisco Jabber\CiscoJabber.exe"
If (fso.FileExists(x86) or fso.FileExists(x64)) Then
  version= CreateObject("Scripting.FileSystemObject").GetFileVersion(x86)
  if (strcomp(version,"",1)=0) then
    version= CreateObject("Scripting.FileSystemObject").GetFileVersion(x64)
    'Wscript.echo "x64"
  end if
  'Wscript.Echo version & "  en x86"
  if (strcomp(version,"11.5.1.29337",1)=0) then
    'Wscript.Echo "Tiene la ultima version"
  else

    'Wscript.Echo "Updating"
    WshShell.Run "msiexec.exe /I ""\\server\sharefolder\CiscoJabberSetup.msi"" /quiet"

  end if
Else
  'WScript.Echo("Install as new app")
  'WshShell.Run  "msiexec.exe /I ""\\server\sharefolder\CiscoJabberSetup.msi"" /quiet"

End If
WScript.Quit()
0

Check this out, this is using a batch find the software's UninstallString registry key and then uninstall the software silently which is much more reliable compare to wmic I found. https://community.spiceworks.com/topic/2143980-deploy-or-upgrade-java-8-via-shutdown-script-remove-old-javas

::It extracts software software GUID, then use the GUID to search the name and version
@echo off
setlocal ENABLEDELAYEDEXPANSION

set SoftwareName=Java 8
set NewVersion=8.0.1720.11
set x86GUID=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
set x64GUID=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
set Installer=\\dc\sources\jre-8u172-windows-i586.exe REMOVEOUTOFDATEJRES=1 AUTO_UPDATE=0 EULA=0 NOSTARTMENU=1 SPONSORS=0 WEB_ANALYTICS=0 WEB_JAVA=1 WEB_JAVA_SECURITY_LEVEL=H /s
REM set Installer=d:\downloads\jre-8u172-windows-i586.exe REMOVEOUTOFDATEJRES=1 AUTO_UPDATE=0 EULA=0 NOSTARTMENU=1 SPONSORS=0 WEB_ANALYTICS=0 WEB_JAVA=1 WEB_JAVA_SECURITY_LEVEL=H /s

REM It's faster to first locate the software GUID, then search it's Name, Version & UninstallString
for /f "delims=" %%P in ('reg query "%x86GUID%" /s /f "%SoftwareName%" 2^>nul ^| findstr "HKEY_LOCAL_MACHINE"') do (
  echo %%P
  reg query "%%P" /v "DisplayVersion" 2>nul | findstr /r /c:"  %NewVersion%" >nul && (
    for /f "tokens=2*" %%A in ('reg query "%%P" /v "DisplayName" 2^>nul ^|findstr "DisplayName"') do echo %%B has already been installed
    for /f "tokens=2*" %%A in ('reg query "%%P" /v "DisplayVersion" 2^>nul ^|findstr "DisplayVersion"') do echo Version: %%B
    goto :EOF
  ) || (
    for /f "tokens=2*" %%A in ('reg query "%%P" /v "DisplayName" 2^>nul ^|findstr "DisplayName"') do echo Found other version %%B, upgrade in progress
    for /f "tokens=2*" %%A in ('reg query "%%P" /v "UninstallString" 2^>nul ^|findstr "UninstallString"') do (
      echo %%B | findstr /c:"MsiExec.exe"  >nul && (
        set MsiStr=%%B
        set MsiStr=!MsiStr:/I=/X!
        echo !MsiStr! /quiet /norestart
        !MsiStr! /quiet /norestart
        rem %Installer%
      ) || (
        echo None MsiExec Uninstall String %%B
        rem "%%B" /S
      )
    )
  )
)
if not defined MsiStr (
  echo %SoftwareName% not found, install it?
  rem %Installer%
)

endlocal

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .