How to run a program from windows service with administrator privileges


I created a windows service that runs a program on windows startup, but with this solution the program runs without administrator privileges. However, if I run the program by click on the program's shortcut on the Start menu, it runs with administrator privileges

I used this code to run the program:

ApplicationLoader.PROCESS_INFORMATION procInfo;

ApplicationLoader.StartProcessAndBypassUAC(program_name, out procInfo);

So how to run this program with administrator privileges?

Best Solution

To run as administrator (program)

Right click and choose "Run as administrator" (one-time / ad hoc)

or right click and choose properties > Compatibility > check "Run this program as administrator" (set it permanently; can also be handy for setting this property on a shortcut (which is basically what Start menu items are))

To not run as administrator (service)

For services, to make it not run as an admin, open the services snap in (run services.msc from command prompt) and right click to edit properties of the service, then update the user info on the "Logon" tab.


It looks like you've used some code from a CodeProject article that wraps the Windows API function CreateProcessAsUser ( Make sure you read that article and follow the steps. You may not have set the correct user on the service, or your current user may not have correct perms, or may not be a member of Administrators, etc.