zoukankan      html  css  js  c++  java
  • c# 获取程序运行的根目录

     获取程序运行的目录。例如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();
  • 相关阅读:
    linux学习记录-----vsftpd服务安装配置
    PTA数据结构第一次作业
    第十一次作业
    第十次作业
    第九次作业
    第八次作业
    第七次作业
    第六次作业
    第五次作业
    第四次作业
  • 原文地址:https://www.cnblogs.com/icyJ/p/BaseDirectory.html
Copyright © 2011-2022 走看看