tags:

views:

93

answers:

2

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?

+1  A: 

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.

Brian R. Bondy
A: 

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

PiotrLegnica
ProductType is 2 on servers currently acting as a domain controller.
Ben Blank
You can also use wmic os get OperatingSystemSKU. As long as you are using Windows Vista or newer (and it appears you are) that property should exist. A list of values for SKU appears here.http://msdn.microsoft.com/en-us/library/aa394239%28VS.85%29.aspx
Tofystedeth