Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if OS is Vista in Python?

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 
like image 578
DzinX Avatar asked Oct 13 '08 07:10

DzinX


People also ask

What is OS name NT?

'nt' means 'New Technology' which is come with the release of a 32-bit version initially.

What is Python window?

The Python window is an efficient and convenient location to use geoprocessing tools and Python functionality from within ArcGIS. The Python commands run from this window can range from single lines of code to complex blocks with logic.


2 Answers

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.

like image 65
monkut Avatar answered Sep 23 '22 20:09

monkut


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.

like image 34
Thomas Hervé Avatar answered Sep 22 '22 20:09

Thomas Hervé