Link to home
Start Free TrialLog in
Avatar of Arikkan
ArikkanFlag for United States of America

asked on

Using VB.Net or C#.Net, - List active user logged into a machine and kill the session

We would like to build a simple program that lists users that are logged into the machine and by selecting the item on the list, we want to kill (log off) the session.

Could you please help in
1. code to get list of active session
2. code to log off the specific session (possibly by seeding ID from the #1 above)

(This is somewhat like what we can do from the Task Manager by selecting the user session and "Sign off")

User generated image
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Avatar of Arikkan

ASKER

Thank you very much, but we wish to handle them within .Net.  Is there a way to do this without Powershell?  
Avatar of Arikkan

ASKER

Thank you but the first link is linking to a site that does not exist.
The second one may be ok with getting a list, but there is no way for terminating the session even we get a list...
ASKER CERTIFIED SOLUTION
Avatar of Andrei Fomitchev
Andrei Fomitchev
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

Hi Andrei,
This code currently disconnect user.  Is there a way to log off user?
Thanks. 
Avatar of Arikkan

ASKER

Nevermind, found that we can do this:
        [DllImport("wtsapi32.dll", SetLastError = true)]
        static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait);