Daniel Delaney
Daniel Delaney

Reputation: 1183

Python check windows server version

I need to log the current windows version in my python application for reporting purposes, but the built in functions I've found so far cant tell the difference between Windows client and server versions:

os.sys.getwindowsversion()
(6, 0, 6002, 2, 'Service Pack 2')
platform.release()
'Vista'
platform.win32_ver()
('Vista', '6.0.6002', 'SP2', 'Multiprocessor Free')

These functions return the same values on Windows Vista and Windows Server 2008 (Since they share the same version number).

Is there any way to get the correct windows version?

Upvotes: 1

Views: 2719

Answers (2)

Brian R. Bondy
Brian R. Bondy

Reputation: 347216

You could use the GetVersionEx Win32 API and check the value of wProductType to differentiate.

Check out the Python for Windows extension package.

VER_NT_DOMAIN_CONTROLLER 0x0000002

The system is a domain controller and the operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.

VER_NT_SERVER 0x0000003

The operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.

Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.

VER_NT_WORKSTATION 0x0000001

The operating system is Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.

Upvotes: 1

Cat Plus Plus
Cat Plus Plus

Reputation: 129774

Try fetching it using WMI Win32_OperatingSystem class (ProductType is 3 on server systems). Scriptomatic can generate Python code for that.

Upvotes: 0

Related Questions