Red Gate forums :: View topic - How to spawn a process (running with specified credentials)
Return to RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net forum

How to spawn a process (running with specified credentials)

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message

Joined: 29 Mar 2008
Posts: 1

PostPosted: Sat Mar 29, 2008 2:24 pm    Post subject: How to spawn a process (running with specified credentials) Reply with quote

Hello everyone,

I'm developing a windows service which needs the ability to spawn a process, running under a given user (specified at runtime) and need to redirect it's stdout, stdin, stderr file descriptors to a file on a network share.

After investigating a lot on the subject, i have concluded i will need to PInvoke CreateProcessWithLogonW or CreateProcessAS from my code.

This is needed because, although i'm currently impersonating the user before trying to use .NET's ProcessStartInfo() and Process() and specifying the relevant username, domain and password for the selected user, the process is already running in a different security context (associated to the user which runs the windows service).

From what i've read, this means i will only be able to Impersonate the user if i PInvoke LogonUser() (which i'm currently doing) on the current thread. This will cause any spawned process to run on the same security context as the user running the windows service so the execution will fail.

I do know i need to PInvoke either CreateProcessWithLogonW or CreateProcessAS so i can successfully spawn a process on the correct security context (and i found a working example here -> but i have NO IDEA how to redirect the stdout, stdin and stderr file descriptors.

I also found that i will need to use a piping mechanism to associate the managed FileStream i create to the unmanaged file descriptors i need to get. (It seems i will need to PInvoke CreatePipe for that ->

Although i, apparently, have all the necessary information need to solve my problem on the above links, i have NO idea how to put it all together since my "Managed / Unmanaged integration skills via PInvoke" are quite limited Surprise)

Could somebody help me put up an example based on this information? I would be ever so grateful!

Thanks in advance,
Luís Silva
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group