Guest XhmikosR Posted February 26, 2009 Posted February 26, 2009 Hello, everyone. I did a search and found many useful things but I couldn't find an entire solution for what I want to do.Anyway I want to retrieve a registry value and set it as a variable to use it later. Example:Key: HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1String: Inno Setup: App Path or InstallLocation (I don't know if there is a difference)So I want to do something like this:FOR /f "tokens=3 delims= " %%i in ( 'reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /v "Inno Setup: App Path"') DO ( SET SetupPath=%%i)But I probably do something wrong with the tokens and/or delims.Also how could I check first if a specific executable is in path and if not then check for the above registry key?Thanks everyone in advance!
Yzöwl Posted February 26, 2009 Posted February 26, 2009 I thought I'd provide an example which would work more like a template for any Inno Setup Application.Line 5 below is already set for the Topic Starter's app, anyone else can set it accordingly. You'd do this by replacing between the = and " with the Inno Setup Application Name minus the trailing _is1:e.g. Set "A_=Wise Registry Cleaner" would read the "Wise Registry Cleaner_is1" Uninstall Key@Echo off&Setlocal enableextensionsSet "U_=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"Set "I_=Inno Setup"Set "A_=%I_% 5"For /f "delims=" %%a In ( 'Reg query "%U_%\%A_%_is1" /v "%I_%: App Path"^|Find "REG_"') Do ( Set "InnoAppPath=%%a"&Call :Sub %%InnoAppPath:*Z=%%)Echo:%InnoAppPath%Pause&Goto :Eof:SubSet InnoAppPath="%*"The code has been changed from the usual delims=<tab> method to make it compatible with Vista too. The resulting variable, %InnoAppPath%, will be surrounded by double quotes, if this is not a requirement in your case you can remove them on the last line of this code.
Guest XhmikosR Posted February 26, 2009 Posted February 26, 2009 I thought I'd provide an example which would work more like a template for any Inno Setup Application.Line 5 below is already set for the Topic Starter's app, anyone else can set it accordingly. You'd do this by replacing between the = and " with the Inno Setup Application Name minus the trailing _is1:e.g. Set "A_=Wise Registry Cleaner" would read the "Wise Registry Cleaner_is1" Uninstall Key@Echo off&Setlocal enableextensionsSet "U_=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"Set "I_=Inno Setup"Set "A_=%I_% 5"For /f "delims=" %%a In ( 'Reg query "%U_%\%A_%_is1" /v "%I_%: App Path"^|Find "REG_"') Do ( Set "InnoAppPath=%%a"&Call :Sub %%InnoAppPath:*Z=%%)Echo:%InnoAppPath%Pause&Goto :Eof:SubSet InnoAppPath="%*"The code has been changed from the usual delims=<tab> method to make it compatible with Vista too. The resulting variable, %InnoAppPath%, will be surrounded by double quotes, if this is not a requirement in your case you can remove them on the last line of this code.Thank you very much! It does work for every Inno Setup App, on XP and on Vista.Since you seem to be very familiar with batch scripting, I'd like to ask you some more questions I have. 1) How can I do the above you suggested, but if there is no registry key (the app is not installed) do not show any messages on the screen but echo a custom message and go to a further step in the script?2) How can I first check if an app is in PATH? Again without any output on screen and if is in PATH do something, if not do something else.Thank you again, in advance!
Yzöwl Posted February 26, 2009 Posted February 26, 2009 1.@Echo off&Setlocal enableextensionsSet "U_=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"Set "I_=Inno Setup"Set "A_=%I_% 5"Set "M_=This is a custom message"For /f "delims=" %%a In ( 'Reg query "%U_%\%A_%_is1" /v "%I_%: App Path"2^>Nul^|Find "REG_"') Do ( Set "InnoAppPath=%%a"&Call :Sub %%InnoAppPath:*Z=%%)If not defined InnoAppPath Echo:%M_%&&Goto :FurtherStepEcho:%InnoAppPath%Pause&Goto :Eof:FurtherStepEcho:This is a further stepPause&Goto :Eof:SubSet InnoAppPath="%*"2.@Echo off&Setlocal enableextensionsSet "A_=reg.exe"For %%# In (%A_%) Do If %%~$PATH:#' Equ ' (Goto DoOneThing)Echo:The app is in PATHGoto :Eof:DoOneThingEcho:The app is not in PATH
Guest XhmikosR Posted February 27, 2009 Posted February 27, 2009 You are the master! Thank you very much for everything.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now