How to check if OS is Vista in Python? How to check if OS is Vista in Python? python python

How to check if OS is Vista in Python?


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'

NOTE: As mentioned in the comments proper values may not be returned when using older versions of python.


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.


The simplest solution I found is this one:

import sysdef 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[1] == 0) and            (version[8] == VER_NT_WORKSTATION))