使用组策略升级程序

使用组策略升级程序

我正在尝试通过 GPO 安装已安装在某些计算机上的程序的新版本。目前,该策略是基于用户的,如果没有安装该程序的先前版本,则该策略可以正常工作。如果安装了该程序的旧版本,则该策略不执行任何操作,但仍视为成功。该程序的旧版本是在每台计算机上手动安装的,因此我无法进行升级。

有没有简单的方法可以替换或删除旧版本?我想过用另一项策略删除旧版本,但这似乎有点草率。

答案1

如果应用程序在“添加/删除程序”中列出,您可以识别之前要执行的 msi 命令以进行全新安装。通常,该条目位于HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall,以及特定的 UninstallString 如 MsiExec.exe /I{23170F69-40C1-2702-0920-000001000000}。

因此,您可以执行 GPO 来先前运行执行该命令的 CMD,然后计算机启动并推送新应用程序。

这是使用 VBS 重新安装 Jabber 的最新版本的一个示例:

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()

答案2

看看这个,这是使用批处理查找软件的 UninstallString 注册表项,然后默默卸载软件与 wmic 相比更可靠我发现。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

相关内容