PC Review Forums Newsgroups Windows 2000 Microsoft Windows 2000 Registry Use reg.exe to capture value in a variable for batch use?

Reply

Use reg.exe to capture value in a variable for batch use?

 
Thread Tools Rate Thread
Old 28-09-2003, 10:27 PM   #1
Craig
Guest
 
Posts: n/a
Default Use reg.exe to capture value in a variable for batch use?


Hi folks,
I'm trying to use reg.exe to capture the value from
the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion" /v ProductName and put in into a
variable (so I can use it in a batch file)...but I can't
figure it out!!! Suggestions???

Thanks,
Craig
  Reply With Quote
Old 28-09-2003, 11:31 PM   #2
Vincent Fatica
Guest
 
Posts: n/a
Default Re: Use reg.exe to capture value in a variable for batch use?

On Sun, 28 Sep 2003 13:27:19 -0700, "Craig" <craigcaughlin@yahoo.com> wrote:

>Hi folks,
>I'm trying to use reg.exe to capture the value from
>the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
>NT\CurrentVersion" /v ProductName and put in into a
>variable (so I can use it in a batch file)...but I can't
>figure it out!!! Suggestions???


With CMD.EXE, you can (this is crude):

v:\> for /f "tokens=3-7" %i in ('reg query
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v
ProductName') do @set zzz=%i %j %k %l %m

v:\> echo %zzz%
Microsoft Windows XP

This only works because the **last** line of REG's output contains the
desired info (SET is executed for every line of REG's output). I knew it
would be 3 tokens but allowed for a couple more anyway.

--
- Vince
  Reply With Quote
Old 29-09-2003, 02:42 PM   #3
Jerold Schulman
Guest
 
Posts: n/a
Default Re: Use reg.exe to capture value in a variable for batch use?

On Sun, 28 Sep 2003 13:27:19 -0700, "Craig" <craigcaughlin@yahoo.com> wrote:

>Hi folks,
>I'm trying to use reg.exe to capture the value from
>the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
>NT\CurrentVersion" /v ProductName and put in into a
>variable (so I can use it in a batch file)...but I can't
>figure it out!!! Suggestions???
>
>Thanks,
>Craig


The following is one line:

for /f "Skip=4 Tokens=2*" %%i in ('reg query
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v
ProductName') do set PN=%%j


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off