C# 获取程序运行目录

                string a = "BaseDirectory:" + AppDomain.CurrentDomain.BaseDirectory + "\r\n" +
                    "MainModule:" + Process.GetCurrentProcess().MainModule.FileName + "\r\n" +
                    "ApplicationBase:" + AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\r\n" +
                    "StartupPath:" + Application.StartupPath + "\r\n" +
                    "ExecutablePath:" + Application.ExecutablePath + "\r\n" +
                    "GetCurrentDirectory:" + Directory.GetCurrentDirectory();

  

原文地址:https://www.cnblogs.com/XuPengLB/p/9104957.html

时间: 2024-08-30 03:56:54

C# 获取程序运行目录的相关文章

Python获取程序运行目录和脚本目录

import os import sys #获取脚本所在目录 print os.path.split( os.path.realpath( sys.argv[0] ) )[0] #获取脚本运行目录 print os.getcwd() 在脚本所在目录运行: python test.py /home/Hadoop /home/hadoop 在其他目录运行:python hadoop/test.py /home/hadoop /home

[转] C# 获取程序运行目录

来自 莫等闲也,原文 // 获取程序的基目录.  System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName // 获取和设置当前目录(该进程从中启动的目录)的完全限定目录. System.Environment.CurrentDirectory // 获取应用程序的当前工作目录. System.IO.Di

C# 获取程序运行时路径

?  前言 开发中,很多时候都需要获取程序运行时路径,比如:反射.文件操作等..NET Framework 已经封装了这些功能,可以很方便的使用. 1.   可使用类 1.   System.AppDomain,程序集:mscorlib.dll. 2.   System.Environment,程序集:mscorlib.dll. 3.   System.IO.Directory,程序集:mscorlib.dll. 4.   System.Reflection.Assembly,程序集:mscor

WPF获取应用程序路径方法,获取程序运行路径方法

试了好多种方法,在WPF中获取工程的路径都没能解决掉,暂时用的绝对路径"D://WPF.....",但是发布的时候出现问题了,放到别的电脑上找不到路径,又开始了地毯式搜索,终于解决了,跟遇到此类问题的朋友分享下解决办法,如下: AppDomain.CurrentDomain.BaseDirectory +文件名即可,简单吧? //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称. string str5=Application.StartupPath; //可获得当前执行的

C#如何加载程序运行目录外的程序集 (转)

---恢复内容开始--- 尼玛,为了这个问题,纠结到差点吐出干血,赶紧记下来! 源地址:http://blog.csdn.net/dyllove98/article/details/9391325 我们的应用程序部署的时候,目录结构一般不会只有运行程序的目录这一个,我们可能在运行目录下建子目录,也可能使用System32目录,也可能使用其它第三方的程序集..Net程序集 首先会在GAC中搜索相应的版本,如果未找到则会应用程序配置文件中找(如果配置),最后到应用程序所在的路径搜索. 如何可以将程序

unicode string和ansi string的转换函数及获取程序运行路径的代码

#pragma once#include <string> namespace stds { class tool { public: std::string ws2s(const std::wstring& ws) { std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C"; setlocale(LC_ALL, "chs"); const wchar_t* _Sou

C# 获取程序安装目录

在网页启动本地程序需要将命令写入注册表,在网页调用命令即可. 首先将注册信息创建一个注册表文件 .reg 格式,以页面启动 notepad++ 程序为例 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Webshell] [HKEY_CLASSES_ROOT\Webshell\DefaultIcon] [HKEY_CLASSES_ROOT\Webshell\shell] [HKEY_CLASSES_ROOT\Webshell\she

C#获取当前程序运行目录大全

Winform获取应用程序的当前路径的方法集合,具体如下,值得收藏 //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Assembly.Location; result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名) //获取新的Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名). string str = System.Diagnostics.Process.Get

python日志功能实现-自动获取程序运行时信息

通过python的inspect模块,我们可以获取程序的运行时栈.一个python的运行时栈是一个六元组:(frame对象, 文件名, 当前行号, 函数名, 保存相关源代码行的列表, 当前行在源代码列表中的位置). 栈中第一个元素代表当前执行的位置信息,最后一个表示最外层的执行信息. 如: 1 import inspect 2 3 class Foo: 4 def __init__(self): 5 pass 6 def say(self): 7 print inspect.stack()[1]