Hi, thank you for reading my post
# Background
I have two PCs, PC_A, PC_B, in the same LAN
I am using PC_A and have a hotkey to run remotedesktop to connect to another PC(PC_B)
say, I have
^F8:: MyFunc_Connect()
which calls "C:\Windows\SysWOW64\mstsc.exe" with parameter to connect to other PC
# What I want to do
When I RemoteDesktop from PC_A to PC_B I wish to block this shortcutkey,
so as to avoid double RemoteDesktop like PC_A➤PC_B➤PC_A, which cause trouble sometimes
# What I tried
I understand that "mstsc.exe" is RemoteDesktop Client, but I have no idea the "server app exe" on PC_B.
If I do know, then I can use WinExist() to judge if PC_B is being connected from some other PCs.
Thank you.
How do I tell if the PC is already in Remote Desktop? Topic is solved
Re: How do I tell if the PC is already in Remote Desktop? Topic is solved
https://github.com/jNizM/ahk-scripts-v2/blob/main/src/Others/IsRemoteSession.ahk
Returns a value of TRUE to indicate that the current session is a remote session, and FALSE to indicate that the current session is a local session.
Returns a value of TRUE to indicate that the current session is a remote session, and FALSE to indicate that the current session is a local session.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: How do I tell if the PC is already in Remote Desktop?
Thank you for your answer, will try it after updating to V2jNizM wrote: ↑08 Feb 2023, 04:49https://github.com/jNizM/ahk-scripts-v2/blob/main/src/Others/IsRemoteSession.ahk
Re: How do I tell if the PC is already in Remote Desktop?
Is there any chance we can convert this code into v1 compatible?
Code: Select all
IsRemoteSession()
{
#DllLoad "wtsapi32.dll"
static WTS_CURRENT_SERVER_HANDLE := 0
static WTSIsRemoteSession := 29
static ProcessId := DllCall("kernel32\GetCurrentProcessId")
; retrieves the Remote Desktop Services session associated with a specified process
if !(DllCall("kernel32\ProcessIdToSessionId", "UInt", ProcessId, "UInt*", &SessionId := 0))
throw OSError()
; retrieves session information for the specified session on the specified Remote Desktop Session Host (RD Session Host)
if !(DllCall("wtsapi32\WTSQuerySessionInformation", "Ptr", WTS_CURRENT_SERVER_HANDLE, "UInt", SessionId, "Int", WTSIsRemoteSession, "Ptr*", &Buf := 0, "UInt*", &Size := 0))
{
DllCall("wtsapi32\WTSFreeMemory", "Ptr", Buf)
throw OSError()
}
IsRemoteSession := NumGet(Buf, "Int")
DllCall("wtsapi32\WTSFreeMemory", "Ptr", Buf)
return IsRemoteSession
}