Sign in to follow this  
Followers 0
Edek

Visual Studio C++ installation directory

1 post in this topic

#1 ·  Posted (edited)

Hi.

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.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_Description=Reads Visual Studio C++ installation directory and prints it to StdOut.
#AutoIt3Wrapper_Res_Fileversion=0.1.0.7
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Run_Tidy=y
#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)
        EndIf
    Next
    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
Else
    ConsoleWrite($sVCDir & @CRLF)
    Exit 0
EndIf

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

@ECHO OFF
FOR /F "usebackq delims==" %%i IN (`VCInstallDir.exe`) DO CALL "%%ivcvarsall.bat" x86
CALL %*
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  
Followers 0