[英]Run a Command Prompt command from Desktop Shortcut
是否可以创建一个桌面快捷方式,在按下时,将打开命令提示符并运行预定义的命令?
Yes! 是! You can create a shortcut to cmd.exe with a command specified after it. 您可以使用之后指定的命令创建cmd.exe的快捷方式。 Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands. 或者,您可以创建批处理脚本,如果您的目标只是使用可单击的方式来运行命令。
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 经过测试,并在Windows 8上工作 - Core X86-64 2014年9月12日
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
". 例如:“ C:\\Windows\\System32\\cmd.exe /k command1 & command2
”。
Yes, make the shortcut's path 是的,制作快捷方式的路径
%comspec% /k <command>
where 哪里
%comspec%
is the environment variable for cmd.exe's full path, equivalent to C:\\Windows\\System32\\cmd.exe
on most (if not all) Windows installs %comspec%
是cmd.exe完整路径的环境变量,相当于大多数(如果不是全部)Windows安装的C:\\Windows\\System32\\cmd.exe
/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 /k
在命令运行后保持窗口打开,如果要在命令运行完毕后关闭窗口,可以用/c
替换 <command>
is the command you wish to run <command>
是您要运行的命令 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. 然后快捷方式将是此批处理文件。
Create new text file on desktop; 在桌面上创建新的文本文件;
Enter desired commands in text file; 在文本文件中输入所需的命令;
Rename extension of text file from ".txt" --> ".bat" 从“.txt” - >“。bat”重命名文本文件的扩展名
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. 如果您想使用shorcut图标执行此操作,则可以在桌面上为cmd.exe应用程序创建快捷方式。 Then append a /K {your command} to the shorcut path. 然后将/ K {您的命令}附加到shorcut路径。
So a default shorcut target path may look like "%windir%\\system32\\cmd.exe", just change it to %windir%\\system32\\cmd.exe /k {commands} 因此,默认的shorcut目标路径可能看起来像“%windir%\\ system32 \\ cmd.exe”,只需将其更改为%windir%\\ system32 \\ cmd.exe / k {命令}
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 /?" 您可以打开命令提示符并键入“cmd /?” to see your options. 看看你的选择。
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 希望这有助于其他人
I tried this, all it did was open a cmd prompt with "cmd -c (my command)" and didn't actually run it. 我试过这个,它所做的就是用“cmd -c(我的命令)”打开一个cmd提示符并且实际上没有运行它。 see below. 见下文。
C:\\windows\\System32>cmd -c (powercfg /lastwake) Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. C:\\ windows \\ System32> cmd -c(powercfg / lastwake)Microsoft Windows [版本6.1.7601]版权所有(c)2009 Microsoft Corporation。 All rights reserved. 版权所有。
C:\\windows\\System32> C:\\ WINDOWS \\ System32下>
***Update ***更新
I changed my .bat file to read "cmd /k (powercfg /lastwake)" and it worked. 我将我的.bat文件更改为“cmd / k(powercfg / lastwake)”并且它有效。 You can also leave out the () and it works too. 你也可以省略(),它也可以。
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 您还可以在桌面上创建一个快捷方式,只需在创建快捷方式向导中的“键入项目位置”栏中键入命令即可运行特定命令甚至批处理文件
cmd -c
and save name.bat 在该位置创建一个文本文件只需编写cmd -c
并保存name.bat Using the Drag and Drop method 使用拖放方法
cmd
to pull up the windows bar operation. 从windows搜索栏中键入cmd
来拉起windows bar操作。 Open File Location
. 显示命令行选项时,右键单击它并选择“ Open File Location
。 Copy to Desktop
while dragging and before dropping, then push down and hold the Control key until you see the message. 如果在拖动时和放下之前没有看到“ Copy to Desktop
,请按住Control键直到看到该消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.