Findstr with registry

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zugort
Posts: 2
Joined: 21 Feb 2011 10:37

Findstr with registry

#1 Post by zugort » 22 Feb 2011 06:10

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

zugort
Posts: 2
Joined: 21 Feb 2011 10:37

Re: Findstr with registry

#2 Post by zugort » 22 Feb 2011 07:47

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

xl1000
Posts: 10
Joined: 01 Feb 2011 06:10

Re: Findstr with registry

#3 Post by xl1000 » 22 Feb 2011 11:15

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Findstr with registry

#4 Post by aGerman » 22 Feb 2011 12:45

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

xl1000
Posts: 10
Joined: 01 Feb 2011 06:10

Re: Findstr with registry

#5 Post by xl1000 » 22 Feb 2011 15:27

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:

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Findstr with registry

#6 Post by aGerman » 22 Feb 2011 16:22

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

Post Reply