MSFN Forum: Batch file problem ... - MSFN Forum

Jump to content



Unattended CD/DVD Guide Homepage · MSFN Forum Rules

Welcome to the Applications Installs forum. Make sure you read the forum rules before you start posting.

Links/Requests to warez and/or any illegal material (porn, cracks, serials, etc..) will not be tolerated. Discussion of circumventing WGA/activation/timebombs/keygens or any other illegal activity will also not be tolerated.

We try our best to keep this forum clean of illegal content. If you see any illegal activity use the "report" button you find in every post to report the specific post to the moderators. If you ignore any of the rules you will be banned without notice.

Read Forum Rules
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch file problem ... Rate Topic: -----

#1 User is offline   midiboy 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 586
  • Joined: 04-July 04

Posted 13 February 2005 - 05:24 PM

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


#2 User is offline   Dahi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 146
  • Joined: 25-November 03

Posted 14 February 2005 - 01:49 AM

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.

#3 User is offline   midiboy 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 586
  • Joined: 04-July 04

Posted 14 February 2005 - 03:13 AM

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

#4 User is offline   midiboy 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 586
  • Joined: 04-July 04

Posted 14 February 2005 - 03:59 AM

Hi again, Dahi,

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

Or I am too stupid :P

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

#5 User is offline   Martin Zugec 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,373
  • Joined: 24-January 04

Posted 14 February 2005 - 04:08 AM

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"


#6 User is offline   midiboy 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 586
  • Joined: 04-July 04

Posted 14 February 2005 - 04:19 AM

Yeah, that did it, soulin !

Thanks alot !!!

:hello:

Bye,
Alex

#7 User is offline   Dahi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 146
  • Joined: 25-November 03

Posted 14 February 2005 - 06:44 AM

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.
FOR /F "TOKENS=3 DELIMS=	" %%i in ('reg query "HKCU\Software\VirtuaMedia\ZoomPlayer" /v InstallDirectory') do set MyInstallPath="%%i"


#8 User is offline   midiboy 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 586
  • Joined: 04-July 04

Posted 14 February 2005 - 10:49 AM

Thanks a lot for the explanation, Dahi !

Bye,
Alex

#9 User is offline   Bilou_Gateux 

  • Powered by Windows Embedded
  • PipPipPipPipPip
  • Group: Members
  • Posts: 766
  • Joined: 03-January 04

Posted 14 February 2005 - 10:56 AM

Ooops! Same answer as Dahi.
:: 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%


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy