1

I want exactly the same output as winver only on the command line. For example, on my machine running winver returns this:

enter image description here

I need a command line alternative that would return 1909. I know how to get the 18363 piece - [environment]::OSVersion.Version.Build (in powershell). Googling reveals several options, none of which tell me that the version is 1909:

  • wmic os get
  • systeminfo

Now maybe they encode it differently, I do not know. Ideally I want to get the Version and the OS Build.

EDIT 1

I am OK to read it from registry, since it can be done on the command line.

EDIT 2

Thanks to a hint from dxiv I found it:

(get-itemproperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId
mark
  • 59,016
  • 79
  • 296
  • 580
  • Don't know that there is an API for that besides reading it from the registry directly, and things don't seem to have changed since [Retrieving Windows version “1511”](https://stackoverflow.com/questions/33641076/retrieving-windows-version-1511). – dxiv Jan 09 '21 at 20:11
  • 1
    @dxiv If you provide an answer, I would be able to credit you. – mark Jan 09 '21 at 20:36

1 Answers1

1

The "Version" number displayed in winver matches the ReleaseID value from the registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion, and circumstantial evidence suggests that there is no API to retrieve it, other than reading it from the registry (per my previous answer here).

The following reads the version number from the registry into a Version environment variable at the cmd prompt (double the %%a, %%c percents when using in a batch file).


C:\etc>for /f "tokens=1-3" %a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseID') do @set "Version=%~c"

C:\etc>echo Version = '%Version%'
Version = '2004'
dxiv
  • 16,984
  • 2
  • 27
  • 49