Jump to content

String Replace Help


Recommended Posts

So I ran into this crazy "program" that cant be uninstalled via WMI, MSIExec, etc.

The only way to uninstall it was from Add/Remove programs manually... Or I found if you find it in the registry under HKCU and run the  uninstall string, it will also uninstall.

However the string in the registry cant be run directly in a cmd window because of the format errors.

It has spaces without quotations, it has invalid characters, etc, etc 

I know things run different when executed in the registry, so maybe there is a way I can run the regsitry key just like how the system does?  If so chime in.

Otherwise I did this a crude way using several stringregexpreplace() functions and have it working.

The solution feels so barbaric and crude that I wanted to post it so some of you guys better than me can clean up the code, maybe offer alternative ways to do it, or reduce the number of times I process the string.

Here is the string right out of the registry:

c:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe /Uninstall file:///C:/Users/it022565/AppData/Local/Temp/OOBAXTOWordAddIn/ApplicationXtender.AXTO.Word.vsto

Here is my cave man scripting to turn this into a run able string.

 

Func _UninstallOld()
    For $i = 1 to 100 ;Enumerate Registry
        $sEnumBase = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" ;Look in HKCU for the uninstall string for the old version
        $sEnum = RegEnumKey($sEnumBase, $i)
        If @Error Then Return
        If $iDebug = 1 Then MsgBox(0, "", $sEnum)
        If StringInStr(RegRead($sEnumBase & $sEnum, "DisplayName"), "Word Addin") Then ExitLoop
    Next
    If $iDebug = 1 Then MsgBox(0, "", $sEnum)
    $sKey = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sEnum
    $sKey2 = RegRead($sKey, "UninstallString")
    If $iDebug = 1 Then MsgBox(0, "Original Install Location", $sKey2)
    $sKey3 = StringRegExpReplace($sKey2, "(?i)(c:.*exe)", '"$1"')
    If $iDebug = 1 Then MsgBox(0, "", $sKey3)
    $sKey4 = StringRegExpReplace($sKey3, "(?i)file:///", "")
    If $iDebug = 1 Then MsgBox(0, "", $sKey4)
    $sKey5 = StringRegExpReplace($sKey4, "%20", " ")
    If $iDebug = 1 Then MsgBox(0, "", $sKey5)
    $sKey6 = StringRegExpReplace($sKey5, '(?i)((?<!")c:.*vsto)', '"$1"')
    If $iDebug = 1 Then MsgBox(0, "", $sKey6)
    RunWait(@ComSpec & ' /c ' & '"' & $sKey6 & ' /s"', "", @SW_HIDE)
EndFunc

Basically step by step I add quotations, strip bad characters, etc.  Kind of proud for using look behind for once :)

Looking forward to what you guys come up with.

Link to comment
Share on other sites

Hey,

Why do you need to read the uninstall string every time if you already know what it is? :)

if fileexists ("c:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe") then

    Run("c:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe /Uninstall " & @UserProfileDir & "\AppData\Local\Temp\OOBAXTOWordAddIn\ApplicationXtender.AXTO.Word.vsto")  

endif

 

Edited by Neutro
Link to comment
Share on other sites

 

On 5/11/2017 at 4:23 PM, Neutro said:

Hey,

Why do you need to read the uninstall string every time if you already know what it is? :)

if fileexists ("c:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe") then

    Run("c:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe /Uninstall " & @UserProfileDir & "\AppData\Local\Temp\OOBAXTOWordAddIn\ApplicationXtender.AXTO.Word.vsto")  

endif

 

Because I do not know what it is, the install location for the vsto is different for almost every computer.  Most of them are under a specific  users desktop folder.  You also do not know if it was installed with 32bit or 64bit visual studio so the uninstaller could be program files or program files (x86).

Edited by ViciousXUSMC
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...