简体   繁体   English

在cmd.exe中将cmd文件名作为命令

[英]cmd filename as command in cmd.exe

I am probably missing some lingo to find the answer to a question which I believe has probably been posted already, hence my apologies beforehand. 我可能会缺少一些行话来找到我认为已经发布的问题的答案,因此我事先表示歉意。

I wrote a cmd script (myCmdFileName.cmd) that changes some IP configurations using netsh. 我编写了一个cmd脚本(myCmdFileName.cmd),该脚本使用netsh更改了一些IP配置。 To run it from cmd, I have to be in the same folder of the script and write in the console myCmdFileName.cmd. 要从cmd运行它,我必须在脚本的同一文件夹中,并在控制台myCmdFileName.cmd中写入。

As you know, netsh is a commandline application itself, as I would use it like: 如您所知,netsh本身就是一个命令行应用程序,就像我这样使用它:

netsh [-flags] [-configs]

What I would like to do is to have my cmd file be called just like as if it was an application like netsh, not worrying about whether I am in the file folder, so like this: 我想做的就是像调用netsh这样的应用程序一样调用我的cmd文件,而不用担心我是否位于文件夹中,所以像这样:

myCmdFileName [-flags] [-arguments]

How would I go about doing that in Windows cmd? 我将如何在Windows cmd中执行此操作?

Thanks a lot in advance! 在此先多谢!

为了从任何地方运行myCmdFileName ,它的父文件夹需要添加到 %PATH% ,或者可以移动它/在%PATH%中已经存在的文件夹中创建指向它的符号链接。

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

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