问题
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? Thanks
回答1:
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.
UPDATE
It looks like you've used some code from a CodeProject article that wraps the Windows API function CreateProcessAsUser
(http://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-and-bit-Archite). 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.
来源:https://stackoverflow.com/questions/27263901/how-to-run-a-program-from-windows-service-with-administrator-privileges