Jump to content

Seeking Method of Detecting that Script is Running on a Computer Currently in a Fullscreen Remote Desktop Session


Recommended Posts

Posted

Greetings!

I have a script running on a remote computer, and I connect to that computer via Remote Desktop. I am able to detect that my script (running on the remote computer) is currently running within a Remote Desktop Session via the below:

$isRemote = DllCall("user32.dll", "int", "GetSystemMetrics", "int", 0x1000)
If $isRemote[0] <> 0 Then
;~     MsgBox(0, "RDP", "Running in a Remote Session")
    ConsoleWrite("Running inside an RDP session" & @CRLF)
    ConsoleWrite("Width: " & @DesktopWidth & " | Height: " & @DesktopHeight & @CRLF)
EndIf

I want to be able to detect whether this Remote Desktop Session is currently Fullscreen, or "windowed." Google keeps trying to tell me I can determine this by comparing the resolution, a la the following Google AI suggestion:

; Declare the GetSystemMetrics function from user32.dll
; The constant SM_REMOTESESSION has a value of 0x1000 (4096 in decimal)
Local Const $SM_REMOTESESSION = 0x1000
Local Const $SM_CXSCREEN = 0
Local Const $SM_CYSCREEN = 1

If GetSystemMetrics($SM_REMOTESESSION) Then
    MsgBox(0, "RDP Session Detected", "The script is running in an RDP session.")

    ; In an RDP session, check if the session is likely fullscreen or windowed
    ; @DesktopWidth and @DesktopHeight contain the dimensions of the entire desktop
    ; GetSystemMetrics(SM_CXSCREEN/SM_CYSCREEN) also returns these dimensions
    Local $iScreenWidth = @DesktopWidth
    Local $iScreenHeight = @DesktopHeight

    ; Check if the current window (the RDP client itself, if the script can access it) 
    ; matches the desktop dimensions.
    ; A more reliable method is to compare the *actual* displayed resolution 
    ; with a known potential windowed size.
    ; This simple check can indicate fullscreen mode if the dimensions match 
    ; the client's full monitor size.

    ; Note: This simple comparison might not be perfect in all multi-monitor or RDP configurations.
    ; For a more robust check within the RDP session, you might use WinGetPos on the RDP client window itself.
    ; However, the script is running *inside* the remote machine, so it sees the remote desktop's properties.

    If $iScreenWidth >= GetSystemMetrics($SM_CXSCREEN) And $iScreenHeight >= GetSystemMetrics($SM_CYSCREEN) Then
        MsgBox(0, "RDP Mode", "The RDP session is likely in Fullscreen mode based on resolution comparison.")
    Else
        MsgBox(0, "RDP Mode", "The RDP session is likely in Windowed mode based on resolution comparison.")
    EndIf

Else
    MsgBox(0, "Local Session", "The script is running in a local session.")
EndIf

; Function to call the Windows API function GetSystemMetrics
Func GetSystemMetrics($nIndex)
    Local $aResult = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $nIndex)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc

But this does not work for me (and I strongly suspect Google is wrong in this case). AutoIt (running within the Remote Desktop client) always reports the full resolution of that client.

Is there any way that Windows (I'm on Windows 11) reports that it is currently running within a Fullscreen Remote Desktop Session vs Windowed Remoted Desktop Session, and if so, how can I use AutoIt to detect that? I have certain functions that I want to disable when in a Windowed state, but want to enable when within a Fullscreen Remote Desktop Session.

Any help is greatly appreciated! :)

Posted
On 2/18/2026 at 4:40 PM, ilikeautoit said:

..a la the following Google AI suggestion

If there is a canvas you can take a screen capture, if not ( minimized or disconnected ) the screen capture will either get an all black image ( if BMP you're gonna see chr(0) / NUL in the whole file minus the header ) or just plain crash the script.

If not maximized, the canvas is the same as maximized. Only the local user will see a smaller window but for the remote, the size is as if maximized.

If you find a solution to your exact problem ( not what you believe you'll need ), post it.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...