A_OSVersion for Win10/11

Helpful script writing tricks and HowTo's
just me
Posts: 9529
Joined: 02 Oct 2013, 08:51
Location: Germany

A_OSVersion for Win10/11

Post by just me » 05 Dec 2023, 10:39

The version number of the operating system, in the format "major.minor.build". For example, Windows 7 SP1 is 6.1.7601.
For Win 10 and 11 "major.minor" is 10.0 for all existing versions. Only the "build" numbers differ. The following Map associates the build numbers with Microsoft's version names:

Code: Select all

Win_10_11_Builds := Map(10240, "Win 10 1507",
                        10586, "Win 10 1511",
                        14393, "Win 10 1607",
                        15063, "Win 10 1703",
                        16299, "Win 10 1709",
                        17134, "Win 10 1803",
                        17763, "Win 10 1809",
                        18362, "Win 10 1903",
                        18363, "Win 10 1909",
                        19041, "Win 10 2004",
                        19042, "Win 10 20H2",
                        19043, "Win 10 21H1",
                        19044, "Win 10 21H2",
                        19045, "Win 10 22H2",
                        22000, "Win 11 21H2",
                        22621, "Win 11 22H2",
                        22631, "Win 11 23H2")
To be continued!

novelprocedure
Posts: 1
Joined: 13 Dec 2023, 16:06
Contact:

Re: A_OSVersion for Win10/11

Post by novelprocedure » 13 Mar 2024, 12:01

For anyone who stumbles across this post, here is a simple function to determine if you're running Windows 10 or Windows 11.

Code: Select all

GetWinOSVersion()
{
    i := A_OSVersion

    If (i < 10.0.20000) ; You're running Windows 10
        Return 10
    Else If (i >= 10.0.20000) ; You're running Windows 11
        Return 11
}

gregster
Posts: 9086
Joined: 30 Sep 2013, 06:48

Re: A_OSVersion for Win10/11

Post by gregster » 13 Mar 2024, 12:13

novelprocedure wrote:
13 Mar 2024, 12:01
For anyone who stumbles across this post, here is a simple function to determine if you're running Windows 10 or Windows 11.
I doubt that this will work correctly. Afaik, you can't use operators like < and >= like this on undefined constructs like 10.0.20000.
Try i := 9, it will still output 11, because 10.0.20000 will evaluate to blank in AHK v1 (try msgbox % 10.0.20000), and in AHK v2 this code won't run at all.
Try StrSplit() to get the final part of the OS version string and then compare the resulting numbers.

Marium0505
Posts: 42
Joined: 11 May 2020, 20:45

Re: A_OSVersion for Win10/11

Post by Marium0505 » 13 Mar 2024, 22:20

Here are two functions, the first one works from
v1.1.13.00+ (including v2):

v1.1.36.00+ (including v2):

Code: Select all

; From v1.1.36.00+ (including v2)
GetWinOSVersion(WindowsVersion := "") {
	Ver := 0
	static Versions := [[">=10.0.20000", "11"], [">=10.0.10000", "10"], [">=6.3", "8.1"], [">=6.2", "8"], [">=6.1", "7"], [">=6.0", "Vista"], [">=5.2", "XP"], [">=5.1", "XP"]]
	If !(WindowsVersion)
		WindowsVersion := A_OSVersion
	If (WindowsVersion = "WIN_7")
		Ver := "7"
	Else If (WindowsVersion = "WIN_8.1")
		Ver := "8.1"
	Else If (WindowsVersion = "WIN_VISTA")
		Ver := "Vista"
	Else If (WindowsVersion = "WIN_XP")
		Ver := "XP"
	Else {
		static Versions := [[">=10.0.20000", "11"], [">=10.0.10000", "10"], [">=6.3", "8.1"], [">=6.2", "8"], [">=6.1", "7"], [">=6.0", "Vista"], [">=5.2", "XP"], [">=5.1", "XP"]]
		for i, Version in Versions {
			If !(VerCompare(WindowsVersion, Version[1]))
				continue
			Ver := Version[2]
			break
		}
	}
	return Ver
}
Both returns 0 if less than XP, otherwise it returns 11,10,8.1,8,7,Vista, or XP as a string.

User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: A_OSVersion for Win10/11

Post by RaptorX » 29 Mar 2024, 16:17

novelprocedure wrote:
13 Mar 2024, 12:01
For anyone who stumbles across this post, here is a simple function to determine if you're running Windows 10 or Windows 11.

Code: Select all

GetWinOSVersion()
{
    i := A_OSVersion

    If (i < 10.0.20000) ; You're running Windows 10
        Return 10
    Else If (i >= 10.0.20000) ; You're running Windows 11
        Return 11
}
I think you would have to use VerCompare for this type of comparison.

What you just tried would break because those are not actual numbers due to the second . in the versioning system.
Projects:
AHK-ToolKit

User avatar
xMaxrayx
Posts: 203
Joined: 06 Dec 2022, 02:56
Contact:

Re: A_OSVersion for Win10/11

Post by xMaxrayx » 17 Apr 2024, 09:01

just me wrote:
05 Dec 2023, 10:39
The version number of the operating system, in the format "major.minor.build". For example, Windows 7 SP1 is 6.1.7601.
For Win 10 and 11 "major.minor" is 10.0 for all existing versions. Only the "build" numbers differ. The following Map associates the build numbers with Microsoft's version names:

Code: Select all

Win_10_11_Builds := Map(10240, "Win 10 1507",
                        10586, "Win 10 1511",
                        14393, "Win 10 1607",
                        15063, "Win 10 1703",
                        16299, "Win 10 1709",
                        17134, "Win 10 1803",
                        17763, "Win 10 1809",
                        18362, "Win 10 1903",
                        18363, "Win 10 1909",
                        19041, "Win 10 2004",
                        19042, "Win 10 20H2",
                        19043, "Win 10 21H1",
                        19044, "Win 10 21H2",
                        19045, "Win 10 22H2",
                        22000, "Win 11 21H2",
                        22621, "Win 11 22H2",
                        22631, "Win 11 23H2")
To be continued!
novelprocedure wrote:
13 Mar 2024, 12:01
For anyone who stumbles across this post, here is a simple function to determine if you're running Windows 10 or Windows 11.

Code: Select all

GetWinOSVersion()
{
    i := A_OSVersion

    If (i < 10.0.20000) ; You're running Windows 10
        Return 10
    Else If (i >= 10.0.20000) ; You're running Windows 11
        Return 11
}
Hi, the issue with this mothed is you relay in your database, if new Windows like WIN12 exit this mothed need to re-fix again.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

User avatar
xMaxrayx
Posts: 203
Joined: 06 Dec 2022, 02:56
Contact:

Re: A_OSVersion for Win10/11

Post by xMaxrayx » 17 Apr 2024, 09:09

here is a mothed that dosn't relay on devs Database sadly it doesn't use AHK, also you may need another way to hide you CMD pop-out

Code: Select all

#Requires AutoHotkey v2.0
MsgBox(ComObject("WScript.Shell").Exec('cmd.exe /c systeminfo | findstr /b /c:"OS Name"').StdOut.ReadAll())
beside there is another issue is relay if windows have systeminfo exited.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Post Reply

Return to “Tutorials (v2)”