3

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. ) 
Bali C
  • 30,582
  • 35
  • 123
  • 152
dushyantp
  • 4,398
  • 7
  • 37
  • 59
  • What do you want to know? The version number or the version name? i.e 10 or express/pro etc. – Bali C Dec 14 '12 at 14:51
  • either of them or both will do. – dushyantp Dec 14 '12 at 14:56
  • Thanks for your response, just for future reference, put any updates into your question with a clear title (see my edit) rather than edit the solution, so it makes more sense. Nice to see you got `reg query` working though. – Bali C Dec 14 '12 at 17:06

1 Answers1

4
@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.

Bali C
  • 30,582
  • 35
  • 123
  • 152
  • 1
    @Rob Thanks for notifying me on the edit, I have added the OP's response into their question so it is there for future readers. – Bali C Dec 14 '12 at 17:05