Skip to content

ElevatedManagedAction scheduled before RemoveExistingProducts alternative #1704

Answered by oleg-shilo
Trigve asked this question in Q&A
Discussion options

You must be logged in to vote

You can always run an elevated process from the unelevated CA:

[CustomAction]
public static ActionResult InvokeRemoveFiles(Session session)
{
    try
    {
        var startInfo = new ProcessStartInfo();

        startInfo.UseShellExecute = true;
        startInfo.FileName = "sc";
        startInfo.Arguments = "stop <ServiceName>";
        startInfo.Verb = "runas";

        Process.Start(startInfo);

        return ActionResult.Success;
    }
    catch(Exception e)
    {
        // handle the error here
    }
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Trigve
Comment options

@oleg-shilo
Comment options

Answer selected by Trigve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants