0

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:

enter image description here

user3765372
  • 281
  • 1
  • 3
  • 14

2 Answers2

0
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));
bill
  • 711
  • 1
  • 8
  • 19
0

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.

user3613932
  • 1,219
  • 15
  • 16