Jump to content
Sign in to follow this  
coffeeturtle

RDP crashing AutoIt on running on Remote computer

Recommended Posts

coffeeturtle

Has anyone seen this odd behavior where an autoit program is running on a remote computer. When you use Microsoft's Remote Desktop client to remote in on that machine, no problem. But if the user at some point later logs on locally to that same machine, autoit crashes?

I'm not sure why it happens. I was just wondering if anyone in general ever has experienced this and maybe what they did to stop the odd behavior.

Thank you!

Edited by coffeeturtle

Share this post


Link to post
Share on other sites
spudw2k

I can't say I've seen that behavior in general, but that's a tough determination without knowing the nature of the script which produces the issue. Furthermore inspection of the actual code involved might be required to truly narrow the cause.

Can you elaborate some?

Share this post


Link to post
Share on other sites
DicatoroftheUSA

It is hard to tell with the info you gave. But what I am guessing, is that you don't have terminal services installed. And you are not running your script as a service. When they log in, you get logged off, therefore your script closes naturally.

Share this post


Link to post
Share on other sites
coffeeturtle

Sorry about the scant amount of information. I was kind of wondering it was a bug with autoit since my script has nothing to do with remote access. I'm going to try to narrow down some of the code and post it here. Line numbers don't match well with the error messages, but maybe JScript's autoiterrortrap might help me.

Thanks again and I will try to post soon.

Share this post


Link to post
Share on other sites
spudw2k

Share this post


Link to post
Share on other sites
DicatoroftheUSA

You can try adding the following

#include <File.au3>
OnAutoItExitRegister ( "_exit" )
global $gsLogPath=@DesktopCommonDir&"log.txt"
_FileWriteLog($gsLogPath, "script started")

;your script here


Func _exit()
local $sMethod
Switch @exitMethod
case 0
$sMethod="Natural closing."
case 1
$sMethod="close by Exit function."
case 2
$sMethod="close by clicking on exit of the systray."
case 3
$sMethod="close by user logoff."
case 4
$sMethod="close by Windows shutdown."
EndSwitch

Local $sLogMsg="Exiting with exit code "&@exitCode& " by "&$sMethod

_FileWriteLog($gsLogPath, $sLogMsg )
exit
EndFunc

You could also launch your script with PSEXEC if it is not gui based.

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites
guinness

Another way using an Array.

#include <File.au3>

OnAutoItExitRegister('_Exit')

Global $__sLogFilePath = @ScriptDir & 'log.txt'
_FileWriteLog($__sLogFilePath, 'Script started')

; Script here.

Func _Exit()
    Local $aExit[5] = ['Natural closing.', 'Closed by Exit function.', 'Closed by clicking on exit of the systray.', _
            'Closed by user logoff.', 'Closed by Windows shutdown.']
    _FileWriteLog($__sLogFilePath, 'Exiting with exit code ' & @exitCode & ' by ' & $aExit[@exitCode])
    $aExit = 0
    Exit @exitCode
EndFunc   ;==>_Exit

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Similar Content

    • argumentum
      By argumentum
      ..so I have to help someone and remember how to get the session ID,
      then remember how to shadow. All from a command prompt. Not cool.
      So I wrote this,
      Is coded for Windows in English. May work in other languages too.
      ( as long as "qwinsta" runs, this should work )
      For this to work as intended, uncheck "noPrompt", or make the changes
       to the group policy, only if you know what you are doing.
      ( I will not aid anyone on how what, as I'm not qualified )
      This is for when all works as you wish, but have to use the
       command line to shadow a user ( and everyone is in a hurry ).
      This gives you a list of users to just click to help the
      user on a remote session, by guiding them ( view ) or
      interacting with the desktop ( control ).
      I do not advise to change anything on your system, nor to use this,
      but if you find it useful, then, it is a very practical utility.
        I did not post in the examples forum as is not an example worth posting.
        It grabs the text out of qwinsta and runs mstsc. Not a noteworthy example.
    • FMS
      By FMS
      Hello,
      At this moment I'm trying to make a RDP tool to make multiple connections and switch between them.
      Curently I'm having troubles in making multiple connections and got some error's.
      I know why I get the error's  (trying to change a active connection) but I'm not sure how to solve this.
      Does somebody know a cleaver way to make it scalable into more connections in the same embeded window?
      Also I'm open for sugestions for making this code better
      Below the code I'm working on at the moment:
       
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #Include <GuiComboBoxEx.au3> Global $configfile = @ScriptDir & "\config.rto" Global $configarray[0][0] Global $RDP_id = False Global $RDP_name = False Global $RDP_ip = False Global $RDP_usr = False Global $RDP_dom = False Global $RDP_pass = False $Form1 = GUICreate("Form1",952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $Combo1 = GUICtrlCreateCombo("Combo1", 8, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Button1 = GUICtrlCreateButton("Connect", 160, 8, 75, 25) $Button2 = GUICtrlCreateButton("Disconnect", 240, 8, 75, 25) $Button3 = GUICtrlCreateButton("Button3", 320, 8, 75, 25) $oRDP = ObjCreate("MsTscAx.MsTscAx.10") $oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE) GUISetState(@SW_SHOW) fetch_config() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Combo1 set_config(GUICtrlRead($Combo1)) Case $Button1 $oRDP.DesktopWidth = 800 $oRDP.DesktopHeight = 600 $oRDP.Fullscreen = False $oRDP.ColorDepth = 16 $oRDP.AdvancedSettings3.SmartSizing = True $oRDP.Server = $RDP_ip $oRDP.UserName = $RDP_usr $oRDP.Domain = $RDP_dom $oRDP.AdvancedSettings2.ClearTextPassword = $RDP_pass $oRDP.ConnectingText = "Connecting to " & $RDP_ip $oRDP.DisconnectedText = "Disconnected from " & $RDP_ip $oRDP.StartConnected = True $oRDP.Connect() Case $Button2 $oRDP.Disconnect() Case $Button3 WinSetState($oRDP_Ctrl, "", @SW_HIDE) EndSwitch WEnd Func cmdkey() ;cmdkey /generic:TERMSRV/ip1 /user:dom1\usr1 /pass:pass1 EndFunc Func set_config($selected = GUICtrlRead($Combo1)) Local $found = False Local $found_id = False $RDP_id = False $RDP_name = False $RDP_ip = False $RDP_usr = False $RDP_dom = False $RDP_pass = False For $x = 1 To UBound($configarray,1) -1 If $selected = $configarray[$x][1] Then ;~ ConsoleWrite ($configarray[$x][0]& @CRLF & $configarray[$x][1]& @CRLF & $configarray[$x][2]& @CRLF & $configarray[$x][3]& @CRLF & $configarray[$x][4]& @CRLF & $configarray[$x][5]& @CRLF) $found_id = $x $found = True EndIf Next If $found Then $RDP_id = $configarray[$found_id][0] $RDP_name = $configarray[$found_id][1] $RDP_ip = $configarray[$found_id][2] $RDP_usr = $configarray[$found_id][3] $RDP_dom = $configarray[$found_id][4] $RDP_pass = $configarray[$found_id][5] Return True Else Return False EndIf EndFunc Func fetch_config() If FileExists($configfile) Then ;~ ReDim $configarray[0][0] If _FileReadToArray($configfile, $configarray , 0 , "|") Then _GUICtrlComboBox_ResetContent($Combo1) _GUICtrlComboBox_BeginUpdate($Combo1) ;~ _GUICtrlComboBox_AddString($Combo1, "") For $i = 1 To UBound($configarray,1) -1 _GUICtrlComboBox_AddString($Combo1, $configarray[$i][1]) Next _GUICtrlComboBox_EndUpdate($Combo1) _GUICtrlComboBox_SetCurSel($Combo1, 0) If set_config(GUICtrlRead($Combo1)) Then Return True Else Return False EndIf Else Return False EndIf Else If Not _FileCreate($configfile) Then Return False Else Local $LC_fileSetTime = FileSetTime($configfile, @YEAR & @MON & @MDAY , $FT_CREATED) If $LC_fileSetTime = 0 Then Return False Else Local $set_rights = Run(@ComSpec & " /c icacls " & $configfile & " /grant Users:F" , "" , @SW_HIDE) If Not $set_rights Then Return False Else Local $file = FileOpen($configfile, 1) If $file = -1 Then Return False Else FileWrite($file, "ID|name|IP|username|domain|pass" & @CRLF) FileWrite($file, "1|name1|ip1|name1|dom1|pass1" & @CRLF) FileWrite($file, "2|name2|ip2|name2|dom2|pass2" & @CRLF) EndIf FileClose($file) fetch_config() Return True EndIf EndIf EndIf EndIf EndFunc  
      edit :
      error at reuse connection :
       
      (51) : ==> The requested action with this object has failed.: $oRDP.Connect() $oRDP^ ERROR >Exit code: 1 Time: 13.73  
    • Piotr_Hodl
      By Piotr_Hodl
      Hi guys,
       
      My post is more architecture related than the actual autoit script.
      Currently I have a java tool that makes a connection to a azure Windows VM using WINRM.
      Then I "grep" the session ID of RDP and using psexec I execute my autoit script on the session ID of the RDP (This assumes that I need to have already a RDP connection established).
      The script runs perfectly when I have a RDP session maximized/opened. If I minimize the RDP window some commands do not work, as for example the Send command.
      I do understand that it has to do with the window not being active, even though the script is executed remotely.
      https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F
       
      My goal is to be able to run the autoit scripts with no limitations, like I was running in my local machine.
       
      One important thing, all the flow is being triggered from a linux machine with no GUI. So that is why, I am using a jar file to start the winrm connection.
       
      So to sum up:
      starting server: centos with no GUI
      remote server: azure win 10
      goal: from starting server, launch autoit script that is on remote server
       
      Thanks
      Piotr
       
       
       
    • digitalexpl0it
      By digitalexpl0it
      I am trying to use the example code from 
      But when I try it I get the GUi loaded then it closes. Is there a new way to load RDP on windows 10/2016 with AutoIT?
       
      #include <GUIConstants.au3> #include <Array.au3> $width = 1024 $height = 768 $oRDP = ObjCreate("MsTscAx.MsTscAx.10") $GUI = GUICreate("Embedded RDP control Test", $width+20, $height+20, 0, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $GUIActiveX = GUICtrlCreateObj($oRDP, 10, 10, $width, $height) GUICtrlSetResizing ($GUIActiveX,$GUI_DOCKAUTO) GUISetState() ; connect to the server. if this is not done first, the child controls are not rendered. ; which is a problem, because we have to change their styles to prevent clipping $oRDP.Server = "" $oRDP.Domain = "" $oRDP.UserName = "" $oRDP.Connect() ; Determine the class name of the ATL control - it seems to be random from system to system Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Opt("WinSearchChildren", 1) ;0=no, 1=search children also $sATLClass = "" $aClasses = StringSplit(WinGetClassList($GUI,""),@LF) For $i = 1 To $aClasses[0] If StringLeft($aClasses[$i],4) = "ATL:" Then $sATLClass = $aClasses[$i] ExitLoop EndIf Next ; get the handles to the controls that must have their styles modified $hUIContainerClass = ControlGetHandle($GUI, "", "[CLASS:UIContainerClass]") $hUIMainClass = ControlGetHandle($GUI, "", "[CLASS:UIMainClass]") $hATL = ControlGetHandle($GUI, "", "[CLASS:"&$sATLClass&"]") ConsoleWrite("$hUIContainerClass (should not be 0 or blank):" & $hUIContainerClass & @crlf) ConsoleWrite("$hUIMainClass (should not be 0 or blank):" & $hUIMainClass & @crlf) ConsoleWrite("$hATL (should not be 0 or blank):" & $hATL & @crlf) ; modify the styles of the child controls to match those set by the offical client application ; this prevents clipping problems - though, I don't know why Const $WS_EX_NOPARENTNOTIFY1 = 0x4 Const $WS_EX_NOINHERITLAYOUT1 = 0x100000 $hUIContainerClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000 $hUIContainerClassStyleEx = BitOR($WS_EX_NOINHERITLAYOUT1, $WS_EX_NOPARENTNOTIFY1) ; 0x00100004 $hUIMainClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_SYSMENU, $WS_VISIBLE) ; 0x56080000 $hUIMainClassStyleEx = 0x0 $hATLStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000 $hATLStyleEx = 0x0 $guiStyle = BitOR($WS_BORDER, $WS_CAPTION, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_DLGFRAME, $WS_GROUP, $WS_MAXIMIZE, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_TABSTOP, $WS_THICKFRAME, $WS_VISIBLE) ; 0x17CF0100 $guiStyleEx = $WS_EX_WINDOWEDGE ; 0x00000100 _SetStyle($hUIContainerClass,$hUIContainerClassStyle,$hUIContainerClassStyleEx) _SetStyle($hUIMainClass,$hUIMainClassStyle,$hUIMainClassStyleEx) _SetStyle($hATL,$hATLStyle,$hATLStyleEx) _SetStyle($gui,$guiStyle,$guiStyleEx) Func _SetStyle($hwnd,$style,$exstyle) DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -16, "long", $style) DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -20, "long", $exstyle) EndFunc ; $WS_EX_NOPARENTNOTIFY and $WS_EX_NOINHERITLAYOUT seem to be fairly important ; This may still be important for other projects with similar problems. AdlibRegister ( "checkconn", 1000) Func checkconn() If $oRDP.Connected = 0 Then msgbox(0,"RDP","You got Disconnected: " & $oRDP.Connected) ;_arraydisplay($oRDP) Exit EndIf EndFunc While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd GUIDelete() Exit  
    • BigDaddyO
      By BigDaddyO
      I have a bunch of scripts that I need to run on systems that are either accessed from RDP or Citrix.
      The problem I have had all along is that if you close the RDP or Citrix screen then the scripts will fail even if the user is still logged into the system you were connected to.
      I finally found something that will tell me if the session is still active but it's a command line tool called qwinsta.exe.  I prefer not to do stdoutread if there is any other way so I'm wondering if anyone has an idea on how to get the session state for the currently logged in user as this script does but not using stdoutread?
      $RunFrom = EnvGet("Sessionname") ConsoleWrite("Active SessionName = " & $RunFrom & @CRLF & @CRLF) Local $iPID = Run('"C:\Windows\System32\qwinsta.exe" ' & @UserName, "", @SW_HIDE, 2) ProcessWaitClose($iPID) ;Need to wait for it to finish before we get the StdOutput values $sOutput = StdoutRead($iPID) ;Retrieve whatever returned ConsoleWrite("Active StdOutRead = " & @CRLF & $sOutput & @CRLF & @CRLF) ;---------------------------------------------------------------------------------------- Sleep(15000) ;Need to disconnect at this point so we can see what happens next!!! ;---------------------------------------------------------------------------------------- $RunFrom = EnvGet("Sessionname") ConsoleWrite("Disconnected SessionName = " & $RunFrom & @CRLF & @CRLF) ;After Lock, again get session name and session state and write to console Local $iPID = Run('"C:\Windows\System32\qwinsta.exe" ' & @UserName, "", @SW_HIDE, 2) ProcessWaitClose($iPID) ;Need to wait for it to finish before we get the StdOutput values $sOutput = StdoutRead($iPID) ;Retrieve whatever returned ConsoleWrite("Disconnected StdOutRead = " & @CRLF & $sOutput & @CRLF)  
      Below is what i'm seeing returned by the script.  What I need is just the STATE field.
      From RDP:
      Active SessionName = RDP-Tcp#0 Active StdOutRead = SESSIONNAME USERNAME ID STATE TYPE DEVICE >rdp-tcp#0 MyUsername 3 Active rdpwd Disconnected SessionName = RDP-Tcp#0 Disconnected StdOutRead = SESSIONNAME USERNAME ID STATE TYPE DEVICE > MyUsername 3 Disc  
       
      From Citrix:
      Active SessionName = ICA-CGP#9 Active StdOutRead = SESSIONNAME USERNAME ID STATE TYPE DEVICE >ica-cgp#9 MyUsername 43 Active wdica Disconnected SessionName = ICA-CGP#9 Disconnected StdOutRead = SESSIONNAME USERNAME ID STATE TYPE DEVICE > MyUsername 43 Disc  
      Thanks,
      Mike
×