2013-06-26 112 views
0

我正在使用Visual Studio 2010,.NET4 C#,我的解决方案有一个安装项目。如何从安装项目获取安装路径

正如您可能知道的,程序的安装路径可以在File System Editor(DefaultLocation属性)中的应用程序文件夹的属性中找到。

如何在代码中访问此字符串?

我的目标:我有一个安装程序类,它定义了安装后要完成的操作。我想采取的路径,并将其作为启动程序添加到注册表中。

+0

您打算询问用户是否可以将程序添加到启动列表中,对吗? – mcmonkey4eva

+0

不,我只是简单地添加它。 (这当然不是用于任何商业用途,所以没有真正的用户会被这个烦恼) –

回答

0

如果你想在安装文件夹中,那么这段代码应该工作:

//getting the full path including the filename 
string assemblyPath = Context.Parameters["assemblyPath"]; 
//removing the filename from the path 
int i = assemblyPath.Length-1; 
while (assemblyPath[i] != '\\') --i; 
string path = assemblyPath.Substring(0, i); 

,如果你想的完整路径,包括它存储在这里的文件名:

Context.Parameters["assemblyPath"]