简体   繁体   English

使用提升的权限运行MSI卸载程序

[英]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.

相关问题 有什么方法可以通过C#WPF应用程序中的非管理员用户更改系统DNS,而无需运行具有提升特权的应用程序? - Is there any ways to change the system DNS from a non admin user in C# WPF appl without running app with elevated privilege? 始终以提升的权限运行VS2015调试 - Always run VS2015 debug with elevated privilege 为什么安装程序在删除提升的特权要求后失败? - Why does installer fail after removing elevated privilege requirement? 在提升权限软件的对话框中显示共享文件夹 - show shared folders in dialog box in elevated privilege software 运行 windows 卸载程序时关闭应用程序 - Close application when running windows uninstaller 标记MSI,因此必须以提升的管理员帐户运行 - Mark MSI so it has to be run as elevated Administrator account 检测是否以管理员身份运行,是否具有提升的权限? - Detect if running as Administrator with or without elevated privileges? 如何将高权限代码从C#转换为VB.Net以用于SharePoint? - How do I convert Elevated Privilege code from C# to VB.Net for use with SharePoint? 使用UAC在用户登录时运行高级应用程序? - Running elevated applications on user login with UAC? 在启动和进程间通信方面提升运行 - Running Elevated on Startup & Inter Process Communication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM