2

Just typing notepad in CMD is enough to open it. So is executing Process.Start("notepad"); .

How do I get my application to be executable from anywhere without having to specify the complete path?

ispiro
  • 23,513
  • 30
  • 116
  • 236

2 Answers2

11

Add the current directory to the PATH environment variable. Preferably the PATH environment variable of your profile, not the system profile whenever possible

AcidJunkie
  • 1,700
  • 15
  • 20
0

notepad works because its folder is in the PATH variable. You can get and set it with methods in the Environment class.

var path = Environment.GetEnvironmentVariable("PATH",
                         EnvironmentVariableTarget.Machine);
path += @";\my\path";
Environment.SetEnvironmentVariable("PATH", path,
                         EnvironmentVariableTarget.Machine);

(note that you'd only want to do this once, and should probably check that the path isn't already in PATH before adding it)

Tim S.
  • 52,076
  • 7
  • 84
  • 114