简体   繁体   English

c#Process.Start()方法如何自动知道文件的位置?

[英]c# How does Process.Start() method automatically know where files are located?

If I feed Process.Start(); 如果我喂Process.Start(); the parameters "Firefox" , Notepad or "cmd" it runs those programs like their location is built in, but with other programs I have to specify the program's directory for it to work. 参数"Firefox" ,“ Notepad"cmd"运行它们的程序就像内置其位置一样,但是对于其他程序,我必须指定程序的目录才能正常工作。

How does it automatically know where some programs located, and why only those programs and not others? 它如何自动知道某些程序位于何处,以及为什么只有这些程序而不是其他程序?

My code: 我的代码:

using System;
using System.Diagnostics;

namespace Testing
{
 public class MainClass
 {
   static void Main()
   {
      Process.Start("Firefox");    // Works
      Process.Start("Notepad");    // Works 
      Process.Start(@"C:\Users\user\Desktop\Steam");   // Works too
      Process.Start("Steam");      // This line gives me "The System cannot find the file specified"(run-time error)
    }
  }
}

I think it depends on Environment variables in Windows. 我认为这取决于Windows中的环境变量 or type PATH in cmd and observe paths, where *.exe files can be found automatically. 或在cmd中键入PATH并观察路径,可以自动找到* .exe文件。

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

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