Jump to content
Sign in to follow this  
ViciousXUSMC

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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ni3dprint
      Hi folks, 
      Thank you so much in advance for your help!  I've been using AUTOIT for manipulating gcode.  So far I've just worked through the excellent help examples and although I'm sure the resulting code is clumsy it has functioned  
      However now I'm trying to improve and advance things and I've stumbled across REGEX.. and I'm a bit stuck.  What I would like to be able to do is to 'move'/'transform' the gcode in a file and re-write it to a new file.  I only need to move it in one direction(X).  At the heart of this I need a script to extract all the X values and then ADD or SUBTRACT an adjustment factor to transform and rewrite the code accordingly.
      So far using an example script and an example input -
      Func Test2()
      Local $iMove = -4
          Local $sInput = '"G1 X45.036 Y6.934 F7800.000 G1 Z0.600 F7800.000 G1 F900 G1 X48.036 Y1.076 E0.58925"'
          Local $sOutput = StringRegExpReplace($sInput, '(?<=[X])\d+.\d+', '\0')
          Display($sInput, $sOutput)
      EndFunc   ;==>Test2
      This identifies the correct values i.e 45.036 and 48.036 but is there a way to dyamically adjust them before they are replaced, by for example a factor of -4 ($iMove above).  So far I can't seem to do math on the '\0' value i.e '\0'+ -4 ?
      Many thanks for your time and expertise!
       
    • By jmp
      i am trying to get number from string using this code :
      #include <IE.au3> $oIE = _IEAttach ("Edu.corner") Local $aName = "Student name & Code:", $iaName = "0" Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.InnerText = $aName Then $iaName = $oTd.NextElementSibling.InnerText $iGet = StringRegExpReplace($iaName, "\D", "") EndIf Next MsgBox(0, "", $iGet) it was get number like 52503058
      But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)

       
    • By jmp
      I am adding labour charge to total paid amount using : 
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData3 = _IETableWriteToArray ($oTable) Local $sitem1 = $aTableData3[5][1] Local $sitem2 = $aTableData3[5][2] Local $lcharge = "10" ;add manualy using inputbox, becuase not generating online Local $atotPric = "Payable Total Price " Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.Innertext = $atotPric Then $iatotPric = $oTd.NextElementSibling.innertext MsgBox (0, "2", $iatotPric) EndIf Next $irCtotal = StringFormat("%.2f", $sitem1 + $sitem2 + $lcharge) $crTotp = StringReplace(_IEBodyReadHTML($oIE), $iatotPric, $irCtotal) _IEBodyWriteHTML ($oIE, $crTotp) But, It was also changing Total price, I want to change only Payable Total Price.

    • By nacerbaaziz
      hello sirs
      i've some questions about StringRegExpReplace i hope you can help me
       
      i tried to make a function that give me the host of the url and other give me the url with out host
      for example i've this link
      https://www.example.com/vb/result.php
      i need the first give me the
      example.com
      and the other give me 
      /vb/result.php
      i find that
      $s_source = "https://www.google.com/vb/index.php" Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1') Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1') msgBox(64, $s_Host, $s_Page)  
      but i found some problems i need your help to correct it
      first: when i get the host if the url has www i want to remove it
      second: if the url with out host did not have other things 
      i need the result to be ""
      e.g
      https://www.example.com
      the first i want it
      example.com
      and the second i want it to be ""
      i hope that you can help me
      thanks in advance
    • By fs1234
      Hi,
      I would like to change the hungarian characters in a string, but I can't figure out how to do it.
      Help, pls.
       
      #include <MsgBoxConstants.au3> Local $sInput = "Árvíztűrő tükörfúrógép" Local $sOutput = StringRegExpReplace($sInput, "(?-i)(á)|(Á)|(é)|(É)|(í)|(Í)|(ó)|(Ó)|(ö)|(Ö)|(ő)|(Ő)|(ú)|(Ú)|(ü)|(Ü)|(ű)|(Ű)", "(?1a)(?2A)(?3e)(?4E)(?5i)(?6I)(?7o)(?8O)(?9o)(?10O)(?11o)(?12O)(?13u)(?14U)(?15u)(?16U)(?17u)(?18U)") Display($sInput, $sOutput) Func Display($sInput, $sOutput) ; Format the output. Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) MsgBox($MB_SYSTEMMODAL, "Results", $sMsg) EndFunc ;==>Display  
×
×
  • Create New...