ilikeautoit Posted February 18 Posted February 18 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: expandcollapse popup; 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! :)
argumentum Posted February 21 Posted February 21 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.
ilikeautoit Posted February 21 Author Posted February 21 9 hours ago, argumentum said: 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. I appreciate the reply, but either I am not understanding or this method unfortunately does not work for me. When the script that is running inside of the Remote Desktop window (ie, the script is running on the Remote computer) takes the screen capture it is always the same size, regardless of whether I'm in fullscreen or not (perhaps because my remote desktop connections are configured to always use the full resolution of the remote pc?).
argumentum Posted February 21 Posted February 21 ..that is what I said, the remote PC will believe to have the desktop size the local PC said it will be on the remote. All you can tell from the remote is if is in view ( with a canvas ) or not ( minimized or disconnected ). But you are explaining the solution you need and not the problem you have. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted February 21 Posted February 21 ..maybe do an IPC with the remote and tell the remote that is in this or that state via clipboard or a file 🤷♂️ 11 minutes ago, ilikeautoit said: the screen capture it is always the same size 9 hours ago, argumentum said: 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. Yes, the size is the same because is a BMP, try a PNG to compare size ?, because the file is just an array of NUL. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ilikeautoit Posted March 2 Author Posted March 2 On 2/21/2026 at 12:19 PM, argumentum said: ..maybe do an IPC with the remote and tell the remote that is in this or that state via clipboard or a file 🤷♂️ Yes, the size is the same because is a BMP, try a PNG to compare size ?, because the file is just an array of NUL. I appreciate your efforts to help! I was not clear -- by size I meant that the image dimensions were the same regardless, so the screen capture was not indicating any different in image resolution, and thus was not able to indicate whether I was in fullscreen Remote Desktop or not.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now