开发者

Creating a shortcut for runas /netonly and vsvarsall.bat . What are the quoting rules to use?

I am attempting to create a shortcut that will load the vcvarsall.bat (Visual Studio Command prompt) under a runas command. Specifically, I want a shortcut that starts in a specific folder; has the runas network credential set to a domain account; mains local account affinity; and has msbuild environment variables set correctly.

Background: We have team city build agents that are not on the domain. Occasionally, I need to troubleshoot them. This means running the build under the team city local account, getting from source using the domain account. I also have the same scenario when working from home - my home computer is not on the domain.

I can use runas.exe to get the credentials correct, but I don't get the msbuild environment variables.

%SystemRoot%\system32\runas.exe /netonly /user:domain\teamcityagent "%comspec% /k 

If I load the environment variables as per the shortcut and set the start in folder, I get the environment variables开发者_如何学运维 and working folder, but I have to enter my credentials each tfs command.

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

How can I combine these two into one shortcut? What are the command quoting rules that apply here? Can you concatenate commands in a shortcut? It would be coolest to do this without a batch file, but if I have to fall back on a batch file, I'll do that.


You can execute multiple separate commands using &&. Successive commands will only be executed if the previous one succeeds (i.e., errorlevel 0). If you want to force all commands to execute, just use a single &.

e.g., printing "foo" and "bar" then pause

%comspec% /c echo foo && echo bar && pause

However in your case, when using runas, you need to wrap the entire command and command arguments in double quotes. Any double quotes in the arguments need to be escaped by a backslash. Other backslashes should be interpreted correctly without needing escaping. To run as another user with the variables loaded printing a greeting, you can do the following:

%SystemRoot%\system32\runas.exe /netonly /user:domain\teamcityagent "%comspec% /k \"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat\" x86 && echo Hello %USERDOMAIN%\%USERNAME%"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜