Skip to content

Instantly share code, notes, and snippets.

@corydolphin
Created February 6, 2013 15:48
Show Gist options
  • Save corydolphin/4723428 to your computer and use it in GitHub Desktop.
Save corydolphin/4723428 to your computer and use it in GitHub Desktop.
Find the version of VisualStudio installed on Windows using python
'''
:platform: Windows
:synopsis: Finds the current version of VisualStudio installed, supporting
Visual Studio 2005 to Visual Studio 2012 (and pretend support for 2014,
if versioning conventions continue).
.. moduleauthor:: Cory Dolphin <[email protected]>
From:http://www.mztools.com/articles/2008/MZ2008003.aspx
To detect which Visual Studio versions (2005, 2008, etc.) are installed on a computer from a setup, you can use the following Windows registry entries (or the ones in the next section):
For Visual Studio 2005: HKEY_CLASSES_ROOT\VisualStudio.DTE.8.0
For Visual Studio 2008: HKEY_CLASSES_ROOT\VisualStudio.DTE.9.0
For Visual Studio 2010: HKEY_CLASSES_ROOT\VisualStudio.DTE.10.0
For Visual Studio 2012: HKEY_CLASSES_ROOT\VisualStudio.DTE.11.0
'''
import _winreg
RegOpenKeyEx = _winreg.OpenKeyEx
RegError = _winreg.error
HKEY_CLASSES_ROOT = _winreg.HKEY_CLASSES_ROOT
def get_installed_vs_versions():
base_str = "VisualStudio.DTE.%0.1f"
versions_found = []
for version in range(8, 15): # support VS8-VS14, if convention continues
try:
RegOpenKeyEx(HKEY_CLASSES_ROOT, base_str % version)
versions_found.append(version)
except RegError: # key not found, version not present.
continue
return versions_found
def get_latest_installed_vs_version():
'''Returns the latest version of VisualStudio installed on the system'''
return max(get_installed_vs_versions())
if __name__ == "__main__":
print "Visual Studio %0.1f found" % get_latest_installed_vs_version()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment