[英]Running MSI uninstaller with elevated privilege
I have created a Window Setup Project, and added a few custom installer classes to the main apps, so to include it in the Custom Action section of the Setup Project. 我创建了一个Window Setup Project,并在主应用程序中添加了一些自定义安装程序类,因此将其包含在Setup Project的Custom Action部分中。 Im not using any third party installer program just plain Visual Studio Setup project. 我没有使用任何第三方安装程序只是简单的Visual Studio安装项目。
I have a custom installer class for my app and in the Uninstall function I have included a function to kill the process, and remove the extra files created in the program directory. 我有我的应用程序的自定义安装程序类,在卸载函数中,我已经包含了一个函数来终止进程,并删除在程序目录中创建的额外文件。 It work in windows XP but not in 7. So I'm assuming it has to do with UAC. 它适用于Windows XP但不适用于7.所以我假设它与UAC有关。 How can I force run an uninstaller with admin privilege? 如何强制运行具有管理员权限的卸载程序?
here my my code for the Uninstaller override: 这里是我的卸载程序覆盖代码:
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
try
{
KillProcess();
DeleteAppPathFolder();
}
catch (Exception) { }
}
private void KillProcess()
{
for (; ; )
{
Process[] procMain = Process.GetProcessesByName("TaskbarNotificator");
if (procMain.Length > 0)
{
procMain[0].Kill();
}
else
break;
}
}
private void DeleteAppPathFolder()
{
FileInfo fileInfo = new FileInfo
(System.Reflection.Assembly.GetExecutingAssembly().Location);
string sProgram = Path.Combine(fileInfo.DirectoryName, GLOBALS.APP_DIR_NAME);
if (Directory.Exists(sProgram))
Directory.Delete(sProgram, true);
}
To make a custom action run with full privileges you can make sure that it's scheduled as deferred with no impersonation. 要使用完全权限运行自定义操作,您可以确保将其计划为延迟而不进行模拟。 Basically, it must use the msidbCustomActionTypeInScript and msidbCustomActionTypeNoImpersonate flags inside the MSI. 基本上,它必须使用MSI中的msidbCustomActionTypeInScript和msidbCustomActionTypeNoImpersonate标志。
This is done differently for each setup authoring tool. 对于每个设置创作工具,这都是不同的。 If you cannot find a way to set it, please give us more details about what you are using to create your MSI. 如果您找不到设置方法,请向我们提供有关您用于创建MSI的更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.