Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remotely log off a user?

Tags:

c#

windows

How can I programatically log off a user remotely (from another machine) with C#? All I know is their username. This is done in an Active Directory environment where the account executing this would be an Administrator (Domain Admin). I assume that security would be handled. Would want to avoid having to install an application on the machine.

There does seem to be an API although I do not know what it uses, as "logoff.exe" provided with windows provides for this capability. In the end I can use this, but would prefer to avoid a Process.Start call and relying on it (plus it doesn't take the username, just the session id).

like image 825
esac Avatar asked Nov 15 '22 07:11

esac


1 Answers

This is more terminal server side of user management but I really like using Cassia


Another option is do this

System.Diagnostics.Process.Start("shutdown.exe", String.Format(@"/l /f /m \\{1}", remoteComputerName));

/l is logoff. /f is force. /m \\computername is the name of the remote computer to do the operation on. If you are not on a domain and the user running the app does not have domain admin rights I can not guarantee the above command will work.


Third option: get PsExec then run the shutdown command with it on the remote computer(shutdown.exe /l /f)

like image 120
Scott Chamberlain Avatar answered Dec 12 '22 04:12

Scott Chamberlain