简体   繁体   English

从桌面快捷方式运行命令提示符命令

[英]Run a Command Prompt command from Desktop Shortcut

是否可以创建一个桌面快捷方式,在按下时,将打开命令提示符并运行预定义的命令?

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. 您可以使用之后指定的命令创建cmd.exe的快捷方式。 Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands. 或者,您可以创建批处理脚本,如果您的目标只是使用可单击的方式来运行命令。

Steps: 脚步:

  1. Right click on some empty space in Explorer, and in the context menu go to "New/Shortcut". 在资源管理器中右键单击一些空白区域,然后在上下文菜单中转到“新建/快捷方式”。

  2. 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>是您要运行的命令

The solutions turned out to be very simple. 解决方案结果非常简单。

  1. Open text edit 打开文本编辑

  2. Write the command, save as .bat. 编写命令,另存为.bat。

  3. Double click the file created and the command automatically starts running in command-prompt. 双击创建的文件,命令将自动在命令提示符下开始运​​行。

在此输入图像描述

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. 然后快捷方式将是此批处理文件。

  1. Create new text file on desktop; 在桌面上创建新的文本文件;

  2. Enter desired commands in text file; 在文本文件中输入所需的命令;

  3. 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 您还可以在桌面上创建一个快捷方式,只需在创建快捷方式向导中的“键入项目位置”栏中键入命令即可运行特定命令甚至批处理文件

  1. Right click on Desktop. 右键单击桌面。
  2. Enter the command in "Type the Location of Item" bar. “键入项目的位置”栏中输入命令。
  3. Double click the shortcut to run the command. 双击快捷方式以运行该命令。

Found detailed Instructions here 在此处找到详细说明

  1. first goto that folder from where you to what to open command prompt where its desktop or some other location 首先转到那个文件夹,从哪里打开命令提示符到哪个桌面或其他位置
  2. make a text file in that location just write cmd -c and save name.bat 在该位置创建一个文本文件只需编写cmd -c并保存name.bat
  3. double click so your CMD path will be of that folder 双击,以便您的CMD路径将是该文件夹 在此输入图像描述

Using the Drag and Drop method 使用拖放方法

  1. From the windows search bar type in cmd to pull up the windows bar operation. 从windows搜索栏中键入cmd来拉起windows bar操作。
  2. When the command line option is shown, right click it and select Open File Location . 显示命令行选项时,右键单击它并选择“ Open File Location
  3. The file explorer opens and the shortcut link is highlighted in the folder. 将打开文件资源管理器,并在文件夹中突出显示快捷方式链接。 If it is not highlighted, then select it. 如果未突出显示,则选择它。
  4. Hold down the Control key and using the mouse drag the shortcut to the desktop. 按住Control键并使用鼠标将快捷方式拖到桌面上。 If you don't see 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键直到看到该消息。
  5. Drop the link on the desktop. 删除桌面上的链接。
  6. Change properties as needed. 根据需要更改属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM