Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

winapi - Can I programmatically check a remote computer to see if someone is already connected via Remote Desktop to this computer?

We have a few Windows 10 Pro computers with Remote Desktop enabled. There are "client" machines running Windows 10 Pro and Windows 10 Home.

Is it possible to programmatically check, from a client machine, that the remote computer is already occupied by someone? That is, if another remote client is already connected to it? If so, can I do this without breaking the existing remote connection?

question from:https://stackoverflow.com/questions/65901692/can-i-programmatically-check-a-remote-computer-to-see-if-someone-is-already-conn

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When a user logs on to a Remote Desktop Services–enabled computer, a session is started for the user. Each session is identified by a unique session ID. Because each logon to a Remote Desktop Connection (RDC) client receives a separate session ID.

Refer: Remote Desktop Sessions

You can use the WTSEnumerateSessions function to retrieve the identifiers of all sessions on a specified RD Session Host server.

WTSEnumerateSessions : Retrieves a list of sessions on a Remote Desktop Session Host (RD Session Host) server.

Note:

  • To enumerate a session, you must enable the query information permission. For more information, see Remote Desktop Services Permissions.
  • To change permissions on a session, use the Remote Desktop Services Configuration administrative tool.
  • To enumerate sessions running on a virtual machine hosted on a RD Virtualization Host server, you must be a member of the Administrators group on the RD Virtualization Host server.

If you want to retrieve the session ID of the current session that the remote desktop service is running, you can call WTSQuerySessionInformation and specify WTS_CURRENT_SESSION for the SessionId parameter and WTSSessionId for the WTSInfoClass parameter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...