Armen Babakanian
Armen Babakanian

Reputation: 2305

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. Im not using any third party installer program just plain Visual Studio Setup project.

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. 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);
}

Upvotes: 0

Views: 1199

Answers (1)

Cosmin
Cosmin

Reputation: 21416

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.

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.

Upvotes: 2

Related Questions