Skip to content

Instantly share code, notes, and snippets.

@EncodeTheCode
Created January 23, 2026 00:54
Show Gist options
  • Select an option

  • Save EncodeTheCode/9af5db652c39ed11d8dd0f51b4a4f17d to your computer and use it in GitHub Desktop.

Select an option

Save EncodeTheCode/9af5db652c39ed11d8dd0f51b4a4f17d to your computer and use it in GitHub Desktop.
import ctypes
def get_windows_edition():
"""Return 'Home', 'Pro' or 'Server'."""
class OSV(ctypes.Structure):
_fields_ = [
("size", ctypes.c_ulong),
("major", ctypes.c_ulong),
("minor", ctypes.c_ulong),
("build", ctypes.c_ulong),
("platform", ctypes.c_ulong),
("sp", ctypes.c_wchar * 128),
("sp_major", ctypes.c_ushort),
("sp_minor", ctypes.c_ushort),
("suite", ctypes.c_ushort),
("product", ctypes.c_byte),
("reserved", ctypes.c_byte),
]
osv = OSV()
osv.size = ctypes.sizeof(OSV)
ctypes.WinDLL("ntdll").RtlGetVersion(ctypes.byref(osv))
if osv.product == 1: # workstation
return "Home" if (osv.suite & 0x2) else "Pro"
return "Server"
# Example
if __name__ == "__main__":
print("Windows edition:", get_windows_edition())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment