Bitte um Hilfe bei einem eigenen Skript

  • Hallo liebe Leute,

    ich habe folgende Problematik bei meinem Skript, das von der Komanndozeile mit zwei Argumenten gestartet wird:
    Das Skript wird mehrfach (in 20 Sekunden Abständen gestartet).
    Leider, trotz Nutzung von Handles, klappt der Ablauf nicht bei parallel laufenden Versionen des Skripts.

    Ich weiß leider momentan nicht mehr weiter, warum, die "ControlSend"´s und "WinClose"`s nicht das richtige Ziel, trotz Handle,
    finden.

    Ich bitte um Hilfe!
    Vielen Dank im Voraus.

    VG
    Mikee


  • Also zuerst mal Herzlich Willkommen im Forum ;)

    In dem Script sind einige Dinge die sehr fehleranfällig sind.
    z.B. in eine ein Textfile mithilfe von notepad zu bearbeiten
    Dafür gibt es Funktionen wie: Filewrite.

    Auch das ControlgetHandle wird/kann Probleme verursachen, da du keine ControlId angibst (der 3te Parameter der bei dir "" ist)
    Und ein Skript öfter starten muss im Normalfall auch nicht sein.

    Vielleicht wäre es ganz gut wenn du beschreibst was genau das Script alles machen soll.
    Ich denke da lässt sich einiges optimieren ;)

    Edit:
    und bitte beim nächsten mal Spoiler und Autoit-Code-Boxen verwenden
    also die beiden hier:
    [Blockierte Grafik: http://www.autoit.de/wcf/icon/wysiwyg/insertSpoilerM.png][Blockierte Grafik: http://www.autoit.de/wcf/icon/wysiwyg/insertAutoItM.png]

  • Hi @all!

    Danke für euer schnelles Feedback! ;)

    Also, ich versuche mal zu erläutern, was mit dem Skript machen möchte.

    1. Ich nutze ein Windows-Batch-Skript, das die verschiedenen Auto-It-Instanzen startet.Diese Übergibt dem Auto-It-Skript zwei Argumente. Der Autoit-Aufruf würde ungefähr so aussehen.

    Code
    C:\Programme\AutoIt3\AutoIt3.exe  C:\temp\autoit\\ica-Check_Uebergabe.au3 "C:\Programme\Citrix\ICA Client\wfica32.exe C:\temp\autoit\ica\test1.ica" "Test1 User"

    Inhalt des Batch-Skripts:

    2.Das Auto-It-Skript nutzt die übergebenen Argumente um einem Citrix-ICA-Fenster mit einem Titel (enthält Argument 2) Keystrokes zu übergeben. Ziel: Beenden von Programmen und Abmelden des Benutzers aus der Session.

    3. Nachdem das ICA-Fenster geschlossen wurde wird eine Text-Datei mit Argument2 als Titelnamen erstellt und Text eingefügt, letzendlich abgespeichert und die Notepad-Session beendet.


    --> Starte ich eine Autoit-Skript-Instanz klappt es, Je mehr dazukommen, desto häufiger gibt es Kuddelmuddel (Bspw. wird Text in die Notepad-Datei geschrieben und Keystrokes aus den Ica-Sessions fliegen rein, oder ähnliches.)

    Grüße
    Mikee

  • Ich habe jetzt die Funktion NotepadSession mit fileopen und filewrite ausgestattet. Das klappt schon mal gut!

    Code
    Func _NotepadSession($notepadtext1)
    	$file = FileOpen("c:\temp\autoit\status-files\"& $CmdLine[2] &".txt", 1)
    	If $file = -1 Then
    		MsgBox(0, "Error", "Unable to open file.")
    		Exit
    	EndIf
    	FileWrite($file, ""& $notepadtext1 &"")
    	FileClose($file)
    EndFunc


    Wie sollte ich Eurer Meinung nach, die Keystrokes an die ICA-Fenster übergeben?

    Kijan:
    WingetProces() liefert mir die PID des Fensters, aber wie bekomme ich das mit dem Senden von Keys an das passende Fenster hin?

    Grüße an alle!

    Mikee

  • in etwa so zb

    Spoiler anzeigen
    [autoit]

    #include <Process.au3>
    #include <Array.au3>
    AutoItSetOption("WinTitleMatchMode", 4)
    Run("notepad.exe")
    WinWaitActive("[CLASS:Notepad]", "")
    $pid = WinGetProcess("[CLASS:Notepad]", "")
    $name = _ProcessGetName($pid)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $myWinList = _WinListWithPID()
    $find = _ArraySearch($myWinList,$pid,0,0,0,0,1,2)

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "Notepad - " & $pid, "Name: " & $myWinList[$find][0] & @CRLF & _
    "WinHandle: " & $myWinList[$find][1] & @CRLF & _
    "PID: " & $myWinList[$find][2])

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinListWithPID()
    $aWin = WinList()
    Redim $aWin[Ubound($aWin, 1)][3]
    For $n = 1 to (Ubound($aWin, 1) - 1)
    $aWin[$n][2] = WinGetProcess($aWin[$n][1])
    Next
    Return $aWin
    EndFunc

    [/autoit]

    so könntest das handle erlangen und weiter weist doch bestimmt alleine^^

  • Okay, so scheint es zu funktionieren..... Danke schon mal an alle! ;)

    [autoit]

    ;~ Auto-It-Skript, daß eine ICA-Datei startet und die Session wieder beendet.

    [/autoit][autoit][/autoit][autoit]

    AutoItSetOption ("WinTextMatchMode", 2 )

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    dim $text
    dim $notepadtext1
    dim $notepadtext2
    dim $notepadtext3
    dim $handle0
    dim $handle1
    dim $handle2
    dim $handle3
    dim $handle4
    dim $file
    dim $pid

    [/autoit][autoit][/autoit][autoit]

    $text=""
    $notepadtext1=""& @ComputerName &" ICA_"& $CmdLine[2] &" 0 Check OK. ICA-Session wurde sauber beendet."
    $notepadtext2=""& @ComputerName &" ICA_"& $CmdLine[2] &" 2 Check fehlerhaft. ICA-Session wurde nicht aufgebaut."
    $notepadtext3=""& @ComputerName &" ICA_"& $CmdLine[2] &" 1 Check mit Problemen. ICA-Session noch offen."

    [/autoit][autoit][/autoit][autoit]

    Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
    EndFunc

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _NotepadSession($notepadtext1)
    $file = FileOpen("c:\temp\autoit\status-files\"& $CmdLine[2] &".txt", 1)
    If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
    EndIf
    FileWrite($file, ""& $notepadtext1 &"")
    FileClose($file)
    EndFunc

    [/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit][autoit]

    ;~ Töten von alten Fenstern, die im Skript relevant sein können.
    WinKill($CmdLine[2],"")

    [/autoit][autoit][/autoit][autoit]

    ;~ Start der ICA-Session
    Run($CmdLine[1])
    _WinWaitActivate($CmdLine[2],"")
    $pid = WinGetProcess(""& $CmdLine[2] &"", "")
    $handle0 = ControlGetHandle(""& $CmdLine[2] &"", "", "")

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    Sleep(110000)
    EndIf

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ESC}")
    sleep(400)
    EndIf

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ESC}")
    sleep(400)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{CTRLDOWN}{F1}")
    sleep(100)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{CTRLDOWN}{CTRLUP}")
    sleep(400)
    EndIf

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{TAB}")
    sleep(400)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ENTER}")
    sleep(400)
    EndIf

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ENTER}")
    sleep(400)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{CTRLDOWN}{F1}")
    sleep(100)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{CTRLDOWN}{CTRLUP}")
    sleep(400)
    EndIf

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{TAB}")
    sleep(400)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ENTER}")
    sleep(400)
    EndIf

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ENTER}")
    sleep(400)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ESC}")
    sleep(400)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ENTER}")
    sleep(200)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    ControlFocus ("","",$handle0)
    ControlSend( "", "", $handle0, "{ENTER}")
    sleep(5000)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    Else
    _NotepadSession($notepadtext2)
    Sleep(100)
    Exit
    EndiF

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Sleep(5000)

    [/autoit][autoit][/autoit][autoit]

    If FileExists("c:\temp\autoit\status-files\"& $CmdLine[2] &".txt") Then
    FileDelete("c:\temp\autoit\status-files\"& $CmdLine[2] &".txt")
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If ProcessExists($pid) Then
    If @error = 0 Then
    _NotepadSession($notepadtext3)
    Sleep(100)
    Exit
    EndIf
    Else
    If @error = 0 Then
    _NotepadSession($notepadtext1)
    Sleep(100)
    Exit
    EndIf

    [/autoit][autoit][/autoit][autoit]

    EndIf
    Exit

    [/autoit]
  • Bitte bei längeren Quelltexten immer Spoiler verwenden.
    Einfach mit dem Button: [Blockierte Grafik: http://www.autoit.de/wcf/icon/wysiwyg/insertSpoilerM.png]

    Einen Thread kannst du auf gelöst setzen indem du den ersten Post bearbeitest, als Präfix gelöst auswählst und das ganze Speicherst/Sendest.