“注册”一个 .exe,以便您可以从 Windows 中的任何命令行运行它

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4822400/
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-09 08:01:08  来源:igfitidea点击:

"Register" an .exe so you can run it from any command line in Windows

windows

提问by HK1

How can you make a .exe file accessible from any location in the Windows command window? Is there some registry entry that has to be entered?

如何使 .exe 文件可从 Windows 命令窗口中的任何位置访问?是否有一些必须输入的注册表项?

采纳答案by ChrisF

You need to make sure that the exe is in a folder that's on the PATHenvironment variable.

您需要确保 exe 位于PATH环境变量上的文件夹中。

You can do this by either installing it into a folder that's already on the PATHor by adding your folder to the PATH.

您可以通过将其安装到上已有的文件夹这样做PATH或通过添加文件夹到PATH

You can have your installer do this - but you will need to restart the machine to make sure it gets picked up.

您可以让安装程序执行此操作 - 但您需要重新启动机器以确保它被启动。

回答by Andreas Rejbrand

You can add the following registry key:

您可以添加以下注册表

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myexe.exe

In this key, add the default string value containing the path to the exe file.

在此键中,添加包含 exe 文件路径的默认字符串值。

回答by darioo

You have to put your .exefile's path into enviroment variable path. Go to "My computer -> properties -> advanced -> environment variables -> Path" and edit path by adding .exe's directory into path.

您必须将.exe文件的路径放入环境变量路径中。转到“我的电脑 -> 属性 -> 高级 -> 环境变量 -> 路径”并通过将.exe的目录添加到路径中来编辑路径。

Another solution I personally prefer is using RapidEEfor a smoother variable editing.

我个人更喜欢的另一个解决方案是使用RapidEE进行更流畅的变量编辑。

回答by AmiNadimi

Windows 10, 8.1, 8

视窗 10、8.1、8

Open start menu,

打开开始菜单,

  1. Type Edit environment variables
  2. Open the option Edit the system environment variables
  3. Click Environment variables...button
  4. There you see two boxes, in System Variablesbox find pathvariable
  5. Click Edit
  6. a window pops up, click New
  7. Type the Directorypath of your .exeor batchfile ( Directorymeans exclude the file name from path)
  8. Click Okon all open windows and restart your systemrestart the command prompt.
  1. 类型 Edit environment variables
  2. 打开选项 Edit the system environment variables
  3. 单击Environment variables...按钮
  4. 在那里你看到两个框,在System Variables框中找到path变量
  5. 点击 Edit
  6. 弹出一个窗口,点击 New
  7. 键入您的或文件的目录路径(目录表示从路径中排除文件名).exebatch
  8. 单击Ok所有打开的窗口并重新启动系统重新启动命令提示符

回答by Ben Voigt

Rather than putting the executable into a directory on the path, you should create a batch file in a directory on the path that launches the program. This way you don't separate the executable from its supporting files, and you don't add other stuff in the same directory to the path unintentionally.

您应该在启动程序的路径上的目录中创建一个批处理文件,而不是将可执行文件放入路径上的目录中。这样您就不会将可执行文件与其支持文件分开,也不会无意中将同一目录中的其他内容添加到路径中。

Such batch file can look like this:

这样的批处理文件可能如下所示:

@echo off
start "" "C:\Program Files (x86)\Software\software.exe" %*

回答by Benja

it's amazing there's no simple solution for such a simple task on windows, I created this little cmd script that you can use to define aliases on windows (instructions are at the file header itself):

令人惊讶的是,对于 Windows 上这样一个简单的任务没有简单的解决方案,我创建了这个小 cmd 脚本,您可以使用它在 Windows 上定义别名(说明位于文件头本身):

https://gist.github.com/benjamine/5992592

https://gist.github.com/benjamine/5992592

this is pretty much the same approach used by tools like NPM or ruby gems to register global commands.

这与 NPM 或 ruby​​ gems 等工具用于注册全局命令的方法几乎相同。

回答by Bevan

Let's say my exe is C:\Program Files\AzCopy\azcopy.exe

假设我的 exe 是 C:\Program Files\AzCopy\azcopy.exe

Command/CMD/Batch

命令/CMD/批处理

SET "PATH=C:\Program Files\AzCopy;%PATH%"

PowerShell

电源外壳

$env:path = $env:path + ";C:\Program Files\AzCopy"

I can now simply type and use azcopyfrom any location from any shell inc command prompt, powershell, git bash etc

我现在可以azcopy从任何 shell inc 命令提示符、powershell、git bash 等任何位置简单地键入和使用

回答by JoePC

You may also permanently (after reboots) add to the Pathvariable this way:

您还可以通过这种方式永久(重新启动后)添加到Path变量:

Right click My Computer-> Click Properties-> Click Advanced system settings-> Click Environment Variables

右击我的电脑->点击属性->点击高级系统设置->点击环境变量

Reference: Change System/User Variables

参考:更改系统/用户变量

回答by Anders

  • If you want to be able to run it inside cmd.exe or batch files you need to add the directory the .exe is in to the %path% variable (System or User)
  • If you want to be able to run it in the Run dialog (Win+R) or any application that calls ShellExecute, adding your exe to the app paths keyis enough (This is less error prone during install/uninstall and also does not clutter up the path variable)
  • 如果您希望能够在 cmd.exe 或批处理文件中运行它,您需要将 .exe 所在的目录添加到 %path% 变量(System 或 User
  • 如果您希望能够在“运行”对话框 (Win+R) 或任何调用ShellExecute 的应用程序中运行它,将您的 exe 添加到应用程序路径键就足够了(这在安装/卸载过程中不易出错,也不会混乱向上路径变量)

回答by Teson

Put it in the c:\windows directory or add your directory to the "path" in the environment-settings (windows-break - tab advanced)

将其放在 c:\windows 目录中或将您的目录添加到环境设置中的“路径”(windows-break - tab advanced)

regards, //t

问候,//t