A_OSVersion für Windows 10 und 11

Hilfreiche Erklärungen und Tipps zum Lernen von Autohotkey

Moderator: jNizM

just me
Posts: 9466
Joined: 02 Oct 2013, 08:51
Location: Germany

A_OSVersion für Windows 10 und 11

05 Dec 2023, 11:21

Die interne Variable liefert für Windows 10 und 11 eine Zeichenfolge im Format "Haupt.Neben.Build" (englisch "major.minor.build"). Dabei steht in "Haupt.Neben" für alle bisherigen Versionen immer 10.0.

Die im Laufe der Jahre erschienenen Versionen haben unterschiedliche Eigenschaften. Wenn in einer neuern Version neue Funktionen eingeführt werden, verweist Microsoft in aller Regel auf den Versionsnamen. Den Versionsnamen sind die folgenden Build-Nummen zugeordnet:

Code: Select all

Build -> "Name"

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"
garry
Posts: 3771
Joined: 22 Dec 2013, 12:50

Re: A_OSVersion für Windows 10 und 11

06 Dec 2023, 09:44

@just me danke für die Infos
anbei ein Skript Beispiel
Productname = Windows 10 Pro , wobei Build>Name ist = 22000 -> "Win 11 21H2" ( ich habe Windows-11)
;-
viewtopic.php?f=6&t=3514 ;- parts from user @jNizM
A collection of small ahk functions - AutoHotkey Community
;-

Code: Select all

/*
Die interne Variable liefert für Windows 10 und 11 eine Zeichenfolge im Format "Haupt.Neben.Build" (englisch "major.minor.build"). 
Dabei steht in "Haupt.Neben" für alle bisherigen Versionen immer 10.0.
Beispiel:
-----------------------------
Full-version      = 10.0.22000.493 ;-- Major.Minor.BuildNumber.UBR < UBR=Update-Build-Revision ( see also cmd =ver )
Build-Name/Number = 21H2/22000
OSinstallDate     = 08. März 2022 - 20:38   |   (639 days)
ProductID         = 00330-51660-51169-AAOEM
Productname       = Windows 10 Pro
Computername      = DESKTOP-QJ0O5KT
releaseID         = 2009
is64bit           = 1
Processorname     = Intel(R) Pentium(R) Silver J5005 CPU @ 1.50GHz
AHK-VERSION       = 1.1.37.01
SCREEN            = 3840*2160
Username=Admin    = ursul=0
Memory            = 8032.41
-----------------------
*/
;----------------------
;----------------------
e1=
(
-----------------------
Build -> "Name"
-----------------------
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"
-----------------------
)
;------------------------------------
F1=%a_scriptdir%\Windows_Version.txt
ifexist,%f1%
 filedelete,%f1%
;---------
FormatTime, Suomi , L1035, dddd MMMM yyyy-MM-dd  HH:mm
Path = HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
RegRead, ProductID, %Path%, ProductID
RegRead, ProductName, %Path%, ProductName
RegRead, ReleaseID, %Path%, ReleaseID
RegRead, version, %Path%,DisplayVersion
RegRead, buildnumber, %Path%,currentbuild
RegRead,UBR, %Path%,UBR
RegRead, ProcessorName, HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0, ProcessorNameString
osinstalldate1:=OSInstallDate()
GMSEx := GlobalMemoryStatusEx()
GMSExM01 := Round(GMSEx[2] / 1024**2, 2)
;---------
FileAppend,
(
DateNow           = %suomi%`r`n-----------------------------
Full-version      = %A_OSVersion%.%ubr% ;-- Major.Minor.BuildNumber.UBR < UBR=Update-Build-Revision ( see also cmd =ver )
Build-Name/Number = %version%/%BuildNumber%
OSinstallDate     = %osinstalldate1%
ProductID         = %productID%
Productname       = %ProductName%
Computername      = %A_ComputerName%
releaseID         = %ReleaseID%
is64bit           = %A_Is64bitOS%
Processorname     = %processorname%
AHK-VERSION       = %a_ahkversion%
SCREEN            = %A_screenwidth%*%A_screenHeight%
Username=Admin    = %a_username%=%a_isadmin%
Memory            = %GMSExM01%
%e1%
),%f1%,utf-8
try
 run,%f1%
exitapp
;--------------
;-- https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3514  jNizM
;--  A collection of small ahk functions - AutoHotkey Community
;-- https://www.autohotkey.com/boards/viewtopic.php?p=49269#p49269  
OSInstallDate()
{
    for objItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_OperatingSystem")
    {
        FormatTime, InstOS, % SubStr(objItem.InstallDate, 1, 14), % "dd. MMM yyyy - HH:mm"
        FormatTime, DateFrom, % SubStr(objItem.InstallDate, 1, 14), % "yyyyMMdd"
        DateTo := A_Now
        DateTo -= DateFrom, days
        return InstOS "   |   (" DateTo " days)"
    }
}

GlobalMemoryStatusEx() {
	static MEMORYSTATUSEX, init := VarSetCapacity(MEMORYSTATUSEX, 64, 0) && NumPut(64, MEMORYSTATUSEX, "UInt")
	if (DllCall("Kernel32.dll\GlobalMemoryStatusEx", "Ptr", &MEMORYSTATUSEX))
	{
		return { 2 : NumGet(MEMORYSTATUSEX, 8, "UInt64")
        , 3 : NumGet(MEMORYSTATUSEX, 16, "UInt64")
        , 4 : NumGet(MEMORYSTATUSEX, 24, "UInt64")
        , 5 : NumGet(MEMORYSTATUSEX, 32, "UInt64") }
	}
}

;================================================

Code: Select all

-----------------------------
Full-version      = 10.0.22000.493 ;-- Major.Minor.BuildNumber.UBR < UBR=Update-Build-Revision ( see also cmd =ver )
Build-Name/Number = 21H2/22000
OSinstallDate     = 08. März 2022 - 20:38   |   (639 days)
ProductID         = 00330-51660-51169-AAOEM
Productname       = Windows 10 Pro
Computername      = DESKTOP-QJ0O5KT
releaseID         = 2009
is64bit           = 1
Processorname     = Intel(R) Pentium(R) Silver J5005 CPU @ 1.50GHz
AHK-VERSION       = 1.1.37.01
SCREEN            = 3840*2160
Username=Admin    = ursul=0
Memory            = 8032.41
-----------------------
Last edited by garry on 07 Dec 2023, 08:32, edited 3 times in total.
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: A_OSVersion für Windows 10 und 11

07 Dec 2023, 02:53

Hier ist noch ne Kleinigkeit die ich hatte

Code: Select all

#Requires AutoHotkey v2.0


OSInfo := GetOSInfo()

Main := Gui()
Main.MarginX := 20
Main.MarginY := 20
Main.SetFont("s10", "Segoe UI")
Main.AddText("xm ym h24 w100 0x200", "MajorVersion")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["MajorVersion"])
Main.AddText("xm y+5 h24 w100 0x200", "MinorVersion")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["MinorVersion"])
Main.AddText("xm y+5 h24 w100 0x200", "BuildNumber")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["BuildNumber"])
Main.AddText("xm y+5 h24 w100 0x200", "UBR")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["UBR"])
Main.AddText("xm y+5 h24 w100 0x200", "FullVersion")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["FullVersion"])
Main.AddText("xm y+5 h24 w100 0x200", "DisplayVersion")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["DisplayVersion"])
Main.AddText("xm y+5 h24 w100 0x200", "ReleaseId")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["ReleaseId"])
Main.AddText("xm y+5 h24 w100 0x200", "ProductInfo")
Main.AddEdit("x+10 yp-1 w150 0x800", OSInfo["ProductInfo"])
Main.Show()


GetOSInfo()
{
	static OSInfo         := Map()
	static STATUS_SUCCESS := 0
	static PRODUCT_INFO   := Map(4, "ENTERPRISE", 7, "STANDARD_SERVER", 8, "DATACENTER_SERVER", 27, "ENTERPRISE_N"
	                           , 48, "PROFESSIONAL", 49, "PROFESSIONAL_N", 125, "ENTERPRISE_S")

	RTL_OSVERSIONINFOEXW := Buffer(284, 0)
	NumPut("UInt", 284, RTL_OSVERSIONINFOEXW, 0)
	if (DllCall("ntdll\RtlGetVersion", "Ptr", RTL_OSVERSIONINFOEXW) = STATUS_SUCCESS)
	{
		OSInfo["MajorVersion"]     := NumGet(RTL_OSVERSIONINFOEXW,   4, "UInt")
		OSInfo["MinorVersion"]     := NumGet(RTL_OSVERSIONINFOEXW,   8, "UInt")
		OSInfo["BuildNumber"]      := NumGet(RTL_OSVERSIONINFOEXW,  12, "UInt")
		OSInfo["ServicePackMajor"] := NumGet(RTL_OSVERSIONINFOEXW, 276, "UShort")
		OSInfo["ServicePackMinor"] := NumGet(RTL_OSVERSIONINFOEXW, 278, "UShort")
	}

	if (DllCall("kernel32\GetProductInfo", "UInt", OSInfo["MajorVersion"]
	                                     , "UInt", OSInfo["MinorVersion"]
										 , "UInt", OSInfo["ServicePackMajor"]
										 , "UInt", OSInfo["ServicePackMinor"]
										 , "UInt*", &ProductType := 0))
		OSInfo["ProductInfo"] := PRODUCT_INFO.Has(ProductType) ? PRODUCT_INFO[ProductType] : ProductType

	OSInfo["DisplayVersion"]       := RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DisplayVersion", "")
	OSInfo["ReleaseId"]            := RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "")
	OSInfo["UBR"]                  := RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR", "")
	OSInfo["FullVersion"]          := OSInfo["MajorVersion"] "." OSInfo["MinorVersion"] "." OSInfo["BuildNumber"] "." OSInfo["UBR"]

	return OSInfo
}
Image
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
just me
Posts: 9466
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A_OSVersion für Windows 10 und 11

07 Dec 2023, 04:51

Moin,

mir ist schon klar, dass man die Buildnummer und die Bezeichnung des installierten Systems auslesen kann. Ich habe das eingestellt, weil ich in v2 mit VerCompare() überprüfen wollte, ob das System eine Funktion aufrufen kann, die laut Microsoft erst ab Win 10 1607 vefügbar ist. Man könnte das auch per Vergleich der Displayversion lösen. Mir war das aber zu umständlich.

Schöne Vorweihnachtszeit!
just me

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 59 guests