Search code examples
windowsvisual-studiobatch-filevisual-studio-shell

Check Visual Studio Shell Installation from Batch


How can we check if and which version of Visual Studio Shell is installed, from a batch script?

I understand we can check the existence of file/folder say under

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

But I am looking for a more elegant and generic solution.

Any help?

Update to accepted answer:

Your answer is elegant and does the task. Since I was specifically checking for certain versions, I am using (after checking the link you provided):

@echo off
reg query "HKEY_CLASSES_ROOT\VisualStudio.DTE.10.0" >> nul 2>&1
if %ERRORLEVEL% NEQ 0 ( echo VS 2010 not installed ) else ( echo VS 2010 installed. )
reg query "HKEY_CLASSES_ROOT\VisualStudio.DTE.11.0" >> nul 2>&1
if %ERRORLEVEL% NEQ 0 ( echo VS 2012 not installed ) else ( echo VS 2012 installed. ) 

Solution

  • @echo off
    for /d %%a in ("%programfiles%\Microsoft Visual Studio*") do (
    for /f "tokens=3 delims=\" %%x in ("%%a") do echo %%x
    )
    pause >nul
    

    If you need more details there are plenty of reg keys you can query to get more info but that would be much harder to extract the data you wanted from the keys and values.

    Note: If you are running on x64 then you may need to add a check for %systemdrive%\Program Files (x86) depending on where VS is installed.