简体   繁体   中英

Service vs. Process

If you want UAC elevated applications to run on windows startup, you need a service. But service applications have a lack of specific features such as creating MessageBoxes or executing other files. The question is: How do I create a startup application with UAC elevation AND the ability to use a GUI and Process.Start() ?

I've had this problem too. As IDWMaster mentioned, the solution is to use the Windows Task Scheduler. Don't think that this is a cheap option - I'd argue that it's better than a service. Quite a lot of softwares do use the Windows Task Scheduler to run administrative tasks. Why? Services, as you well know, aren't able to interact with the desktop so well - if you created a global keyboard hook in a service, for example, it won't capture keys. Why not normal registry startup keys? Because, as you also well know, programs requiring administrative privileges cannot autostart as an administrator using the registry startup keys. Using the Windows Task Scheduler solves all these problems.

Here's an excellent library that makes it an joy to interface with the Windows Task Scheduler in C#: http://taskscheduler.codeplex.com/

您可以使用NSSM创建存根服务以启动任何应用程序。

You can use Task Scheduler, and when setting up new task, on General Tab you can select user, including administrator, as well "run with highest privileges". On Trigger tab select "On Startup".

使用任务计划程序可以计划您的任务在用户交互式登录时运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM