卸载前获取应用程序的安装路径 [英] get the installation path of the application before uninstall
本文介绍了卸载前获取应用程序的安装路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
卸载之前如何获取应用程序的安装路径?我的意思是用户选择卸载应用程序的时间.
我已经创建了一个安装程序类,并在BeforeUninstall事件中使用以下代码来查找应用程序路径,但它在Windows驱动器(C:\ Windows \ ...)中返回错误的路径:
Hi all,
How can i get the installation path of my application before uninstall it? I mean the time that the user select to uninstall the application.
I have create an Installer Class and use the following code in BeforeUninstall event to find application path but it returns a wrong path in Windows drive(C:\Windows\...):
using Microsoft.Win32;
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Installer\Assemblies");
string regfilepath="";
if (key!=null) // Make sure there are Assemblies
{
foreach(string Keyname in key.GetSubKeyNames())
{
if (Keyname.IndexOf("YOUR_EXE_FILE.EXE")>0)
{
regfilepath=Keyname;
break;
}
}
}
string fullpath="";
for (int a=0;a<regfilepath.Length;a++)
{
if (regfilepath.IndexOf("|",a,1)>0)
fullpath+="\\";
else
fullpath+=regfilepath.Substring(a,1);
}
推荐答案
您可以在CustomActionData属性中传递"[TARGETDIR]",然后在代码中返回[TARGETDIR].
请看下面提供的链接.它将帮助您
http://msdn.microsoft.com/en-us/library/2w2fhwzz.aspx [ ^ ]
You can pass "[TARGETDIR]" in your CustomActionData property, then back in your code you can get the [TARGETDIR].
Just have look at below provided link. It will help you
http://msdn.microsoft.com/en-us/library/2w2fhwzz.aspx[^]
这篇关于卸载前获取应用程序的安装路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文