Get disconnected users and logOff them

2019-09-01 14:48发布

I am trying to loging into remote server using credentials from command line and checking for the users who got disconnected and I would make them logOff programatically.

This is the way I'm trying to do as of now and bit working.But I'm getting all the users list which I don't want.

So far this is my code for finding out the users on remote desktop who got connected to it.

quser /server:myservername

For Logging Off individually I am using this:

logoff /server:myservername 1 /v

Now my question is If there are more than "1" user how do I find the list of who all are got disconnected and make them LogOff.

2条回答
Ridiculous、
2楼-- · 2019-09-01 15:37

From what I can see on my Google searches, quser returns the list of users connected, as well as a session ID column. Simply replace the "1" in your "logoff /server:myservername 1 /v" command with the session you want to log off and it should log that session off instead.

Another option is to set a group policy timer which will logout disconnected users after the timeout period set. Here is a link to an example: http://talkingtechnical.blogspot.com/2009/05/creating-group-policy-to-log-off-remote.html

Setting it at this level means the server will manage the connections rather than rely on a program to run and do so.

查看更多
走好不送
3楼-- · 2019-09-01 15:45

You have to use WMI in vb.net, like;

http://www.pinvoke.net/default.aspx/wtsapi32/WTSEnumerateSessions.html

WTSEnumerateSessions (wtsapi32)

查看更多
登录 后发表回答