我已经在环境变量的路径中添加了notepad++.exe。

现在在命令提示符中,notepad++.exe filename.txt打开filename.txt。但我想用np filename。txt来打开文件。

我尝试使用DOSKEY np=notepad++。但它只是把一个已经打开的notepad++放在前面,而不打开文件。我怎样才能让它打开文件呢?

谢谢。


当前回答

因为你已经在你的路径中有notepad++.exe。在该文件夹中创建一个名为np的快捷方式,并将其指向notepad++.exe。

其他回答

这个解决方案并不合适,但在某些情况下是有用的。

首先创建一个文件夹,并将其添加到系统路径中。转到要为其创建别名的任何程序的可执行文件。右击并发送到桌面(创建快捷方式)。将快捷方式重命名为合适的别名。现在,选择快捷方式并放入文件夹中。

从运行提示符,您可以直接键入快捷方式的名称,您可以有程序为您打开。但在命令提示符中,需要追加.lnk并按enter键,程序将被打开。

此外,您还可以创建别名。在您的路径(例如C:\Windows)中使用命令

@echo %2 %3 %4 %5 %6 > %windir%\%1.cmd

一旦你这样做了,你可以这样做:

alias nameOfYourAlias commands to run 

然后你可以输入命令行

nameOfYourAlias 

这将执行

commands to run 

但对我来说,最好的方法是添加一个程序的路径。

setx PATH "%PATH%;%ProgramFiles%\Sublime Text 3" /M 

现在我崇高地奔跑

subl index.html

首先,您可以创建一个名为np的文件。cmd并将其放在PATH搜索列表中的文件夹中。 然后,编辑np。CMD文件如下所示:

@echo off
notepad++.exe

为了补充josh的回答,

您可以通过以下步骤使别名持久,

用DOSKEY命令创建一个.bat或.cmd文件。 运行regedit,进入HKEY_CURRENT_USER\Software\Microsoft\Command Processor 添加字符串值条目,名称为AutoRun和.bat/的完整路径。cmd文件。 例如,%USERPROFILE%\alias。在命令cmd中,用%USERPROFILE%替换路径的初始段对于多台机器之间的同步很有用。

这样,每次运行cmd时,都会加载别名。

对于Windows 10或Windows 11,请将该条目添加到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor中。

(对于Windows 11,还要注意默认情况下“终端应用程序”指向PowerShell。搜索“cmd”命令提示符。)

为了完整起见,这里有一个模板来说明可能有用的别名类型。

@echo off

:: Temporary system path at cmd startup

set PATH=%PATH%;"C:\Program Files\Sublime Text 2\"

:: Add to path by command

DOSKEY add_python26=set PATH=%PATH%;"C:\Python26\"
DOSKEY add_python33=set PATH=%PATH%;"C:\Python33\"

:: Commands

DOSKEY ls=dir /B $*
DOSKEY sublime=sublime_text $*  
    ::sublime_text.exe is name of the executable. By adding a temporary entry to system path, we don't have to write the whole directory anymore.
DOSKEY gsp="C:\Program Files (x86)\Sketchpad5\GSP505en.exe"
DOSKEY alias=notepad %USERPROFILE%\Dropbox\alias.cmd

:: Common directories

DOSKEY dropbox=cd "%USERPROFILE%\Dropbox\$*"
DOSKEY research=cd %USERPROFILE%\Dropbox\Research\

请注意,$*语法适用于目录字符串之后,也适用于带有参数的可执行文件之后。因此,在上面的示例中,用户定义的命令dropbox research指向与research相同的目录。 正如Rivenfall所指出的,包含一个允许方便地编辑别名的命令是一个好主意。cmd文件。参见上面的别名。如果您在一个cmd会话中,输入cmd重新启动cmd并重新加载别名。cmd文件。


当我在互联网上搜索这个问题的答案时,不知怎么的,讨论要么只集中在持久性上,要么只集中在DOSKEY的某些用法上。我希望在这里有人能从这两方面受益!


这里有一个.reg文件来帮助你安装别名。cmd。现在将它设置为上面建议的dropbox文件夹的示例。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="%USERPROFILE%\\alias.cmd"

对于单用户应用程序,上面的方法就可以了。不过,也有一些情况需要检查是否存在别名。CMD首先存在于注册表项中。参见下面的示例。

C:\Users\Public\init.CMD文件承载潜在的跨用户配置:

@ECHO OFF
REM Add other configurations as needed
IF EXIST "%USERPROFILE%\alias.cmd" ( CALL "%USERPROFILE%\alias.cmd" )

注册表项应相应更新为C:\Users\Public\init.CMD或使用.reg文件:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="C:\\Users\\Public\\init.cmd"

如果你想在每个目录/每个项目的基础上启用别名,试试下面的方法:

First, create a batch file that will look for a file named aliases in the current directory and initialize aliases from it, let’s call it make-aliases.cmd @echo off if not exist aliases goto:eof echo [Loading aliases...] for /f "tokens=1* delims=^=" %%i in (aliases) do ( echo %%i ^<^=^> %%j doskey %%i=%%j ) doskey aliases=doskey /macros echo -------------------- echo aliases ^=^> list all echo alt+F10 ^=^> clear all echo [Done] Then, create aliases wherever you need them using the following format: alias1 = command1 alias2 = command2 ... for example: b = nmake c = nmake clean r = nmake rebuild Then, add the location of make-aliases.cmd to your %PATH% variable to make it system-wide or just keep it in a known place. Make it start automatically with cmd. I would definitely advise against using HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun for this, because some development tools would trigger the autorun script multiple times per session. If you use ConEmu you could go another way and start the script from the startup task (Settings > Startup > Tasks), for example, I created an entry called {MSVC}: cmd.exe /k "vcvars64 && make-aliases", and then registered it in Explorer context menu via Settings > Integration> with Command: {MSVC} -cur_console:n, so that now I can right-click a folder and launch a VS developer prompt inside it with my aliases loaded automatically, if they happen to be in that folder. Without ConEmu, you may just want to create a shortcut to cmd.exe with the corresponding command or simply run make-aliases manually every time.

如果你碰巧忘记了你的别名,使用aliases宏,如果出现任何问题,只需按Alt+F10重置当前会话,这是cmd中的内置命令。