Page 1 of 1

Findstr with registry

Posted: 22 Feb 2011 06:10
by zugort
Hey guys,

At first I have to say I'm new to Batch programming. :D

I have a question:
Is it possible to get from the Standard registry entry at

"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PHPScript\Shell\Open\Command",

which looks like "C:\xampp\php\php.exe -f "%1" -- %*" to only get the exe file and the path to it (And not all the other stuff)?
And finally is it possible to save that in a variable?

I'm sorry, if I didn't express it in the right way. So feel free to ask ;-)

Greetings from Germany,
zugort :)

Re: Findstr with registry

Posted: 22 Feb 2011 07:47
by zugort
I did it:

for /F "tokens=3" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PHPScript\Shell\Open\Command"') do set var1=%%G

I almost had it like this, but I used delims, which was obviously wrong :roll:
Thank you for your patience 'though ;-)

Greetings,
zugort

Re: Findstr with registry

Posted: 22 Feb 2011 11:15
by xl1000
Interesting topic :)

How about this one:

Code: Select all

reg QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\txtfile\Shell\Open\Command"

The output is:

Code: Select all

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\txtfile\Shell\Open\Command
    <NO NAME>   REG_EXPAND_SZ   "C:\Program Files\Notepad++\notepad++.exe" %1


Here the file is located in a path containing spaces.

Re: Findstr with registry

Posted: 22 Feb 2011 12:45
by aGerman
Hmm. Maybe not the best way, but we could use ".exe" as string separator.

Code: Select all

@echo off &setlocal

for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Classes\txtfile\Shell\Open\Command" /ve') do (
  set "command=%%~b"
  setlocal enabledelayedexpansion
  for /f "delims=?" %%c in ("!command:.exe=?!") do (
    endlocal
    set "appfullname=%%c.exe"
  )
)

echo %appfullname%
pause


Regards
aGerman

Re: Findstr with registry

Posted: 22 Feb 2011 15:27
by xl1000
Close, but no cigar yet...
Output is :

Code: Select all

REG_EXPAND_SZ   "C:\Program Files\Notepad++\notepad++.exe

Changing the "tokens=2*" into "tokens=3*" did the trick
The output now becomes :

Code: Select all

C:\Program Files\Notepad++\notepad++.exe


So, now the cigar is earned ... thnx.. :lol:

Re: Findstr with registry

Posted: 22 Feb 2011 16:22
by aGerman
Yeah :lol:
I didn't consider the command output that you wrote. Your <NO NAME> is my (Standard). As you can see it's language dependent how many spaces the string contains :wink:

Regards
aGerman