I want run my program under a limited user account but with administrator privileges on windows XP.
I can't find an answer. I think I can use two ways:
- Run my program by another way like a program or a service
- Run my function with some method like PrincipalPermission space or something like this
But I can't solve this problem.
This can't be done. A limited user doesn't have admin privileges. You need to run it as an admin user with, e.g. runas.
One way to solve this is to fragment your program into two parts. One part as a windows service and the one as a user app. You can set the service to run as a Network Service, Local Service or Local System depending the level of access you need. Anything that needs administrator privileges will be performed by the Windows service. The user app can be responsible for showing the user interface and other similar things. You need to have some kind of IPC (Inter process communication) between your applications to facilitate this as well.
Have you looked at the "runas" command? For example: