Get disconnected users and logOff them

拜拜、爱过 提交于 2019-12-11 16:46:46

问题


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.


回答1:


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

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

WTSEnumerateSessions (wtsapi32)




回答2:


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.



来源:https://stackoverflow.com/questions/18377592/get-disconnected-users-and-logoff-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!