简体   繁体   中英

How can I make a c# command line application runnable in cmd.exe with installer?

I've written a C# command line application in visual studio. I would like to be able to run it as a command from the cmd.exe prompt application, after it installs. To do this I need to install the application in such a way that this would work

C:\Users\user3765372\Documents\>myAppName argument

a good example of an application with this functionality ins node.js eg:

C:\Users\user3765372\Documents\>nodejs server.js

Will cause node to run the server.js file. How can I make my program run like this for its commands?

Note my app isn't in Documents... its somewhere else.

I'm using this plugin to create the installer

Update:

This should work.... I think I may be making a mistake:

在此处输入图片说明

string yourAppPath = //whateverdirectoryyouwant;
string path = string.Format("{0};{1}", Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine),yourAppPath);
Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Machine);

Some users report using SetEnvironmentalVariable not taking effect. You can do this instead:

Process.Start("setx", string.Format("/M Path {0}",path));

If you want to create an installation (msi file) recommend using the Wix installer for creating an installation, and using the environment tag. More details here .

Alternately, you can use the Visual Studio Installer project but it will require a custom action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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