5

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?

Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
jaysonragasa
  • 1,076
  • 1
  • 20
  • 40

2 Answers2

3

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
  • 61,059
  • 10
  • 88
  • 148
1

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

hallie
  • 2,760
  • 19
  • 27
  • not sure I would consider setting up auto login relevant here. – TomTom Mar 12 '10 at 07:35
  • +1 - although that method also requires a reboot, it does work - the effect would be the same. – Daniel Earwicker Mar 12 '10 at 07:37
  • 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 Mar 12 '10 at 08:13
  • 1
    Not an option in production systems. – Kobor42 Apr 10 '14 at 07:16
  • @TomTom To complainers. Yes, at the moment I do not like this method either. And oh man, I am also disappointed by not having found what I was looking for :P But then again, the above answer is not pointless at all. I was looking for a solution to a different though related problem. For switching active user the above solution may be rather helpful in some cases. In case there is no better way, the above is **a way**. Just because **you** do not need this answer or it does not fit your needs and because you are disappointed, does not mean the answer is bad. – Roland Pihlakas Dec 24 '16 at 22:30