0

I am trying to build a C# app that aims to do multiple tasks [e.g. open a file, open a port, spawn a Windows service etc.] simultaneously.

Here is what I require:-

a) The app should be able to run these tasks at the same time [each initiated through and inside a separate thread but inside the same application domain] b) Each thread should run under the account of a separate Windows user account [The user name and password will be supplied before the application starts through a repository/table]

Please suggest the best way to achieve this in C#? Thanks, Sumit

Bathla
  • 125
  • 9

2 Answers2

1

Here is my research effort:- a) DllImport LogonUser, SetThreadToken and LogOffUser APIs b) Log the user in and get the handle/token c) Create the thread and set the token on the thread using SetThreadToken d) Run/Execute the thread. Now the thread will perform the action as if being run under the account of the user whose credentials were supplied with LogonUser API e) After the thread has done its job, call the LogoffUser API to log the user off the thread.

This did work for me!

However, I would be interested in knowing if I can do this using managed/pure C# APIs.

Anyone?

Bathla
  • 125
  • 9
0

not sure if you can run different tasks/threads under diffrent user credentials although you can call, this is not same as running different threads using different user credentials.

Process.Start(filenameToStart, username, password, domain);

and for parallel processing Parallel.Invoke can be used.

Parallel.Invoke( () => doX(), () => doY());

Mayank
  • 8,777
  • 4
  • 35
  • 60
  • Thanks for answering that Mayank. But I did a bit of research myself and found that a native API SetThreadToken that can be used for impersonating any user and running a thread under his/her credentials – Bathla Aug 16 '12 at 18:38