简体   繁体   中英

Start process with full rights and environment

I have a windows service running under a user account other than LocalSystem, let's assume the user mydomain\\svcUser .

The service spawns a new process P using Process.Start(...) . The process P makes usage of the default Outlook Profile defined under user mydomain\\procUser . Works fine.

Now, I need to spawn the same process P under a new user: mydomain\\procUser that basically has the same priviledges as mydomain\\svcUser .

I tried to use CreateProcessAsUser in many ways after obtaining the token with LogonUser but it just won't work.

Now, if I change the Log On user of my process to mydomain\\procUser then the spawned process P has all the required rights and environment stuff to work properly.

I am pretty lost on how to combine the parameters to be passed to LogonUser and CreateProcessAsUser so that I can be able to keep the service running under mydomain\\svcUser but the spawned process P to work properly under mydomain\\procUser .

This link is very helpful, but it's only a great guideline article, the success depends on how to use the flags and other stuff when calling LogonUser and CreateProcessAsUser .

Use the overload of Process.Start that takes in user credentials

public static Process Start(
string fileName,
string userName,
SecureString password,
string domain
)

See here

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