Reputation: 489
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
Upvotes: 1
Views: 2933
Reputation: 378
HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server --->>>> Set DWORD32 AllowRemoteRPC == 1
The Remote Procedure Call (RPC) service [RpcSs] should be running on a computer by default.
We need this enabled to use the following commands:
I believe those commands use the functions you are trying to use behind the scenes, therefore if those commands succeed then that means the functions will succeed.
Upvotes: 0
Reputation: 9645
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.
Upvotes: 3