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 UltimateWhat 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?
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 cls 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.
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.
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 http://img190.imageshack.us/img190/... Thanks for coming back to report your success.
Regards.
Wahine.
Please come back & tell us if your problem is resolved.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |