C# 程序运行目录,软件开机自启目录

            string exeDir = Application.ExecutablePath;//
            //string exeDir1 = System.IO.Directory.GetCurrentDirectory();
            string exeDir2 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string exeDir3 = System.AppDomain.CurrentDomain.BaseDirectory;//
            //string exeDir4 = System.Environment.CurrentDirectory;
            string exeDir5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string exeDir6 = System.Windows.Forms.Application.StartupPath;
            string exeDir7 = System.Windows.Forms.Application.ExecutablePath;//

其中注释的两行,在正常情况下运行时可以获取运行的目录的,但如果是软件开机自启动,获取的目录将不是软件运行目录,而是win64目录。

以下为没有注释的代码输出结果。

D:\Program Files\shutdown\Shutdown.exe
D:\Program Files\shutdown\Shutdown.exe
D:\Program Files\shutdown\
D:\Program Files\shutdown\
D:\Program Files\shutdown
D:\Program Files\shutdown\Shutdown.exe


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值