2

I have a batch script like this (which i was able to derive from Open a file in Visual Studio at a specific line number ). Can any one tell me how to to pass the registry key of devenev i.e.( HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe), so that i dont have to give the path as D:\Progra....and that it can be run on any pc with visual studio installed. Thanks in advance.

@echo off

cd /d D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

devenv /Command "Edit.Goto 83" "E:\examples\A.cpp"

@echo off

2
  • Why not just add the path D:\Program Files\...\IDE to your path environment variable? Commented Mar 28, 2013 at 19:20
  • Possible duplicate of stackoverflow.com/questions/445167/… Commented Mar 28, 2013 at 19:42

3 Answers 3

3
for /f "tokens=3*" %%x in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe"') do set DEVENV="%%x %%y"
%DEVENV% /Command "Edit.Goto 83" "E:\examples.A.cpp"

One caveat - if you have more than one edition of VS installed, this will launch the version which was most recently installed.

More generically:

set REGKEY="HKLM\SOFTWARE\Wow6432Node\BI\Science\AB\exenamehere.exe"
set CPPFILE=C:\SomePathHere\foo.cpp

for /f "tokens=3*" %%x in ('reg query "%REGKEY%"') do set EXE="%%x %%y"
%EXE% /AnyOtherParamsHere "%CPPFILE%"

You could also accept a command line argument like so (ideally there would be error handling as well). %1 is the first argument, %2 would be the second, on up through 9. Taking more than 9 parameters is certainly possible, but is beyond the scope of this question.

set REGKEY="HKLM\SOFTWARE\Wow6432Node\BI\Science\AB\exenamehere.exe"
set FILENAME=%1

for /f "tokens=3*" %%x in ('reg query "%REGKEY%"') do set EXE="%%x %%y"
%EXE% /AnyOtherParamsHere %FILENAME%

If the path to your file has spaces in it, you'll need to quote them when you run this batch file (e.g., mybatch.cmd "C:\path with spaces\foo.cpp").

Also, don't forget to mark this as the answer if you've found it useful. :-)

Sign up to request clarification or add additional context in comments.

2 Comments

If the path was not "E\examples.A.cpp" and if it was another registry key as HKLM\SOFTWARE\Wow6432Node\BI\Science\AB...how can i pass this into the code u've provided.Thanks in advance.
hey..i just moved my cpp into an examples folder and placed it into D:\Program Files\VideoLAN\VLC...Now the reg key name (folder) is HKEY_LOCAL_MACHINE\SOFTWARE\VideoLAN\VLC and i want the value data of the value name InstallDir..so that i can append the path \examples.A.cpp to the value data (which is actually a path -D:\Program Files\VideoLAN\VLC )..so that i can pass the path as %2..The code would be something like %DEVENV% /Command "Edit.Goto %1" "D:\Program Files\VideoLAN\VLC\%2" but i dont want the path to be passed as D:\Pro...but the registry value of InstallDir.Thanks in advance
0
@ECHO OFF
SETLOCAL 
FOR /F "tokens=2*" %%A IN (
   'REG QUERY "HKLM\SSOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" /v devenv.exe'
) DO (set vs9dir=%%B)
ECHO %vs9dir%

should return your value - in theory. I can't verify as I don't have VS.

Comments

0

You can try this, it might work:

for /f "tokens=3*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe"^|find "<NO NAME>"') do set "key=%%j"
echo "%key%"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.