midiboy Posted February 13, 2005 Share Posted February 13, 2005 Hi guys,I am sorry to bother you with this but I cannot find the solution to this so I hope someone might have an idea or even a solution to this problem.I am trying to query a string from the registry and put the result in a variable from inside a batch file.The information I want to retrieve out of the registry is the installation path of ZoomPlayer.It is stored like this in the registry:[HKEY_CURRENT_USER\Software\VirtuaMedia\ZoomPlayer]"InstallDirectory"="C:\\Programme\\Zoom Player"Now, I am querying the registry with this command:FOR /F "TOKENS=3" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory ^| FINDSTR "REG_SZ" ') do set INSTALLPATH = "%%i"This works fine except for one small problem. It will always retrieve this result:"C:\Programme\Zoom"This means, it will stop at the first blank instead of retrieving the whole path. Of course this is useless !I have tried all kinds of things to get around this but found no working solution. Any ideas ?Thanks for your help ! Bye,Alex Link to comment Share on other sites More sharing options...
Dahi Posted February 14, 2005 Share Posted February 14, 2005 Try this to get the bit after the space.FOR /F "TOKENS=3*" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory ^| FINDSTR "REG_SZ" ') do set MyInstallPath = "%%i %%j"INSTALLPATH wasnt getting set correctly on my PC, so I had to change it to MyInstallPath. Link to comment Share on other sites More sharing options...
midiboy Posted February 14, 2005 Author Share Posted February 14, 2005 Hi Dahi,as usual, your tip works great, thanks ! If you don´t mind ... could you give me some theory as to why it works that way ? I understand the reason behind the "*" after tokens but I have no idea why a second variable "%%j" would be necessary ....thanks, you helped a lot ! Bye,Alex Link to comment Share on other sites More sharing options...
midiboy Posted February 14, 2005 Author Share Posted February 14, 2005 Hi again, Dahi,I guess I was too early with my assumption. It is not working correctly yet. Or I am too stupid FOR /F "TOKENS=3*" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory ^| FINDSTR "REG_SZ" ') do set MYINSTALLPATH = "%%i %%j"ECHO ZoomPlayer was found in %MYINSTALLPATH%The outcome of this was:ZoomPlayer was found inNo matter, what name I choose for the variable, be it WHERE or MYINSTALLPATH or anything else ... it does not get echoed correctly. Does the name of this variable really matter ??I checked by using "set" before echoing the variable and the variable MYINSTALLPATH was set correctly but I still cannot "use" it ??Probably just a minor thing but ....Thanks for your help !Alex Link to comment Share on other sites More sharing options...
Martin Zugec Posted February 14, 2005 Share Posted February 14, 2005 Change FOR /F "TOKENS=3*" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory ^| FINDSTR "REG_SZ" ') do set MyInstallPath = "%%i %%j"to FOR /F "TOKENS=3*" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory ^| FINDSTR "REG_SZ" ') do set MyInstallPath="%%i %%j" Link to comment Share on other sites More sharing options...
midiboy Posted February 14, 2005 Author Share Posted February 14, 2005 Yeah, that did it, soulin !Thanks alot !!! Bye,Alex Link to comment Share on other sites More sharing options...
Dahi Posted February 14, 2005 Share Posted February 14, 2005 Well spotted Soulin!According to the help for the FOR command, the %%J holds the text picked up by the *.FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k would parse each line in myfile.txt, ignoring lines that begin with a semicolon, passing the 2nd and 3rd token from each line to the for body, with tokens delimited by commas and/or spaces. Notice the for body statements reference %i to get the 2nd token, %j to get the 3rd token, and %k to get all remaining tokens after the 3rd.Since REG returns values separated by tabs, you could use delims to extract just the bit you want. Just make sure you have only one TAB character between the DELIMS= and the quote mark. And you can drop the FINDSTR too.FOR /F "TOKENS=3 DELIMS= " %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory') do set MyInstallPath="%%i" Link to comment Share on other sites More sharing options...
midiboy Posted February 14, 2005 Author Share Posted February 14, 2005 Thanks a lot for the explanation, Dahi ! Bye,Alex Link to comment Share on other sites More sharing options...
Bilou_Gateux Posted February 14, 2005 Share Posted February 14, 2005 Ooops! Same answer as Dahi.:: set local install DatabaseUpdateDirectoryHttp variable:: 3 tokens are 'ValueName' 'Type' 'Value under selected Key':: delims is a tab delimiterfor /F "tokens=3 delims= " %%I in ('REG QUERY "HKLM\SOFTWARE\Data Fellows\F-Secure\Anti-Virus" /v "DatabaseUpdateDirectoryHttp" ^| findstr "REG_SZ" ') do set DatabaseUpdateDirectoryHttp="%%I":: For troubleshooting purposesIF %DEBUG%==TRUE echo. DatabaseUpdateDirectoryHttp = %DatabaseUpdateDirectoryHttp% Link to comment Share on other sites More sharing options...
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