批处理文件:打开cmd,运行VS命令提示符,执行Makecert [英] Batch file: Open cmd, run VS Command Prompt, execute Makecert

查看:750
本文介绍了批处理文件:打开cmd,运行VS命令提示符,执行Makecert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在批处理文件中执行此操作:



1.打开cmd

2.通过cmd运行VS命令提示符

3.执行此命令

I need to do this in a batch file:

1. Open cmd
2. Run VS Command Prompt via cmd
3. Execute this command

"makecert -sv SignRoot.pvk -cy authority -r sha1 -a -n \"CN=Certificate\" -ss my -sr localmachine certificate.cer"





到目前为止,我已经完成了1 2,我的问题是进入#3。



这是我到目前为止所拥有的。



So far, I''ve done 1 and 2, my problem is getting into #3.

Here''s what I have so far.

start  cmd.exe /k "%comspec% /c  "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86"

推荐答案

我认为您要做的是打开一个命令窗口,并定义VS2010编译器环境,并在其中执行''makecert''。



而不是上面描述的内容,请执行以下操作:



点击开始 - > (所有节目) - > Microsoft Visual Studio 2010 - > Visual Studio工具 - > Visual Studio命令提示符(2010)



这将打开您想要的命令窗口。然后你可以输入''makecert''东西......
I think what you want to do is open a command window with the VS2010 compiler environment defined and execute the ''makecert'' stuff in it.

Rather than what you have described above, do this:

Click Start -> (all programs) -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt (2010)

This will open the command window you want. You can then enter the ''makecert'' stuff...


删除CMD.EXE部分,这是完全多余的。







感谢您的澄清。现在,不仅摆脱CMD.EXE意味着删除冗余工具,它也很关键。



Visual Studio提示是互动的,你不要想。它确实是通过%comspec%执行的,这已经是相同的CMD.EXE。你也需要摆脱它。那么Visual Studio Prompt的作用是什么?它只是按照一些实用程序正常工作的方式设置环境和工作目录。跛脚的东西,按他们的方式;我真的希望微软能够在将来摆脱这种方法。



所以,你只需要执行环境,然后执行你的命令行,没有CMD.EXE。方法如下:



转到主菜单并将Visual Studio命令提示符.lnk文件复制到某个目录中。打开其属性窗口(Alt + Enter)并复制两个字符串:Target字段中的批处理文件的全名和Start in中的工作目录。结果取决于您安装Visual Studio的方式。它将类似于:

Remove CMD.EXE part, it''s totally redundant.



Thank you for clarification. Now, not only getting rid of CMD.EXE mean removing redundant tool, it''s also critical.

Visual Studio Prompt is interactive, something you don''t want. It really is executed via %comspec% which is the same vary CMD.EXE already. You need to get rid of it, too. So what Visual Studio Prompt does? It simply sets up environment and working directory the way some utilities work correctly. Lame thing, by they way; I really hope Microsoft will be able to get rid of such approach in future.

So, all you need is to carry out the environment and then execute your command line, without CMD.EXE. Here is how:

Go to main menu and copy the Visual Studio Command Prompt .lnk file in some directory. Open its properties window (Alt+Enter) and copy two strings: a full name of the batch file from the field "Target" and a working directory from "Start in". The result depends on how you installed Visual Studio. It will be something like:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\





你真的想统一然后写只是目录和文件名:



You really want to unify then so write just the directory and file name:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\
vcvarsall.bat





根据你的内容修改这些字符串。



现在,您可以在批处理文件中执行以下操作:



Modify these strings according to what you have.

Now, here is what you can do in your batch file:

set workingDir=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\
set vs=vcvarsall.bat

cd %workingDir%
call %vs%

:: your commands go here, such as:
makecert -sv SignRoot.pvk -cy authority -r sha1 -a -n \"CN=Certificate\" -ss my -sr localmachine certificate.cer





我''我们展示了这些 def 部分,以帮助您统一其他命令和Visual Studio安装的批处理。您还可以将参数传递给批处理文件以抽象我们的文件名,例如:



I''ve shown these def parts to help you to unify the batch for other commands and Visual Studio installations. You can also pass parameters to batch files to abstract our file names, for example:

:: ...
makecert -sv %1 -cy authority -r sha1 -a -n \"CN=Certificate\" -ss my -sr localmachine %2





这样,您可以用文件调用批处理文件参数。这可能很重要,因为您不想将文件复制到Visual Studio Common Prompt的工作目录中,因此您需要复制其完整路径名:





This way, you can call your batch file with file parameters. This can be important, because you don''t want to copy your files to working directory of Visual Studio Common Prompt, so you would need to copy their full path names:

yourBatchFile.bat /path/to/SignRoot.pvk /path/to/certificate.cer





例如,您可以将此行放在其他批处理文件中。小心包含空格的路径名;他们应该进来;或者避免它们。



-SA


似乎你想添加VS2010环境到当前命令窗口。以下是如何操作...转到解决方案1中描述的Visual Studio命令提示符(2010)菜单,但不是单击它(即左键单击),右键单击,选择属性。在目标编辑控件中,您应该看到如下内容:



It seems that you want to add the VS2010 environment to the current command window. Here is how to do it... Go to the "Visual Studio Command Prompt (2010)" menu described in Solution 1, but instead of clicking on it (ie. left click), do a right click, select properties. In the ''Target'' edit control, you should see something like:

%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86





或类似的东西。在批处理文件中,您希望单独添加该行,而不使用%comspec%/ k。接下来是你的makecert系列。



这是你的批处理文件应该包含的内容(引号固定):





or something similar. In your batch file, you want to add that line by itself, without the "%comspec% /k". Following this would be your makecert line.

Here is what your batch file should contain (with quotes fixed up):

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
makecert -sv SignRoot.pvk -cy authority -r sha1 -a -n "CN=Certificate" -ss my -sr localmachine certificate.cer





[makecert line is is包裹在这里;它应该在您的批处理文件中的一行。]



[the makecert line is wrapping here; it should be on one line in your batch file.]


这篇关于批处理文件:打开cmd,运行VS命令提示符,执行Makecert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆