views:

538

answers:

2

How do I logoff a user via a Windows Service?

I found this example here but it will not work in a service. http://www.c-sharpcorner.com/UploadFile/thiagu304/desktopfunctions02112007140806PM/desktopfunctions.aspx

A: 

Duplicate:

http://stackoverflow.com/questions/221410/remotely-and-programatically-logoff-an-active-domain-user

Jonathan Allen
The questions are similar but not really duplicates. Also, neither of the answers in the linked question are particularly good.
Stephen Martin
+2  A: 

Check out WTSLogoffSession. It does precisely what you want and is pretty easy to call via PInvoke. To get the session ID use WTSGetActiveConsoleSessionId or WTSEnumerateSessions and WTSQuerySessionInformation.

Stephen Martin
Thanks. I will take a look at that.
James
Thanks. I got it to work with what you suggested.
James