tags:

views:

332

answers:

4

Hi,

I'd like to know if is there any way in C# to programatically log-in a Windows User Account?

We are currently developing an monitoring application and one of the feature is to be able to log-off the current Windows User and switch to another Windows User Account.

I have some few methods for Logging off, such as through API or Command Line. But what about logging-in a user account?

A: 

This might be what you're looking for...codesample

hallie
not sure I would consider setting up auto login relevant here.
TomTom
+1 - although that method also requires a reboot, it does work - the effect would be the same.
Daniel Earwicker
i mean part of the code/idea maybe useful..
hallie
Whow. "althoug it requires a reboot, the effect would be the same" must be a new level of how low computer service can go. A solution reuiqring a eboot to change the logged in user is NOT the same.
TomTom
+2  A: 

You mean interactive?

  • Logoff, if anything fails, spawn a request to logoff.exe
  • Logon - nope. that is a GINA module that can go in front (look it up in google), but this is a very tricky beast to do. The security system in windows is pretty well isolated for obvious reasons (i.e. security).

I am not aware of anything you could do in C#.

http://technet.microsoft.com/en-us/library/cc780332%28WS.10%29.aspx

has some more details how user logon works.

TomTom
+1 It should be possible to replace the GINA module with your own.
Lieven
A: 

here is an document How Interactive Logon Works

http://technet.microsoft.com/en-us/library/cc780332%28WS.10%29.aspx

drorhan
A: 

For logoff you can you use something like this, For login first look at Interactive Logon document, also you can create user profile without Interactive Logon, take a look at this KB

Hameds