Assist to convert from AHK v2 to v1 : Remote Connection detection

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rc76
Posts: 147
Joined: 07 Nov 2020, 01:45

Assist to convert from AHK v2 to v1 : Remote Connection detection

Post by rc76 » 20 Jan 2024, 21:48

Hi

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
}

Return to “Ask for Help (v1)”