wal
wal

Reputation: 17729

run wix batch script as elevated/admin

I have written a WIX Installer using wixsharp that wraps a legacy installation procedure that used a batch file. When running the MSI as an non-admin I do get prompted to elevate (the UAC dialog) however the batch script is run as a non-admin

var project = new Project(string.Format("App");
project.Actions = new[] { new PathFileAction(@"C:\build\build_script.bat", args[1], @"C:\build\", Return.check, When.After, Step.InstallExecute, Condition.NOT_Installed, Sequence.InstallExecuteSequence) };
project.UI = WUI.WixUI_InstallDir;

One way around this is to start a command prompt as Administrator and run the MSI using msiexec - this works but is very clunky.

How can I make my PathFileAction run as Administrator?

Upvotes: 1

Views: 2625

Answers (2)

wal
wal

Reputation: 17729

I used this answer which is based on pure WIX - you need to add Execute='deferred' Impersonate='no' to the output xml so in wixsharp this is possible via Attributes...

var publishAction = new PathFileAction(@"C:\build\build_script.bat"...
publishAction.Attributes = new Dictionary<string, string>() 
{ 
    {"Execute", "deferred"}, 
    {"Impersonate", "no"} 
};

UPDATE: this will run the script as NT AUTHORITY\SYSTEM - if you want to run it as yourself (with elevated permissions) it appears this is not possible

Upvotes: 1

Christopher Painter
Christopher Painter

Reputation: 55581

I can't see the contents of build_script.bat but I assume it's installing the MSI silently. In this scenario UAC prompts aren't possible so the installer exits out with a no priv failure. You have to run the .bat file elevated or you have to "bless" the MSI by advertising (msiexec /jm) it first so that it'll self elevate in place from the non elevated user process.

Upvotes: 0

Related Questions