fisofo Posted January 5, 2007 Share Posted January 5, 2007 Happy Friday!I'm trying to somehow "poll" or something similar RDP sessions that are not currently active (we're talking using the windows mstsc.exe here) so that they do not reach the time limit that knocks them into username/password screen. Thing is, I can't seem to do it Here is what I've tried:func RDPKeepAlive() $aActiveServers = winlist("- Remote Desktop") $hActiveWin = WinGetHandle(WinGetTitle("")) For $x = 1 to $aActiveServers[0][0] If $hActiveWin <> $aActiveServers[$x][1] Then ; do 'em one at a time ControlFocus ($aActiveServers[$x][1], "", "ToolbarWindow322") $test01 = ControlClick($aActiveServers[$x][1], "", "ToolbarWindow322") $test02 = ControlClick($aActiveServers[$x][1], "", "101") $test1 = ControlSend($aActiveServers[$x][1], "", "UIMainClass1", "+") $test2 = ControlSend($aActiveServers[$x][1], "", "OPWindowClass2", "+") $test3 = ControlSend($aActiveServers[$x][1], "", $aActiveServers[$x][0], "+") $test4 = ControlSend($aActiveServers[$x][1], "", "", "+") EndIf Next endfuncI've confirmed that all of the above controlclick/send's return a 1, so it's not an issue of the "control" not being found. You'll notice I've been trying to send the shift key to them, i figured that was the least intrusive way to do it... assuming it would freaking work I've inspected ControlSendPlus, but I don't see it offering any more value to what i'm trying here, please correct me if I'm wrong.Anywho, anyone have ideas on how to do this? My goal is to be able to leave an RDP session in the background or minimized and keep it from timing out to login screen. Putting code on the servers is not an option, and i want them to stay in the background as i often have upwards of 8 to 10 servers i'm switching around in.thanks! Link to comment Share on other sites More sharing options...
Zedna Posted January 6, 2007 Share Posted January 6, 2007 (edited) Nice idea. I can use i too.Now I can't test RDP. Did you tried other keys than Shift?Here is another test:$test5 = ControlClick($aActiveServers[$x][1], "", "UIMainClass1")EDIT:new idea - use some kind of SendMessage to given window handle ... Edited January 6, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
fisofo Posted January 6, 2007 Author Share Posted January 6, 2007 Nice idea. I can use i too. Now I can't test RDP. Did you tried other keys than Shift? Here is another test: $test5 = ControlClick($aActiveServers[$x][1], "", "UIMainClass1") EDIT: new idea - use some kind of SendMessage to given window handle ...thanks! I'm testing right now (every test takes 10 minutes ) I like the SendMessage idea, but i'd have NO idea where to start... Link to comment Share on other sites More sharing options...
fisofo Posted January 6, 2007 Author Share Posted January 6, 2007 sweet monkey's of madness! $test5 = ControlClick($aActiveServers[$x][1], "", "OPWindowClass2") This appears to have worked, so that's pretty awesome. I've got to split but i'll do a bit more testing when i get back. Link to comment Share on other sites More sharing options...
fisofo Posted January 6, 2007 Author Share Posted January 6, 2007 Cancel that, it works for a little while... and then it freezes the session I'll see what i can figure out... Link to comment Share on other sites More sharing options...
Zedna Posted January 6, 2007 Share Posted January 6, 2007 Cancel that, it works for a little while... and then it freezes the session I'll see what i can figure out...Show your whole code: How you call RDPKeepAlive(). Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
fisofo Posted January 6, 2007 Author Share Posted January 6, 2007 Well, i've got about 600 lines right now, but I'll show you all the relevant stuff for KeepAlive. $KeepAliveCount = 0 $RDPWin_KeepAlive = 1 $RDPWin_KATime = 2 *60000 AdlibEnable ( "_OnAdLib", 500 ) Func _OnAdLib() $aAdlib = WinList($Win_Match_Title) If $RDPWin_KeepAlive = 1 Then $KeepAliveCount += 500 If $KeepAliveCount >= $RDPWin_KATime Then _KeepAlive($aAdlib) $KeepAliveCount = 0 EndIf EndIf EndFunc Func _KeepAlive($aActiveServers) $hActiveWin = WinGetHandle(WinGetTitle("")) For $x = 1 to $aActiveServers[0][0] If $hActiveWin <> $aActiveServers[$x][1] Then ;~ ControlFocus ($aActiveServers[$x][1], "", "ToolbarWindow322") ;~ $test1 = ControlClick($aActiveServers[$x][1], "", "ToolbarWindow322") ;~ $test2 = ControlClick($aActiveServers[$x][1], "", "101") ;~ $test3 = ControlSend($aActiveServers[$x][1], "", $aActiveServers[$x][0], "+") ;~ $test4 = ControlSend($aActiveServers[$x][1], "", "", "+") ;~ $test5 = ControlSend($aActiveServers[$x][0], "", "Input Capture Window", "+") ;~ $test6 = ControlSend($aActiveServers[$x][1], "", "UIMainClass1", "+") ;~ $test7 = ControlSend($aActiveServers[$x][1], "", "OPWindowClass2", "+") ;~ $test8 = ControlClick($aActiveServers[$x][1], "", "OPWindowClass2") ;~ $test9 = ControlClick($aActiveServers[$x][0], "", "Input Capture $test10 = ControlClick($aActiveServers[$x][1], "", "") EndIf Next EndFunc I haven't tried a ControlFocus combined with thoes last ControlClicks, so maybe I'll do that next. So right now, this function gets called every 2 minutes (AdlibeEnable is not set to 2 minutes because i have 1 or two other functions that run at the 500 ms time). It appears that the code is actually "working" in that it's doing exactly what it says it is, but for whatever reason, the RDP Session freezes after receiving ControlClick's a few times. Link to comment Share on other sites More sharing options...
ptrex Posted January 7, 2007 Share Posted January 7, 2007 @bothMaybe you can use the RDC Webcomponent and the COM interface to get it going.RDP COM interfaceJust an idea.regardsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
LOULOU Posted January 7, 2007 Share Posted January 7, 2007 @bothMaybe you can use the RDC Webcomponent and the COM interface to get it going.RDP COM interfaceJust an idea.regardsptrexI suggest you to use autolib from Paul1A, with these library you can control a lot of windows control uncrotolabel with autoit2 Link to comment Share on other sites More sharing options...
fisofo Posted January 7, 2007 Author Share Posted January 7, 2007 I suggest you to use autolib from Paul1A, with these library you can control a lot of windows control uncrotolabel with autoit2Thanks for the suggestions.@ptrex - seems to be a bit n/a ? looks like those are for the web connect com objects, and well, i just don't know how to use them @LOULOU - thanks i'll check it out, although at this point i'm not sure if it's an issue of "control" or not. It seems as if I'm really close here, I hope I don't have to dive into that significant library (albeit, excellent) to solve a seemingly small problem :"> Link to comment Share on other sites More sharing options...
ptrex Posted January 8, 2007 Share Posted January 8, 2007 @fisofolooks like those are for the web connect com objects, and well, i just don't know how to use themIndead this is for the webcomponent of RDC, but this way you might have more control over the Object using COM.Regards,ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
jeepjep Posted January 17, 2007 Share Posted January 17, 2007 Not sure if this will help you or not? When you login to a RDP session you can set this without a script. righ-click on desktop - > properties -> screen saver You will probably see 10 minutes in there, just set it to none. And you should be done? Sorry If I missed something John Link to comment Share on other sites More sharing options...
fisofo Posted January 17, 2007 Author Share Posted January 17, 2007 Not sure if this will help you or not? When you login to a RDP session you can set this without a script.righ-click on desktop - > properties -> screen saverYou will probably see 10 minutes in there, just set it to none.And you should be done?Sorry If I missed something JohnIn one regard, you are right in that this type of thing can be set from the server side (it's actually a group policy setting for disconnect time period for inactive sessions, or something like that... not the screensaver timeout).However, I'm looking for something quicker that doesn't have to be continually configured. I connect on average to about 15 different servers in a single day, and new ones are constantly being added, so going and changing settings each time is a real pain.Anyway, I'm afraid I may need to let this one die for the time being as thorough testing on my part has not been able to get any of the ControlClick/Send commands to work reliably... and I the webcomponent stuff hasn't really worked yet either. Link to comment Share on other sites More sharing options...
manonstreet Posted February 19, 2008 Share Posted February 19, 2008 (edited) In one regard, you are right in that this type of thing can be set from the server side (it's actually a group policy setting for disconnect time period for inactive sessions, or something like that... not the screensaver timeout).However, I'm looking for something quicker that doesn't have to be continually configured. I connect on average to about 15 different servers in a single day, and new ones are constantly being added, so going and changing settings each time is a real pain.Anyway, I'm afraid I may need to let this one die for the time being as thorough testing on my part has not been able to get any of the ControlClick/Send commands to work reliably... and I the webcomponent stuff hasn't really worked yet either.I got this to work just fine in Perl with Win32::GUITest (which is just a wrapper to the API calls like AutoIT) using the following:SendMessage($icw, WM_SETFOCUS, undef, undef);PostMessage($icw, WM_MOUSEMOVE, 0, 0);$icw is a handle to InputCaptureWindowsWM_SETFOCUS is 0x007WM_MOUSEMOVE is 0x200undef is Perl's version of NULLI'm sure you can use AutoIT to mimic the above code. By the way, the code does NOT steal the focus from your current window. It only informs the window it has focus so that the move mouse command works. Similarly it does not move the mouse, it just tells the TS window that you moved it to position 0, 0.Good luck,--man on street Edited February 19, 2008 by manonstreet Link to comment Share on other sites More sharing options...
drac Posted March 7, 2009 Share Posted March 7, 2009 I got this to work just fine in Perl with Win32::GUITest (which is just a wrapper to the API calls like AutoIT) using the following: SendMessage($icw, WM_SETFOCUS, undef, undef); PostMessage($icw, WM_MOUSEMOVE, 0, 0); $icw is a handle to InputCaptureWindows WM_SETFOCUS is 0x007 WM_MOUSEMOVE is 0x200 undef is Perl's version of NULL Thanks for the tip. I just needed to send some mouse movements to specific remote desktop window, so here's the code: #Include <WinAPI.au3> #Include <SendMessage.au3> $WM_SETFOCUS = 0x007 $WM_MOUSEMOVE = 0x200 If $CmdLine[0] = 0 Then MsgBox(0, "Error", "Please enter server name as command line parameter.") Exit Else $sName = $CmdLine[1] Endif $title = $sName & " - Remote Desktop" $hWnd = WinGetHandle($title) If $hWnd = 0 Then MsgBox(0, "Error", "Cannot find Remote Desktop Window for server " & $sName) Exit Else MsgBox(0, "hWnd", "Sending mouse movements to " & $title & " (" & $hWnd & ")" ) Endif while 1 ;MsgBox(0, "sending mouse move to", $hWnd) _SendMessage($hWnd, $WM_SETFOCUS) _WinAPI_PostMessage($hWnd, $WM_MOUSEMOVE, 0, 0) Sleep(60000) WEnd RokX 1 Link to comment Share on other sites More sharing options...
aixylinux Posted April 9, 2013 Share Posted April 9, 2013 Using the help in this forum, I was able to write the following script. It works for me. I have other things I want to add to the script, but this is functional.#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_outfile=rdp_keepalive.exe#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****; Module: rdp_keepalive;; Function: Search for RDP sessions and send periodic mouse movements to them to; to keep them from timing out.;; based on original by manonstreet at; ;; Usage: See $USAGE string below;; Method: Script searches for windows whose title contains " - Remote Desktop" .; It sends a mouse movement to the windows.; After all windows have been poked, it sleeps a while and loops.#Include <WinAPI.au3>#Include <SendMessage.au3>#include <GuiEdit.au3>#include <GUIConstantsEx.au3>#Include <Date.au3>;#Include <Hash.au3>;#include <Debug.au3>;_DebugSetup ();#include <GetOpt.au3>AutoItSetOption("MustDeclareVars", 1)AutoItSetOption ("TrayIconHide", 1) ;# No blinky icon in tray;#######################################; Global variables;#######################################Const $USAGE = "Usage: rdp_keepalive [-d] [-k]" & @CRLF & _ " -d Debug trace to console (or --debug)" & @CRLF & _ " -k Kill previous execution" & @CRLF & _ " -h Display usage"Const $SLEEP = 600000 ; sleep loop delay 10 minutesConst $WM_SETFOCUS = 0x007Const $WM_MOUSEMOVE = 0x200Const $PGM = StringRegExpReplace(@ScriptName, "\..*", "") ; Strip extensionDim $DBG = False ; Global debug flag; Main ProgramGet_Options()AutoItSetOption("WinTitleMatchMode", 2) ; Match any substring in the titleWhile 1Dim $windows = WinList(" - Remote Desktop")if $windows[0][0] = 0 Then Dbg("No RDP sessions are active")EndIfDim $i;Dim $offset = 0For $i = 1 to $windows[0][0] Dim $title = $windows[$i][0] Dim $hWnd = $windows[$i][1] Dim $restore = False Dim $hActv Dim $actTitle ; If window is minimized, can't send mouse clicks to it. Dim $wstate = WinGetState($hWnd) If BitAND($wstate, 16) Then $hActv = WinGetHandle("") ;# Get currently active window handle $actTitle = WinGetTitle($hActv) Dbg("Active window is " & $actTitle) Dbg("Window " & $title & " is minimized, restoring") WinSetState($hWnd, '', @SW_MAXIMIZE) WinSetState($hWnd, '', @SW_RESTORE) $restore = True ; Remember need to restore focus to prev window EndIf Dbg("Sending mouse move to " & $title) _SendMessage($hWnd, $WM_SETFOCUS) If @error Then Die("_SendMessage error" & @error) _WinAPI_PostMessage($hWnd, $WM_MOUSEMOVE, 0, 0) If @error Then Die("_WinAPI_PostMessage error" & @error) ; Restore focus to previously active window If $restore Then Dbg("Restoring focus to " & $actTitle) WinActivate($hActv) EndIfNext;$offset = 0Sleep($SLEEP)WEnd; Should never get here, but just in caseExit 0;#######################################; Function section;#######################################Func Get_Options()Local $aOpts[3][3] = [ _ ['-d', '--debug', False], _ ['-k', '--kill', False], _ ['-h', '--help', False] _ ]_GetOpt_Set($aOpts) ; Set options.If 0 < $GetOpt_Opts[0] Then ; If there are any options... While 1 ; ...loop through them one by one. ; Get the next option passing a string with valid options. Local $sOpt = _GetOpt('dkh') If Not $sOpt Then ExitLoop ; No options or end of loop. Switch $sOpt ; What is the current option? Case '?' ; Unknown options come here. @extended is set to $E_GETOPT_UNKNOWN_OPTION Usage('Unknown option: ' & $sOpt) Case 'd' Logger('Debug mode enabled') $DBG = True Case 'k' Kill_Previous() Exit 0 Case 'h' Usage('') EndSwitch WEndEndIfEndFunc;#######################################; Kill previous execution;#######################################Func Kill_Previous()Local $list = ProcessList() ; List of processesLocal $i, $pname, $pidLocal $found = 0For $i = 1 to $list[0][0] Local $pname = $list[$i][0] Local $pid = $list[$i][1] ; Look for matching process names If Not StringRegExp($pname, $PGM, 0) Then ContinueLoop If $pid = @AutoItPID Then ContinueLoop ; Don't commit suicide $found += 1 Logger("Killing process " & $pid & ", name " & $pname) If ProcessClose($pid) Then If ProcessWaitClose($pid, 60) Then Logger("Process ended") Else Logger("Timeout waiting for process to end") EndIf Else Logger("Can't kill process: " & @error) EndifNextIf $found = 0 Then Logger("No " & $PGM & " processes found")Else Logger("Killed "& $found & " processes")EndIfSleep(10000) ; Hold window open a whileEndFunc;#######################################; Output message if global $DBG flag is set;#######################################Func Dbg($msg)If $DBG Then Logger($msg)EndFunc;#######################################;# Write timestamped message to log window;#######################################Func Logger($msg)Local Static $hLog = 0Local $ts = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SECLocal $title = $PGM & " Log"If $hlog = 0 Then GUICreate($title, 500, 300) $hLog = GUICtrlCreateEdit($ts & " Log starting" & @CRLF, 2, 2, 394, 268) If $hlog = 0 Then MsgBox(0, $PGM & " Error", "Can't create logging window") exit 1 EndIf GUISetState()EndIf_GUICtrlEdit_AppendText($hLog, $ts & " " & $msg & @CRLF);ConsoleWrite($PGM & " " & $ts & " " & $msg & @CRLF)EndFunc;#######################################;# Log error message and usage string, then Die;#######################################Func Usage($msg)Die($msg & @CRLF & $USAGE)EndFunc;#######################################;# Log message and terminate. Leave window open a while so it can be read.;#######################################Func Die($msg)Logger($msg)Sleep(15000)Exit 1EndFunc;### E N D ############################## Link to comment Share on other sites More sharing options...
Patrick Burwell Posted November 23, 2015 Share Posted November 23, 2015 (edited) I don't have the code for AutoAPI.au3 or SendMessage.au3, which you include in the script. Can you post it? Edited November 23, 2015 by Patrick Burwell Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 23, 2015 Moderators Share Posted November 23, 2015 Patrick Burwell,If you are referring to WinAPI.au3 & SendMessage.au3 then these 2 files are included in the standard AutoIt install package.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Patrick Burwell Posted November 23, 2015 Share Posted November 23, 2015 Okay thanks! So we have to ensure this is in the folder we run the scripts from? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 23, 2015 Moderators Share Posted November 23, 2015 Patrick Burwell,No, the standard include files in the ...\AutoIt3\Include folder are always visible to scripts. See the #include page in the Help file for more details.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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