在 Windows Vista 上以管理员身份运行时,如何在不同目录中启动快捷方式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/68307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:12:00  来源:igfitidea点击:

How can I make a shortcut start in a different directory when running it as an administrator on Windows Vista?

windowswindows-vistauacshortcutscmd

提问by Sam S

I have a shortcut on my desktop which opens a command prompt with many arguments that I need. I set the 'start in' field to d:\ and it works as expected (the prompt starts in d:). When I choose Advanced -> run as administrator and then open the shortcut, it starts in C:\Windows\System32, even though I have not changed the 'start in' field. How can I get it to start in d:\?

我的桌面上有一个快捷方式,可以打开一个带有许多我需要的参数的命令提示符。我将“开始于”字段设置为 d:\,它按预期工作(提示从 d: 开始)。当我选择 Advanced -> run as administrator 然后打开快捷方式时,它从 C:\Windows\System32 开始,即使我没有更改“开始于”字段。我怎样才能让它在 d:\ 中启动?

回答by Joseph Daigle

If you use the /k argument, you can add a single line to execute a change drive and change directory. For instance:

如果使用 /k 参数,则可以添加一行来执行更改驱动器和更改目录。例如:

C:\Windows\System32\cmd.exe /k "d: & cd d:\storage"

C:\Windows\System32\cmd.exe /k "d: & cd d:\storage"

Using &you can string together many commands on one line.

使用&您可以在一行中将许多命令串在一起。

Edit: You can also change drive with the cd command alone "cd /d d:\storage". Thanks to Adam Mitz for the comment.

编辑:您也可以单独使用 cd 命令更改驱动器"cd /d d:\storage"。感谢 Adam Mitz 的评论。