UninstallMSI Function: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
${If} ${RunningX64} | ${If} ${RunningX64} | ||
Setregview 64 | |||
StrCpy $0 "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | |||
${Else} | |||
Setregview 32 | |||
StrCpy $0 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | |||
${EndIf} | |||
${registry::Open} "$0" "/NI='$R0' /K=0 /T=REG_SZ" $1 | |||
StrCpy $6 0 | |||
${While} $6 < 1 | |||
${registry::Find} $1 $2 $3 $4 $5 | |||
${If} $3 == "DisplayName" | |||
${AndIf} $4 == "$R0" | |||
StrCpy $6 1 | |||
${EndIf} | ${EndIf} | ||
${If} $5 == "" | |||
StrCpy $6 1 | |||
${EndIf} | ${EndIf} | ||
ExecWait '$4' | ${EndWhile} | ||
${registry::Read} "HKEY_LOCAL_MACHINE\$2" "UninstallString" $4 $5 | |||
Push $4 | |||
Push '/I' | |||
Push '/quiet /x' | |||
Call StrRep | |||
Pop $4 | |||
${If} $2 == "" | |||
${OrIf} $4 == "" | |||
Goto msifail | |||
${EndIf} | |||
ExecWait '$4' | |||
msifail: | |||
${registry::Close} $1 | |||
Pop $6 | Pop $6 |
Latest revision as of 20:14, 22 April 2020
Author: Faroguy (talk, contrib) |
Description
I needed to have a robust function that would uninstall an arbitrary MSI installation. The other solution provided did not work because I did not know the GUID of the application, only its name.
Includes Required
Function
Function UninstallMSI Exch $R0 Push $0 Push $1 Push $2 Push $3 Push $4 Push $5 Push $6 ${If} ${RunningX64} Setregview 64 StrCpy $0 "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ${Else} Setregview 32 StrCpy $0 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ${EndIf} ${registry::Open} "$0" "/NI='$R0' /K=0 /T=REG_SZ" $1 StrCpy $6 0 ${While} $6 < 1 ${registry::Find} $1 $2 $3 $4 $5 ${If} $3 == "DisplayName" ${AndIf} $4 == "$R0" StrCpy $6 1 ${EndIf} ${If} $5 == "" StrCpy $6 1 ${EndIf} ${EndWhile} ${registry::Read} "HKEY_LOCAL_MACHINE\$2" "UninstallString" $4 $5 Push $4 Push '/I' Push '/quiet /x' Call StrRep Pop $4 ${If} $2 == "" ${OrIf} $4 == "" Goto msifail ${EndIf} ExecWait '$4' msifail: ${registry::Close} $1 Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 Pop $R0 EndFunction
To call the function all you need to do is this:
Push "MyOldMSIName" Call UninstallMSI