1

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?

wal
  • 17,409
  • 8
  • 74
  • 109

2 Answers2

1

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

Community
  • 1
  • 1
wal
  • 17,409
  • 8
  • 74
  • 109
  • publishAction has properties: Impersonate = false and Execute = Execute.deferred, so no need set from attributes. – VikciaR Dec 06 '16 at 08:40
0

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.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Chris I am trying `msiexec /jm` now however it already self elevates (presumably so it can be registered in add/remove programs?) – wal Feb 17 '15 at 23:12
  • Chris, after running `msiexec /jm App.Msi` in an admin command prompt I get this `you do not have sufficient priviledges to completes the re-advestiment of this product. Re-Advestisment requires initiation by a local system account calling the MsiAdvertiseScript API, such as through the Group Policy Software Deployment` – wal Feb 17 '15 at 23:20