I have found this code that detects remote connection using DLL:
https://github.com/jNizM/ahk-scripts-v2/blob/main/src/Others/IsRemoteSession.ahk
However it uses AHK v2 syntax.
It will be very kind if can help to make it work on v1 if possible?
Thank you so much!
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
}