Sign in to follow this  
Followers 0
orbs

get Windows version info

2 posts in this topic

#1 ·  Posted (edited)

this has been asked in the forum many times, i hope this function "Remarks" section can sum-up the idea with all its considerations and caveats.

the thing is, the internal macro @OSVersion is not always up-to-date for the newest versions of windows, notably the preview releases, so a more direct approach is taken here.

; #FUNCTION# ====================================================================================================================
; Name ..........: _OSVersion
; Description ...: Returns the Windows version as registered in the registry.
; Syntax ........: _OSVersion([$sHostName = @ComputerName])
; Parameters ....: $sHostName - [optional] The host name (or IP address) of the host to retrieve the informatino for.
; Return values .: Success - Returns a numeric decimal value corrsponding to Windows version.
;                  Failure - Returns 0 and sets @error to 1.
; Author ........: orbs
; Modified ......:
; Remarks .......: * Continuously updating list of Windows versions is posted at the MSDN link hereunder. Info as per March 2015:
;                      Operating system                  Version number
;                      -----------------                 --------------
;                      Windows 10 Technical Preview      10.0
;                      Windows Server Technical Preview  10.0
;                      Windows 8.1                        6.3
;                      Windows Server 2012 R2             6.3
;                      Windows 8                          6.2
;                      Windows Server 2012                6.2
;                      Windows 7                          6.1
;                      Windows Server 2008 R2             6.1
;                      Windows Server 2008                6.0
;                      Windows Vista                      6.0
;                      Windows Server 2003 R2             5.2
;                      Windows Server 2003                5.2
;                      Windows XP 64-Bit Edition          5.2
;                      Windows XP                         5.1
;                      Windows 2000                       5.0
;                  * The returned value is numerical, although it is stored in the registry as a string (REG_SZ). This allows for
;                    numerical comparison, for example _OSVersion()<6 means XP/2003 or earlier, _OSVersion()>6.1 means the new
;                    and arguably hideous generation of Windows (featuring the "Metro" crap).
;                  * The relevant registry key is not affected by WOW64 (see 2nd MSDN link hereunder), so no need to use HKLM64.
;                  * The relevant registry branch contains other useful information, e.g. a string representation of the OS name
;                    and Service Pack level. For example:
;                      "Windows 7 Ultimate" data is stored in value "ProductName"
;                      "Service Pack 1" data is stored in value "CSDVersion"
;                  * To retrieve the information for another host over network, adequate connectivity and authorization required.
; Related .......:
; Link ..........: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832.aspx
;                  https://msdn.microsoft.com/en-us/library/windows/desktop/aa384253(v=vs.85).aspx
;                  http://stackoverflow.com/questions/14648796/currentversion-value-in-registry-for-each-windows-operating-system
; Example .......: No
; ===============================================================================================================================
Func _OSVersion($sHostName = @ComputerName)
    Local $sOSVersion = RegRead('\\' & $sHostName & '\HKLM\Software\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion')
    If @error Then Return SetError(1, 0, 0)
    Return Number($sOSVersion)
EndFunc   ;==>_OSVersion
Edited by orbs
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

HEADS UP!

Windows 10 RTM returns 6.3, not 10.0 as expected. Microsoft, for their own reasons, chose to cripple this entry in the registry. do NOT use this function for Windows 10. instead, an alternative method was suggested by all-mighty KaFu here:

EDIT: the rest of the said registry branch still contains relevant information. it seems that only the CurrentVersion value is crippled.

Edited by orbs
1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0