Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Normally, the path is something like C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\.

From Visual Studio, one can use $(VCInstallDir)$ to get this path.

Q: But in a batch file, how to get this path?

I know one can use environment variable %VS100COMNTOOLS% in a batch file to get a similar path which is C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\.

The solution should not dependent on VS's version.

share|improve this question
up vote 3 down vote accepted

You could also use the registry to find the path to the Visual Studio install directory. You would have to add extra logic to handle different versions of VS that might be installed e.g 10.0 or 11.0.

; 32-bit system:
set KEY_NAME="SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VS"
; 64-bit system:
; set KEY_NAME="SOFTWARE\WOW6432Node\Microsoft\VisualStudio\9.0\Setup\VS"
set VALUE_NAME=ProductDir

FOR /F "usebackq skip=4 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
    set ValueValue=%%C

if defined ValueName (
    @echo Registry Value = %ValueValue%
) else (
    @echo %KEY_NAME%\%VALUE_NAME% not found.
share|improve this answer
Pretty sure this will have issues with spaces in install paths.… – Craig Ringer Mar 12 '14 at 23:16

It looks like VCInstallDir is an environment variable that is independent upon the version of Visual Studio.

echo %VCInstallDir%

That may be used in a batch file.

share|improve this answer

You can use a method similar to this one to detect the bit level of your particular command shell:

IF "%programfiles%"=="C:\Program Files" (
  ECHO This is a 64-bit cmd.exe shell.
) ELSE (
  ECHO This is a 32-bit cmd.exe shell.

Then, you can use that to figure out where Visual Studio is located. It really depends on what you are doing. You could also use a method like this:

SET "VS_LOC=%programfiles%\Visual Studio\bin\program.exe"
  ECHO Found a visual studio installation.
) ELSE (
  ECHO Could not find the visual studio install at %VS_LOC%.

I could go on and on about different ways of doing this. It is up to you depending on your situation.

share|improve this answer

Way late to this question, but i've found a simpler way to get the MSVC directory. The trick is to use %VS100COMNTOOLS% variable (or the version of your visual studio, here 100 is 10.0), which is guaranteed to exist even without calling the ..\VC\vcvarsall.bat batch file.

%VCInstallDir% variable falls to this as it's empty until vcvarsall.bat is called, but we can't call the file if we don't know the full path.

The %VS100COMNTOOLS% on the other hand exists and returns something like:

c:\Program Files\Microsoft Visual Visual Studio 10.0\Common7\Tools

Then, a simply cut-off of the last characters seems good:

echo "%VS100COMNTOOLS:~0,-14%VC\"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .