Jump to content
Sign in to follow this  

Visual Studio C++ installation directory

Recommended Posts



This script below reads Visual Studio C++ installation directory from registry and prints it to console.

This script is intended to compile as console application.

The main question is: is this script work well?

I've tested this script with VS C++ 2008 only.

This script should work VS C++ 2003/2005 and VS C++ Express editions also.

Please check this script if you have any VS C++ Express edition or VS C++ 2003/2005.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Description=Reads Visual Studio C++ installation directory and prints it to StdOut.
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; VCInstallDir.au3 - installation directory of Visual Studio 2003/2005/2008 C++

Opt("TrayIconHide", 1)

Global Const $VC_SETUP_KEY = "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\%s\\Setup\\VC"
Global Const $VC_SETUP_VALUE = "ProductDir"
Global Const $VC_VER[5] = ["7.0", "8.0Exp", "8.0", "9.0Exp", "9.0"]

Func get_vc_install_dir()
    Local $i, $sVCDir
    For $i = UBound($VC_VER) - 1 To 0 Step -1
        $sVCDir = RegRead(StringFormat($VC_SETUP_KEY, $VC_VER[$i]), $VC_SETUP_VALUE)
        If Not @error Then
            Return SetError(0, $VC_VER[$i], $sVCDir)
    Return SetError(1, "", "")
EndFunc   ;==>get_vc_install_dir

Dim $sVCDir = get_vc_install_dir()
If @error Then
    ConsoleWriteError("Cannot find any Visual Studio C++ installation." & @CRLF)
    Exit 1
    ConsoleWrite($sVCDir & @CRLF)
    Exit 0

Example batch file vcenvrun.cmd that uses compiled script VCInstallDir.exe:

FOR /F "usebackq delims==" %%i IN (`VCInstallDir.exe`) DO CALL "%%ivcvarsall.bat" x86
Edited by Edek

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this