Solved Extract Windows version from Text

July 24, 2011 at 15:17:54
Specs: Windows 7
Hi everyone,

I hope there is someone who can help solve this because my Dos scripting is pretty basic and I have not been able to create or find a solution so far despite trying for some hours.

I want to extract the Windows version from the registry which can be done using the following instruction, however it includes a lot of extra text which is not wanted

reg.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName

This gives the following text

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
ProductName REG_SZ Windows 7 Ultimate

What I want is to extract the windows version after REG_SZ, trimming any spaces so that just the Windows version is returned or available in a variable. Therefore what will extract just the Windows version, be it Windows XP, Vista or Windows 7?

See More: Extract Windows version from Text

Report •

July 24, 2011 at 18:09:02
✔ Best Answer
Try this, it works on my system Win XP where the Reg.exe is ver 3.0 and the output consists of 3 lines of text plus two blank lines..

@echo off

for /f "skip=4 tokens=1-2*" %%1 in ('reg.exe query "hklm\software\microsoft\windows nt\currentversion" /v Productname') do (
    echo %%3

Please come back & tell us if your problem is resolved.

Report •

July 25, 2011 at 17:24:27
That is strange, I am using Win XP and I get 2 text lines as shown above plus one blank line output by the query. Reg.exe is v3.0 on mine too.

Using the registry is meant to be a more reliable and faster method of finding the Operating system than using systeminfo.

Thank you, nevertheless despite the apparent difference in output, it still works very well.

Report •

July 25, 2011 at 19:57:37
Mmmm. Thanks for the info. I reran the query on XP Pro (Corporate) and still get 4 lines before the required info, lines 1 and 3 are blank. See

Thanks for coming back to report your success.



Please come back & tell us if your problem is resolved.

Report •

Related Solutions

Ask Question