Laxmi Lal Menaria
Laxmi Lal Menaria

Reputation: 1445

How to Switch User programatically using C#

I have windows 2003 server and want to switch users programatically using c#. I have list of all active user so how can I switch the user ?

I need to capture the screen of all users which are logon currently.

Thanks Laxmilal

Upvotes: 2

Views: 5300

Answers (3)

StefanE
StefanE

Reputation: 7630

You can execute actions with impersonations(with a specific username and password) in ASP .Net.

If it's a windows application you just start a process with different username described in here. http://msdn.microsoft.com/en-us/library/ed04yy3t.aspx

Cheers, Stefan

Upvotes: 1

Oded
Oded

Reputation: 498952

It is not entirely clear what you want to achieve.

There are several ways to have a program run as a different user than the logged in one (or have the program execute another process with different credentials):

  • Use runas, supplying the credentials for the other user
  • In C#, use Process.Start with ProcessStartInfo. This lets you provide the credentials under which the process should run
  • Windows services require an account to run - this can be a different user than the logged in one (and will run whether someone is logged on or not)

You can't change the credentials of an already running process.

Can you explain exactly what you are trying to achieve? Perhaps there are other ways to achieve what you want.

Upvotes: 2

fejesjoco
fejesjoco

Reputation: 11903

You mean like if you lock the screen and log on with someone else? That is totally impossible. You know the login screen says you need to press ctrl-alt-del, it is designed so that noone can mess with that. You can impersonate users however, like with the runas command, but you need to know their passwords for that.

Upvotes: 0

Related Questions