我怎样才能得到使用批处理脚本注册表项的价值? [英] How can I get the value of a registry key using a batch script?
问题描述
我有这样一个批处理脚本(这我能够从<一个派生href=\"http://stackoverflow.com/questions/350323/open-a-file-in-visual-studio-at-a-specific-line-number\">Open在一个特定的行号在Visual Studio中的文件)。任何一个可以告诉我如何通过devenev即(HKEY_LOCAL_MACHINE \\ SOFTWARE \\微软\\的Windows \\ CurrentVersion \\应用程序路径\\ devenv.exe的)注册表项,使我没有给路径D:\\ PROGRA .. ..和它可以在安装有Visual Studio的任何一台PC上运行。提前致谢。
关闭@echo
CD / D D:\\ Program Files文件\\微软的Visual Studio 9.0 \\ Common7 \\ IDE
devenv的/命令Edit.Goto 83E:\\ EXAMPLES \\ A.cpp
关闭@echo
FOR / F令牌= 3 *%%倍In('章查询HKLM \\ SOFTWARE \\微软\\的Windows \\ CurrentVersion \\应用程序路径\\程序devenv.exe')不设置devenv的=%%点¯x%% Y
%devenv的%/命令Edit.Goto 83E:\\ examples.A.cpp
一个警告 - 如果你已经安装了VS的多个版本,这将启动这是最近安装的版本
更一般:
设置REGKEY =HKLM \\ SOFTWARE \\ Wow6432Node \\ BI \\科学\\ AB \\ exenamehere.exe
设置CPPFILE = C:\\ SomePathHere \\ Foo.cpp中FOR / F令牌= 3 *%%倍In('章查询%REGKEY%)并设置EXE =%%点¯x%% Y
%EXE%/ AnyOtherParamsHere%CPPFILE%
您还可以接受命令行参数,像这样(理想情况下会有错误处理以及)。 %1是第一个参数,%2将是第二次,最多到9时间超过9个参数当然是可能的,但超出了这个问题的范围。
设置REGKEY =HKLM \\ SOFTWARE \\ Wow6432Node \\ BI \\科学\\ AB \\ exenamehere.exe
将filename设置=%1FOR / F令牌= 3 *%%倍In('章查询%REGKEY%)并设置EXE =%%点¯x%% Y
%EXE%/ AnyOtherParamsHere%FILENAME%
如果路径到您的文件中有空格,你需要说出来了,当你运行这个批处理文件(例如, mybatch.cmdC:用空格\\路径\\ Foo.cpp中
)。
另外,不要忘记纪念这个作为回答如果您发现它有用。 : - )
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
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. :-)
这篇关于我怎样才能得到使用批处理脚本注册表项的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!