C# 启动位置与应用程序不同';它的位置。

C# 启动位置与应用程序不同';它的位置。,c#,C#,我需要在windows启动时启动我的c#应用程序。我尝试使用以下两个选项添加注册表项和应用程序的exe路径 System.Environment.CurrentDirectory Directory.GetCurrentDirectory() 但是,当windows启动时,文件夹路径显示为system32目录,而不是应用程序的目录。因此,依赖于当前目录的代码无法正常工作。如何解决这个问题来实现到程序文件夹??我已经搜索了相关帖子,但没有找到解决方案 谢谢, 此代码适用于我: Director

我需要在windows启动时启动我的c#应用程序。我尝试使用以下两个选项添加注册表项和应用程序的exe路径

System.Environment.CurrentDirectory
Directory.GetCurrentDirectory()
但是,当windows启动时,文件夹路径显示为system32目录,而不是应用程序的目录。因此,依赖于当前目录的代码无法正常工作。如何解决这个问题来实现到程序文件夹??我已经搜索了相关帖子,但没有找到解决方案

谢谢,


此代码适用于我:

Directory.GetParent(System.Windows.Forms.Application.ExecutablePath)
这将给出应用程序所在的目录


非常感谢。

我认为您需要使用此处的exe路径,而不是当前目录。查看,然后查看


您可以从当前程序集的位置检索路径:

var assembly = System.Reflection.Assembly.GetEntryAssembly();
var curDir = System.IO.Path.GetDirectoryName(assembly.Location);
你可以试试

System.Reflection.Assembly.GetExecutingAssembly().Location
希望这有帮助

System.Reflection.Assembly.GetExecutingAssembly().Location
System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);