Sign in to follow this  
Followers 0
Allow2010

Looking fo the best way to get Windows version

4 posts in this topic

Hi all,

i want to make sure that my script only runs on Windos Vist upto Windows 8.1

I want an errormessage when the script is started on newer or older Windows versions.

According to a list on the net, all windows versions have version numbers like this:

 

Windows Vista, Beta 1 6.0.5112 (20.07.2005) Windows Vista, Community Technology Preview (CTP) 6.0.5219 (30.08.2005) Windows Vista, TAP Preview 6.0.5259 (17.11.2005) Windows Vista, CTP (Dezember) 6.0.5270 (14.12.2005) Windows Vista, CTP (Februar) 6.0.5308 (17.02.2006) Windows Vista, CTP (Refresh) 6.0.5342 (21.03.2006) Windows Vista, April EWD 6.0.5365 (19.04.2006) Windows Vista, Beta 2 Previw 6.0.5381 (01.05.2006) Windows Vista, Beta 2 6.0.5384 (18.05.2006) Windows Vista, Pre-RC1 6.0.5456 (20.06.2006) Windows Vista, Pre-RC1, Build 5472 6.0.5472 (13.07.2006) Windows Vista, Pre-RC1, Build 5536 6.0.5536 (21.08.2006) Windows Vista, RC1 6.0.5600.16384 (29.08.2006) Windows Vista, Pre-RC2 6.0.5700 (10.08.2006) Windows Vista, Pre-RC2, Build 5728 6.0.5728 (17.09.2006) Windows Vista, RC2 6.0.5744.16384 (03.10.2006) Windows Vista, Pre-RTM, Build 5808 6.0.5808 (12.10.2006) Windows Vista, Pre-RTM, Build 5824 6.0.5824 (17.10.2006) Windows Vista, Pre-RTM, Build 5840 6.0.5840 (18.10.2006) Windows Vista, RTM (Release to Manufacturing) 6.0.6000.16386 (01.11.2006) Windows Vista 6.0.6000 (08.11.2006) Windows Vista, Service Pack 2 6.0.6002 (04.02.2008) Windows Server 2008 6.0.6001 (27.02.2008) Windows 7, RTM (Release to Manufacturing) 6.1.7600.16385 (22.10.2009) Windows 7 6.1.7601 Windows Server 2008 R2, RTM (Release to Manufacturing) 6.1.7600.16385 (22.10.2009) Windows Server 2008 R2, SP1 6.1.7601 Windows Home Server 2011 6.1.8400 (05.04.2011) Windows Server 2012 6.2.9200 (04.09.2012) Windows 8 6.2.9200 (26.10.2012) Windows Phone 8 6.2.10211 (29.10.2012) Windows Server 2012 R2 6.3.9200 (18.10.2013) Windows 8.1 6.3.9200 (18.10.2013) Windows 8.1, Update 1 6.3.9600 (08.04.2014)

 

As @osversion ist no very acurate (Windows 10 has 6.4.xxxxx and @osversion still gives me Win81 until an update for autoit is released) i tought about checking the numbers directly.

But @osbuild only gives me the last 4 digits of the version (like 9600). How can i acces the first two numbers (like 6.3)?

Any ideas for a good and flexible solution?

Thanks !

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

it's in the registry:

Func _OSVersion()
    Local $sHKLM = 'HKLM'
    Switch @OSArch
        Case 'X86'
            $sHKLM = 'HKLM'
        Case 'X64'
            $sHKLM = 'HKLM64'
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    $sOSVersion = RegRead($sHKLM & '\Software\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion')
    If @error Then Return SetError(1, 0, 0)
    Return Number($sOSVersion)
EndFunc   ;==>_OSVersion

EDIT: apparently it does not require HKLM64, it works also like this:

Func _OSVersion()
    $sOSVersion = RegRead('HKLM\Software\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion')
    If @error Then Return SetError(1, 0, 0)
    Return Number($sOSVersion)
EndFunc   ;==>_OSVersion

this can be applied to remote computers also.

Edited by orbs

Share this post


Link to post
Share on other sites

thanks....will try that out in my scripts...

Share this post


Link to post
Share on other sites

tried it, works great, thanks again...

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