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

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

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
 
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.
 
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
 
Back
Top