Link to home
Avatar of Arikkan
ArikkanFlag for United States of America

asked on

log off users from remote machine using C#.Net

From the earlier thread (https://www.experts-exchange.com/questions/29216276/Using-VB-Net-or-C-Net-List-active-user-logged-into-a-machine-and-kill-the-session.html) we are able to list users and log off users on local machine when using

IntPtr ptrOpenedServer = WTSOpenServer(ServerName)

[DllImport("wtsapi32.dll", SetLastError = true)]
        static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait);

where "ServerName" is "localhost".

However, when specifying the ServerName with the remote machine, we are not able to log off the user.

Could you please let us know if there is a way to log off user on a remote machine on the same network with no firewall restrection between the two machines?  

FYI, we are able to get the list of the logged in users using the code mentioned in the earlier thread.  

Thank you very much.
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial