"Run as Administrator" for a single function in an app

Hi Windows folks,

I have a project that has 2 faces when run - a daemon manager (uses sc.exe) that must be executed with Administrator privileges and the rest which runs at normal user privilege level.

I would like to ONLY prompt the user for the admin privileges elevation on the daemon/service start and stop tasks while not prompting for UAC authorization for the rest. I started out just building the app for Administrator access, but that prevents normal access since we can’t interface with the user’s desktop if the whole app is running as Administrator. I’ve also tried using RunAs, but that means that the user must enable the Administrator account and set/know the password.

The only other solution that we’ve come up with is to disable the daemon/service management in the user tool and force the user into the Services app. However, that prevents a couple of other convenience features from being available.

Does anyone have a method that would use the normal UAC elevation for a specific process launched in a shell?

I wrote this as my first project for the weekly code challenge but I ran into issues with DragItem.Drag so I didn’t feel like it was good enough to release to the public as part of that event.

Take a look at the RunAs method, there’s also a cool batch file trick in canvasDrag.MouseDown

Its heavily commented but let me know if you need info on something specific, hope it helps.

https://www.dropbox.com/s/x0p0cp1eh4n2ppo/EzSymLinker.xojo_binary_project?dl=1

PS. I use this quite a lot to symlink in my reformatcode script into each new install/beta of xojo so I only have to alter it in one place.

1 Like

Genius code, Julian. That should be an example included with the IDE because I know that (as my mom used to say) “we’re not the only two chickens in this coop.”

Thanks.

1 Like