简体   繁体   English

在Windows上从命令行轻松运行程序

[英]Running programs easily from a command line on Windows

Linux allows me to have a short system path by placing binaries in just a few locations. Linux通过将二进制文件放在几个位置来使我的系统路径很短。 I don't have to edit the path because I just installed a new application, and I don't have to hunt for applications I want to run. 我不必编辑路径,因为我刚刚安装了一个新应用程序,也不必寻找要运行的应用程序。 How can I, with PowerShell as the program I use to launch programs from, accomplish the same thing on Windows (Vista)? 使用PowerShell作为启动程序的程序,如何在Windows(Vista)上完成相同的任务?

Vista has a symlinks now via mklink. Vista现在通过mklink具有一个符号链接。 Perhaps you could setup a "c:/bin" folder and generate symlinks to point back to the original binaries. 也许您可以设置一个“ c:/ bin”文件夹并生成符号链接以指向原始二进制文件。 That is assuming that Vista's symlinks work similarly to the ones in Linux. 假设Vista的符号链接的工作方式与Linux中的符号链接类似。 Here's a short tutorial. 这是一个简短的教程。

Many programs create an app paths entry in the registry (HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths). 许多程序在注册表中创建应用程序路径条目(HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ App Paths)。 For those apps, you can start them like so: 对于这些应用,您可以这样启动它们:

PS> Start-Process <appname>
PS> Start-Process excel

If you don't have PowerShell V2, which provides Start-Process, you can use the PowerShell Community Extensions on V1. 如果没有提供启动过程的PowerShell V2,则可以在V1上使用PowerShell社区扩展

I kinda think I may be misunderstanding the question and this might be obvious but I hope it helps in case you didn't already know all this. 我有点以为我可能会误解这个问题,这也许很明显,但是如果您还不了解所有这一切,我希望它会有所帮助。

It sounds like adding a few directories to your path environmental variable might help. 听起来向路径环境变量添加一些目录可能会有所帮助。 From the command prompt you can view all environmental variables with the set command. 在命令提示符下,您可以使用set命令查看所有环境变量。 Then you can cut and paste your path and use set again to add to it. 然后,您可以剪切并粘贴路径,并再次使用set来添加它。 If you prefer the GUI route right click on My Computer -> Properties -> (in vista and 7 go to "Advanced System Settings" on the left in XP skip this step) -> Advanced Tab -> At the bottom there is an Environmental Variables button. 如果您喜欢GUI路由,请右键单击“我的电脑”->“属性”->(在Vista和7中,请转到XP左侧的“高级系统设置”,跳过此步骤)->“高级”选项卡->“底部”变量按钮。 When something is invoked form the command line windows checks in all the directories marked in the path first. 从表格中调用某些内容时,命令行窗口会首先检入路径中标记的所有目录。 After your app dir is in the path you can execute it without fully qualifying your path. 将应用程序目录放入路径后,无需完全限定路径即可执行它。

Hope that helped! 希望能有所帮助!

您始终可以添加.cmd文件作为别名。

我将应用程序安装到c:\\ bin中。

Using specifically Powershell you can just create aliases for programs you want to start. 专门使用Powershell,您可以为要启动的程序创建别名。 I doubt that this is actually less work than editing the PATH environment variable, though. 我怀疑这实际上比编辑PATH环境变量要少。

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

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