How, in the simplest possible way, distinguish between Windows XP and Windows Vista, using Python and pywin32 or wxPython?
Essentially, I need a function that called will return True iff current OS is Vista:
>>> isWindowsVista()
True
The simplest solution I found is this one:
import sys
def isWindowsVista():
'''Return True iff current OS is Windows Vista.'''
if sys.platform != "win32":
return False
import win32api
VER_NT_WORKSTATION = 1
version = win32api.GetVersionEx(1)
if not version or len(version) < 9:
return False
return ((version[0] == 6) and (version[8] == VER_NT_WORKSTATION))
The solution used in Twisted, which doesn't need pywin32:
def isVista():
if getattr(sys, "getwindowsversion", None) is not None:
return sys.getwindowsversion()[0] == 6
else:
return False
Note that it will also match Windows Server 2008.
Python has the lovely 'platform' module to help you out.
>>> import platform
>>> platform.win32_ver()
('XP', '5.1.2600', 'SP2', 'Multiprocessor Free')
>>> platform.system()
'Windows'
>>> platform.version()
'5.1.2600'
>>> platform.release()
'XP'