获取程序运行的目录。例如D:\Program Files\QQ.exe,则可以获取D:\Program Files

string method1 = AppDomain.CurrentDomain.BaseDirectory;
//D:\Test\bin\Debug\

System.IO.FileInfo info = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
string method2 = info.Directory.FullName;
//D:\Test\bin\Debug

string method3 = Application.StartupPath;
//D:\Test\bin\Debug

注意上面的结果有少许差别:第一种最后还会有'\'

 

调取电脑的默认安装路径:

using Microsoft.Win32;

RegistryKey Key = Registry.LocalMachine;
RegistryKey ServiceIP = Key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion", false);
string strServiceIP = ServiceIP.GetValue("ProgramFilesDir").ToString();

 

相关文章:

  • 2022-12-23
  • 2021-12-23
  • 2021-10-21
  • 2022-02-16
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-10
  • 2021-08-04
相关资源
相似解决方案