I am trying to uninstall an application using a batch script and i need to fetch the uninstaller string from reg keys, edit the uninstaller string from the regfile.
My requirement is :
I need to replace
Original string:
"UninstallString"="C:\\WINDOWS\\st6unst.exe -n \"C:\\Program Files\\Myapp\\ST6UNST.LOG\" "
with new sring:
"UninstallString"=C:\\WINDOWS\\st6unst.exe -n "C:\\Program Files\\Myapp\\ST6UNST.LOG"
that is remove \ after -n and then remove \ after ST6UNST.LOG and then the doublwe quotes.
Advance thanks.
How to find a replace a string using batch script
Moderator: DosItHelp
Murali wrote:Also i need to store the string C:\\WINDOWS\\st6unst.exe -n "C:\\Program Files\\Myapp\\ST6UNST.LOG" in a variable
Thanks.
For storing a registry value in a variable I guess you can try the following approach:
Code: Select all
@ECHO OFF
set reg_branch="HKEY_LOCAL_MACHINE\SOFTWARE\Skype\Phone"
set reg_value=SkypePath
for /f "tokens=2,*" %%a in ('reg query %reg_branch% /v %reg_value% ^| findstr %reg_value% ') do ( set yourvariable=%%b )
ECHO %yourvariable%
pause
In my case the bat file returns :
Code: Select all
C:\Program Files\Skype\Phone\Skype.exe
so it seems to be working fine.
I of course used here some registry entry created by Skype upon install.
If I remember correctly, I found this on www.robvanderwoude.com - all credits go to the author.
I used the following script to tp get the value and it works fine.
But
Before executing the uninstallation command i need to edit the string as below and run the command
RegVal contains string
i should change it to :
i.e.. remove \ after -n and then remove \ after ST6UNST.LOG and then the double quotes.
then i should execute the command.
Thanks.
@echo off
REGEDIT /E MyAppReg.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ST6UNST #1"
FOR /F "tokens=1* delims==" %%A IN ('TYPE MyappReg.reg ^| FINDSTR.EXE /I /B /R /C:"\"UninstallString\"="') DO (
SET RegKey=%%~A
SET RegVal=%%~B
)
%RegVal%
pause
But
Before executing the uninstallation command i need to edit the string as below and run the command
RegVal contains string
"C:\\WINDOWS\\st6unst.exe -n \"C:\\Program Files\\Myapp\\ST6UNST.LOG\"
i should change it to :
"C:\\WINDOWS\\st6unst.exe -n "C:\\Program Files\\Myapp\\ST6UNST.LOG"
i.e.. remove \ after -n and then remove \ after ST6UNST.LOG and then the double quotes.
then i should execute the command.
Thanks.
Murali wrote:"C:\\WINDOWS\\st6unst.exe -n "C:\\Program Files\\Myapp\\ST6UNST.LOG"
Are you sure you need to have three quote marks here ?
EDIT
well, here goes :
Code: Select all
@ECHO OFF
:: here goes ...
SET var="C:\\WINDOWS\\st6unst.exe -n "C:\\Program Files\\Myapp\\ST6UNST.LOG"
ECHO original string
ECHO.
ECHO %var%
ECHO.
SET substr1=%VAR:~1,28%
SET substr2=%VAR:~31,37%
SET your_var=%substr1%"%substr2%"
ECHO new string
ECHO.
ECHO %your_var%
ECHO.
pause
exit
I hope this is what you needed and will be able to modify it in case I misunderstood anything
works on XP, dunno about different versions of Windows