How do I uninstall a 64-bit and 32-bit application on the same action script?

Hello guys!

Here’s the deal, I need to remove WinRAR from all computers in my environment. Some people have the 32-bit version installed and some have the 64-bit version installed.

I created the following action script to remove the 64-bit version:

// Action Script to Uninstall WinRAR Silently and Remove Installation Directory

// Define the UninstallString and InstallLocation
parameter "uninstallStringx64" = "{(value "UninstallString" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"
parameter "installLocationx64" = "{(value "InstallLocation" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"

// Check if UninstallString is not empty
if {parameter "uninstallStringx64" != ""}
  // Run the UninstallString silently with administrative privileges
  waithidden cmd /C "{parameter "uninstallStringx64"} /S"

  // Check if InstallLocation is not empty
  if {parameter "installLocationx64" != ""}
    // Remove the installation directory
    waithidden cmd /C "rmdir /S /Q "{parameter "installLocationx64"}""
  endif
endif

This one works fine, but when I try to mesh with the 32-bit located in “HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver”, it doesn’t work!

The logic I’m looking for here is the following.

The action will first look if 64-bit version is present, if not then it looks for the 32-bit one and removes it, the other way around as well. And if by any means there are the two versions, then it removes both.

I’m falling to create this logic.

Is it even possible?

This will either give you the uninstall string or it will error - it will not give an empty reult (which seems to be what you are testing) if the uninstall key doesn’t exist.

The thing is, as I said, the script to remove the 64-bit version is working flawless. The problem is when I try to mesh both versions. Just look at what I tried to do:

// Action Script to Uninstall WinRAR Silently and Remove Installation Directory

action uses wow64 redirection false

// Define the UninstallString and InstallLocation
parameter "uninstallStringx86" = "{(value "UninstallString" of key "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"
parameter "installLocationx86" = "{(value "InstallLocation" of key "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"

// Check if UninstallString is not empty
if {parameter "uninstallStringx86" != ""}
  // Run the UninstallString silently with administrative privileges
  waithidden cmd.exe /C "{parameter "uninstallStringx86"}" /S

  // Check if InstallLocation is not empty
  if {parameter "installLocationx86" != ""}
    // Remove the installation directory
    waithidden cmd /C "rmdir /S /Q "{parameter "installLocationx86"}""

endif
  endif

// Action Script to Uninstall WinRAR Silently and Remove Installation Directory

action uses wow64 redirection false

// Define the UninstallString and InstallLocation
parameter "uninstallStringx64" = "{(value "UninstallString" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"
parameter "installLocationx64" = "{(value "InstallLocation" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"

// Check if UninstallString is not empty
if {parameter "uninstallStringx64" != ""}
  // Run the UninstallString silently with administrative privileges
  waithidden cmd.exe /C "{parameter "uninstallStringx64"}" /S

  // Check if InstallLocation is not empty
  if {parameter "installLocationx64" != ""}
    // Remove the installation directory
    waithidden cmd /C "rmdir /S /Q "{parameter "installLocationx64"}""

endif
  endif

This works very well when I have both 32-bit and 64-bit installed. The problem begin when I install only the 64-bit or 32-bit version, because then I get an error such as:

STATUS: Running action...
Wow64 redirection disabled. action uses wow64 redirection false
Command failed (Relevance substitution failed) parameter "uninstallStringx86" = "{(value "UninstallString" of key "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"
Command failed (Relevance clauses must be surrounded by { and } guards.) parameter "uninstallStringx86" = "{(value "UninstallString" of key "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"

--- Result ---
Evaluation Failure.

I tried to place more guards but somehow it still doesn’t uninstall the program. So, the problem here is that combining 32-bit and 64-bit removal is not working.

I think what you’re running into is the fact that relevance substitution happens before the ActionScript is run.

On machines that don’t have the 32-bit installed, the relevance returns a “not exists” error, and vice versa.

Try testing for existence when defining your parameters, providing a default value that will skip the uninstall step for the missing version.

Something like

parameter "uninstallStringx64" = ""

if {exists (value "UninstallString" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry)}

parameter "uninstallStringx64" = "{(value "UninstallString" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver" of native registry) as string}"

endif

and so on.

delete __appendfile

appendfile @ECHO OFF
appendfile {concatenation "%0d%0a" of ("start /wait %22%22 msiexec.exe /x" & name of it & " /qn REBOOT=ReallySuppress" ) of keys whose (value "DisplayName" of it as string as lowercase contains "winrar" AND (value "Publisher" of it as string as lowercase contains "xxxxxxxx")) of keys "hklm\software\microsoft\windows\currentversion\uninstall" of (native registry;registry)}

delete uninstallWinRAR.bat
copy __appendfile uninstallWinRAR.bat

waithidden cmd.exe /c uninstallWinRAR.bat

action may require restart