[wix-users] Permission to Stop/Start a Service from a Custom Action on Button click

Ven H venh.123 at gmail.com
Wed May 30 04:07:12 PDT 2018

I have a Custom Action that is called on a button click. In this button
click, I have to restart the Sql Service on the local machine. After
building this msi, if I right click and install, it fails while trying to
Stop & Start the service using ServiceController class (throws an access
denied exception). I tried with the WMI approach also, but the same result.

 But if I open up a PowerShell or Console window as Administrator and
execute the msi using msiexec command, it works fine. I am already an
administrator in the machine. I am not able to understand why it doesn't
work in the first case, whereas it works in the second case, even though I
am admin. How can I ensure in my Custom Action code to behave like the
second case?

I tried with and without Impersonate attributes on the Custom Action, but
no luck. Since it is called on button click, I am not able to make the CA
deferred and hence it is immediate. In my CA code, when I check the current
user using Environment.GetEnvironmentVariable("USERNAME") and also using
System.Security.Principal.WindowsIdentity.GetCurrent(), it shows the same
in both the cases. I am a little confused. Can anyone please help me?

More information about the wix-users mailing list