windows 从桌面快捷方式运行命令提示符命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9738434/
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
Run a Command Prompt command from Desktop Shortcut
提问by Philip Kirkbride
Is it possible to create a desktop shortcut that, when pressed, will open command prompt and run a pre-defined command?
是否可以创建一个桌面快捷方式,按下该快捷方式将打开命令提示符并运行预定义的命令?
采纳答案by Philip Kirkbride
回答by Robin Hood
Create A Shortcut That Opens The Command Prompt & Runs A Command:
创建一个打开命令提示符并运行命令的快捷方式:
Yes! You can create a shortcut to cmd.exe with a command specified after it. Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands.
是的!您可以使用后面指定的命令创建 cmd.exe 的快捷方式。或者,您可以创建批处理脚本,如果您的目标只是以可点击的方式运行命令。
Steps:
脚步:
Right click on some empty space in Explorer, and in the context menu go to "New/Shortcut".
When prompted to enter a location put either:
右键单击资源管理器中的一些空白区域,然后在上下文菜单中转到“新建/快捷方式”。
当提示输入位置时,请输入:
"C:\Windows\System32\cmd.exe /k your-command
" This will run the command and keep (/k) the command prompt open after.
" C:\Windows\System32\cmd.exe /k your-command
" 这将运行命令并保持 ( /k) 命令提示符打开。
or
或者
"C:\Windows\System32\cmd.exe /c your-command
" This will run the command and the close (/c) the command prompt.
" C:\Windows\System32\cmd.exe /c your-command
" 这将运行命令并关闭 ( /c) 命令提示符。
Notes:
笔记:
Tested, and working on Windows 8 - Core X86-64 September 12 2014
If you want to have more than one command, place an "&" symbol in between them. For example: "
C:\Windows\System32\cmd.exe /k command1 & command2
".
测试并在 Windows 8 上运行 - Core X86-64 2014 年 9 月 12 日
如果您想拥有多个命令,请在它们之间放置一个“&”符号。例如:“
C:\Windows\System32\cmd.exe /k command1 & command2
”。
回答by Alex K.
Yes, make the shortcut's path
是的,制作快捷方式的路径
%comspec% /k <command>
where
在哪里
%comspec%
is the environment variable for cmd.exe's full path, equivalent toC:\Windows\System32\cmd.exe
on most (if not all) Windows installs/k
keeps the window open after the command has run, this may be replaced with/c
if you want the window to close once the command is finished running<command>
is the command you wish to run
%comspec%
是 cmd.exe 完整路径的环境变量,相当于C:\Windows\System32\cmd.exe
大多数(如果不是全部)Windows 安装/k
在命令运行后保持窗口打开,/c
如果您希望在命令运行完成后关闭窗口,则可以将其替换为<command>
是您要运行的命令
回答by user2373716
Create new text file on desktop;
Enter desired commands in text file;
Rename extension of text file from ".txt" --> ".bat"
在桌面上创建新的文本文件;
在文本文件中输入所需的命令;
从“.txt”重命名文本文件的扩展名-->“.bat”
回答by Dan
Yes. One option you have is to create a batch file containing the command
是的。您拥有的一种选择是创建一个包含命令的批处理文件
cmd -c {your command}
cmd -c {你的命令}
or
或者
cmd -k {your command}
cmd -k {你的命令}
The shortcut will then be to this batch file.
然后快捷方式将是该批处理文件。
回答by joef
This is an old post but I have issues with coming across posts that have some incorrect information/syntax...
这是一篇旧帖子,但我遇到一些信息/语法不正确的帖子时遇到问题...
If you wanted to do this with a shorcut icon you could just create a shortcut on your desktop for the cmd.exe application. Then append a /K {your command} to the shorcut path.
如果您想使用快捷方式图标执行此操作,您只需在桌面上为 cmd.exe 应用程序创建一个快捷方式即可。然后将 /K {your command} 附加到快捷路径。
So a default shorcut target path may look like "%windir%\system32\cmd.exe", just change it to %windir%\system32\cmd.exe /k {commands}
因此,默认的快捷目标路径可能类似于“%windir%\system32\cmd.exe”,只需将其更改为 %windir%\system32\cmd.exe /k {commands}
example: %windir%\system32\cmd.exe /k powercfg -lastwake
示例:%windir%\system32\cmd.exe /k powercfg -lastwake
In this case i would use /k (keep open) to display results.
在这种情况下,我将使用 /k(保持打开状态)来显示结果。
Arlen was right about the /k (keep open) and /c (close)
Arlen 关于 /k(保持打开)和 /c(关闭)是正确的
You can open a command prompt and type "cmd /?" to see your options.
您可以打开命令提示符并键入“cmd /?” 查看您的选项。
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
A batch file is kind of overkill for a single command prompt command...
批处理文件对于单个命令提示符命令来说有点矫枉过正......
Hope this helps someone else
希望这对其他人有帮助
回答by mayhem2k
I tried this, all it did was open a cmd prompt with "cmd -c (my command)" and didn't actually run it. see below.
我试过这个,它所做的只是用“cmd -c(我的命令)”打开一个cmd提示符,并没有实际运行它。见下文。
C:\windows\System32>cmd -c (powercfg /lastwake) Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\windows\System32>cmd -c (powercfg /lastwake) Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。版权所有。
C:\windows\System32>
C:\windows\System32>
***Update
I changed my .bat file to read "cmd /k (powercfg /lastwake)" and it worked.
You can also leave out the () and it works too.
***更新
我将我的 .bat 文件更改为“cmd /k (powercfg /lastwake)”并且它起作用了。您也可以省略 (),它也可以工作。
回答by Adiii
回答by Nitish Andola
You can also create a shortcut on desktop that can run a specific command or even a batch file by just typing the command in "Type the Location of Item"bar in create shortcut wizard
您还可以在桌面上创建一个快捷方式,该快捷方式可以运行特定命令甚至批处理文件,只需在创建快捷方式向导的“键入项目的位置”栏中键入命令
- Right click on Desktop.
- Enter the command in "Type the Location of Item"bar.
- Double click the shortcut to run the command.
- 右键单击桌面。
- 在“键入项目的位置”栏中输入命令 。
- 双击快捷方式运行命令。
回答by ΩmegaMan
Using the Drag and Drop method
使用拖放方法
- From the windows search bar type in
cmd
to pull up the windows bar operation. - When the command line option is shown, right click it and select
Open File Location
. - The file explorer opens and the shortcut link is highlighted in the folder. If it is not highlighted, then select it.
- Hold down the Controlkey and using the mouse drag the shortcut to the desktop. If you don't see
Copy to Desktop
while dragging and before dropping, then push down and hold the Controlkey until you see the message. - Drop the link on the desktop.
- Change properties as needed.
- 从windows搜索栏输入
cmd
拉起windows栏操作。 - 当显示命令行选项时,右键单击它并选择
Open File Location
。 - 文件资源管理器打开,快捷方式链接在文件夹中突出显示。如果它没有突出显示,则选择它。
- 按住Control键并使用鼠标将快捷方式拖到桌面。如果
Copy to Desktop
在拖动时和放下之前没有看到,请按下并按住该Control键,直到看到消息。 - 将链接放在桌面上。
- 根据需要更改属性。