0

Can someone tell me how to properly install this program to run with admin privileges at startup on Windows 10 using WiX?

All the help I've seen via Google has been old ones saying to use the Startup folder. Now, although the Startup folder still seems to work, I don't think it's the preferred way to do it anymore.

I also need think the need to run as admin adds a wrinkle in the process.

Brad Y.
  • 161
  • 2
  • 14
  • Can you run it as a Windows Service? Maybe you have faced the [new restrictions on interactive services in Windows 10](https://www.coretechnologies.com/blog/windows-services/interactive-services-removed-windows-10/)? – Stein Åsmul May 06 '21 at 23:23
  • No. It needs a UI. I was able to get around the issue because my app runs in tandem with a service. So, I had the service do the work that requires the privs and had the non-service program talk to it using WCF. But I would think there should be a way to solve the problem. – Brad Y. May 07 '21 at 15:00
  • That's not getting around the problem, that is the proper design problem to solve the problem. – Christopher Painter May 07 '21 at 19:11
  • [I have this old answer on autostart](https://stackoverflow.com/a/56653034/129130). Adding just in case. – Stein Åsmul May 08 '21 at 01:19

2 Answers2

0

I can see few ways to do it:

  1. Set registry values using WIX: in this case you should add your app install path to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (x86) or HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run (x64). Problem is to get windows version. I guess it's possible to do by WIX (using few RegistryKey elements with condition) but I haven't tried.
  2. Use custom action to set registry values: the same as previous, but using C#. Also in this case it will be easy to determine windows version and add your app to the right key.
  3. Using custom actions and Task Scheduler. For example you can use this library to add task to run after startup.
  4. Run cmd using WIX to set up Task Scheduler (or via custom actions). The same as previous but without any libs.
ba-a-aton
  • 574
  • 1
  • 4
  • 14
0

A program requesting or requiring admin is a function of the EXE not WiX. The EXE should be manifested to request elevation.

MSFT has said it is not a best practice to have things in startup request admin. It's a horrible user experience.

The better approach is to do what you said you do in your comment. Have a component running as a service that the non-priv UI can communicate with.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Yes, we need better samples for that - services and apps working together? I don't like auto-start apps, but I have used them. The limit is elevation-prompt on boot - that is not advisable for any reason I think. Hans Passant has an answer on [forcing admin rights](https://stackoverflow.com/a/2818776/129130) and he warns about how UAC prompts wear out patience. – Stein Åsmul May 07 '21 at 19:25