2012-01-06 219 views
1

我需要在Windows启动时启动我的c#应用程序。我试图通过使用以下两个选项来添加与应用程序的exe路径的注册表项。启动位置与应用程序的位置不同。

System.Environment.CurrentDirectory 
Directory.GetCurrentDirectory() 

但是,在Windows启动时,该文件夹路径显示到system32目录下,而不是应用程序的目录。所以,依赖于当前目录的代码无法正常工作。如何解决这个要实现的程序文件夹?我搜查了相关的帖子,但没有获得解决方案。

谢谢


此代码的工作对我来说:

Directory.GetParent(System.Windows.Forms.Application.ExecutablePath) 

这给了应用程序所在目录。

非常感谢。

回答

1

您可以从当前装配的位置检索路径:

var assembly = System.Reflection.Assembly.GetEntryAssembly(); 
var curDir = System.IO.Path.GetDirectoryName(assembly.Location); 
0

您可以尝试

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

希望这会有所帮助!