Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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.

@ECHO OFF
setlocal ENABLEEXTENSIONS
set KEY_NAME="SOFTWARE\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.
)
pause
share|improve this answer
    
Pretty sure this will have issues with spaces in install paths. stackoverflow.com/questions/22352793/… –  Craig Ringer Mar 12 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"
IF EXIST "%VS_LOC%" (
  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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.