大家好,我的exe 放在C:\Test下面,然后有个程序在C:\Soft里面,这个程序里面有个按钮是启动我的exe,我怎么才能获得我exe所在的目录呢?目前我采用的方法:
System.Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath获取出来的都是C:\Soft,并不是我exe真正所在的目录?求指导
System.Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath获取出来的都是C:\Soft,并不是我exe真正所在的目录?求指导
解决方案 »
- 请问,这样的控件怎么移动
- c#调用Delphi动态库,pbitmapinfo 类型问题、bitmap处理(求高手指点)
- 使用list的一个问题
- 急,自定义datatable多行多列问题??
- 如何确定SqlException.Number指向的具体错误
- 分行打印问题,文字混排(中、英文、数字)打印在固定的宽度中,谢谢!!在线等,特别急急!有说明
- 在开发个小型进销存,不用服务器端直接客户端远程连接数据库行不行,后期会有什么问题吗?
- 上传文件与覆盖文件问题(ASP.NET),请支援!!!!
- 100分求vs.net 2003,msdn 2003,4月的
- 请mmkk()进来我要给分
- 通过SQLite存储Log4Net日志
- post数据
exepath = apppath + "\..\soft";
System.Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath获取出来的都是C:\Soft,并不是我exe真正所在的目录?
---------------------------
这两个是获取当前程序的所在路径,对了没有支持的EXE程序,他是不知道的,
建议你用配置文件指定EXE的路径
string str="";
str += "\r\n" + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
str += "\r\n" + System.Environment.CurrentDirectory;
str += "\r\n" + System.IO.Directory.GetCurrentDirectory();
str += "\r\n" + System.AppDomain.CurrentDomain.BaseDirectory;
str += "\r\n" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
str += "\r\n" + System.Windows.Forms.Application.StartupPath;
str += "\r\n" + System.Windows.Forms.Application.ExecutablePath;
Console.Write(str);
Console.ReadKey();
得到结果:
D:\1\bin\Debug\路径测试.vshost.exe
D:\1\bin\Debug
D:\1\bin\Debug
D:\1\bin\Debug\
D:\1\bin\Debug\
D:\1\bin\Debug
D:\1\bin\Debug\路径测试.EXE
1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
获取模块的完整路径。
2. System.Environment.CurrentDirectory
获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
3. System.IO.Directory.GetCurrentDirectory()
获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:\www里,这个函数有可能返回C:\Documents and Settings\ZYB\,或者C:\Program Files\Adobe\,有时不一定返回什么东东,我也搞不懂了。
4. System.AppDomain.CurrentDomain.BaseDirectory
获取程序的基目录。
5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
获取和设置包括该应用程序的目录的名称。
6. System.Windows.Forms.Application.StartupPath
获取启动了应用程序的可执行文件的路径。效果和2、5一样。只是5返回的字符串后面多了一个"\"而已
7. System.Windows.Forms.Application.ExecutablePath
获取启动了应用程序的可执行文件的路径及文件名,效果有时和1一样。
不解释 你懂的