Help - Search - Members - Calendar
Full Version: Batch file problem ...
MSFN Forums > Unattended Windows Discussion & Support > Application Installs

   
Google Internet Forums Unattended CD/DVD Guide
midiboy
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:

CODE
[HKEY_CURRENT_USER\Software\VirtuaMedia\ZoomPlayer]
"InstallDirectory"="C:\\Programme\\Zoom Player"


Now, I am querying the registry with this command:

CODE
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:

CODE
"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
Dahi
Try this to get the bit after the space.
CODE
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.
midiboy
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
midiboy
Hi again, Dahi,

I guess I was too early with my assumption. It is not working correctly yet. no.gif

Or I am too stupid tongue.gif

CODE
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:

CODE
ZoomPlayer was found in


No 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
Martin Zugec
Change
CODE
FOR /F "TOKENS=3*" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory ^| FINDSTR "REG_SZ" ') do set MyInstallPath = "%%i %%j"


to

CODE
FOR /F "TOKENS=3*" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory ^| FINDSTR "REG_SZ" ') do set MyInstallPath="%%i %%j"
midiboy
Yeah, that did it, soulin !

Thanks alot !!!

welcome.gif

Bye,
Alex
Dahi
Well spotted Soulin!

According to the help for the FOR command, the %%J holds the text picked up by the *.
QUOTE
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.
CODE
FOR /F "TOKENS=3 DELIMS=    " %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory') do set MyInstallPath="%%i"
midiboy
Thanks a lot for the explanation, Dahi !

Bye,
Alex
Bilou_Gateux
Ooops! Same answer as Dahi.
CODE
:: set local install DatabaseUpdateDirectoryHttp variable
:: 3 tokens are 'ValueName'    'Type'    'Value under selected Key'
:: delims is a tab delimiter
for /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 purposes
IF %DEBUG%==TRUE echo. DatabaseUpdateDirectoryHttp = %DatabaseUpdateDirectoryHttp%
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.