Probleme mit Programm-Neustart Skript.

  • Hi,

    hab ein kleines Problem mit folgendem Skript. Wenn ich es über den Skript Editor starte funktioniert er Einwand frei.
    Sobald ich es in eine Exe kompiliere und ausführe stürzt es einfach nach Zeile 124 (dem DllCall) ohne Meldung ab.

    Hoffe Ihr könnt mir helfen.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstants.au3>
    #include <Array.au3>
    #include <WindowsConstants.au3>

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

    #cs ----------------------------------------------------------------------------
    AutoIt Version: 3.3.0.0
    #ce ----------------------------------------------------------------------------

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

    Opt("TrayIconDebug", 1)

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

    ;=========================================================================================================================
    ;Kommandozeilenparameter prüfen und Variablen setzen
    Global $v_GuiName = 'Outlook Start-Assistent'
    $a_outlook_profiles = _ArrayCreate('')
    $v_def_profile = RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles', 'DefaultProfile')
    $v_Outlook_Home = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE', 'Path')

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

    For $i = 1 to 10
    $var = RegEnumKey('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles', $i)
    If @error <> 0 Then ExitLoop
    If RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\' & $var & '\13dbb0c8aa05101a9bb000aa002fc45a', '001e6750') <> '' Then
    If $var = $v_def_profile Then $var = $var & ' (Default)'
    _ArrayAdd($a_outlook_profiles, $var)
    EndIf
    Next

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

    ;~ #################################################################################
    ;~ Gui1
    $gui_high = 170
    If UBound($a_outlook_profiles) > 2 Then $gui_high = $gui_high + (20 * (UBound($a_outlook_profiles) - 2 ))
    If $gui_high > 600 Then $gui_high = 600

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

    $Gui1 = GUICreate($v_GuiName, 260, $gui_high, -1, -1, -1)
    $l_Gui1 = GUICtrlCreateLabel('Folgende Profile sind konfiguriert.' & @CRLF & 'Wählen Sie eine zum start von Outlook aus.', 30, 10)

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

    Global $radio[UBound($a_outlook_profiles)]
    Global $high = 30
    For $i = 1 To UBound($a_outlook_profiles) - 1
    $high = $high + 20
    $radio[$i] = GUICtrlCreateRadio($a_outlook_profiles[$i], 30, $high, 120, 20)
    If StringInStr($a_outlook_profiles[$i], ' (Default)') Then GUICtrlSetState($radio[$i], $GUI_CHECKED)
    Next

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

    $l_Parameter = GUICtrlCreateLabel('Parameter:', 10, $high + 33, 50, 20)
    $ib_Parameter = GUICtrlCreateInput('', 65, $high + 30, 155, 20)
    $b_Parameter_List = GUICtrlCreateButton('...', 225, $high + 30, 20, 20)

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

    $b_outlook_start = GUICtrlCreateButton('Profil starten', 15, $high + 60, 230, 20)

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

    $schliessen = GUICtrlCreateButton("Schließen", 95, $high + 90, 70, 20)

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

    GUISetState(@SW_SHOW, $Gui1)

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

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $b_Parameter_List
    Run('notepad.exe ParameterAll.txt', @ScriptDir, @SW_SHOW)
    Case $b_outlook_start
    If ProcessExists('OUTLOOK.EXE') Then
    SplashTextOn('Outlook', 'Outlook wird neu gestartet.' & @CRLF & 'Bitte warten...', 300, 50, -1, -1, 34, '', 11)
    Else
    SplashTextOn('Outlook', 'Outlook wird gestartet.' & @CRLF & 'Bitte warten...', 300, 50, -1, -1, 34, '', 11)
    EndIf

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

    ProcessQuit('OUTLOOK.EXE')
    Sleep(3000)

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

    While ProcessExists('OUTLOOK.EXE')
    ProcessClose('OUTLOOK.EXE')
    Sleep(2000)
    WEnd

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

    For $i = 1 To UBound($a_outlook_profiles) - 1
    If GUICtrlRead($radio[$i]) = 1 Then $v_start_profile = $a_outlook_profiles[$i]
    Next
    MsgBox(0, '', $v_start_profile)
    If StringInStr($v_start_profile, ' (Default)') Then
    Run($v_Outlook_Home & 'OUTLOOK.EXE ' & GUICtrlRead($ib_Parameter))
    Else
    Run($v_Outlook_Home & 'OUTLOOK.EXE /Profile "' & $v_start_profile & '" ' & GUICtrlRead($ib_Parameter))
    EndIf
    SplashOff()
    Case $GUI_EVENT_CLOSE, $schliessen
    Exit
    EndSwitch
    WEnd

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

    Func ProcessGetWindows($PId)
    $PId = ProcessExists($PId)
    If $PId = 0 Then
    SetError(1)
    Else
    Local $WinList = WinList()
    Local $WindowTitle[1][2]
    Local $x = 0

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

    For $i = 1 To $WinList[0][0]
    If WinGetProcess($WinList[$i][1], "") = $PId And $WinList[$i][0] <> ""Then
    ReDim $WindowTitle[$x+1][2]
    $WindowTitle[$x][0] = $WinList[$i][0]
    $WindowTitle[$x][1] = $WinList[$i][1]
    $x += 1
    EndIf
    Next

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

    Return $WindowTitle
    EndIf
    EndFunc

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

    Func ProcessQuit($filename)
    $Return=0
    $a = ProcessList($filename)

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

    For $i = 1 To UBound($a) - 1
    $Return = ProcessGetWindows($a[$i][1])
    Next

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

    If($Return==0) Then
    Return
    EndIf

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

    DllCall("User32.dll", "int", "PostMessageA", "hwnd", $Return[0][1], "int", $WM_QUIT, "int", "", "int", "")
    EndFunc

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

    Einmal editiert, zuletzt von Herra (9. März 2009 um 11:15)

  • Hallo Herra.

    1.)
    Habt etwas mehr Geduld, denn Ungeduld bringt nichts. Man muß sich auch erst einmal in das Script lesen

    2.)
    Wo ist die fehlermeldung die die angegeben wird.
    In Deinem Fall bezieht sich die Fehlermeldung auf MsgBox(0,$v_start_profile) mit dem Hinweis "Error:Variable used without being declared".

    Evtl. hilft Dir das ja schon etwas weiter. Ansonsten wirklich etwas Geduld haben.

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    k3mrwmIBHejryPvylQSFieDF5f3VOnk6iLAVBGVhKQegrFuWr3iraNIblLweSW4WgqI0SrRbS7U5jI3sn50R4a15Cthu1bEr

  • Hi Alina,

    entschuldigt meine Ungeduld ;)

    Also MsgBox(0,$v_start_profile) habe ich nur zu Testzwecken eingefügt. Die bringt bei mir keine Fehlermeldung.

    Wie oben geschrieben, es wird gar keine Fehlermeldung ausgegeben.

    ...Wenn ich es über den Skript Editor starte funktioniert er Einwand frei.
    Sobald ich es in eine Exe kompiliere und ausführe stürzt es einfach nach Zeile 124 (dem DllCall) ohne Meldung ab.

    Danke und Gruß
    Herra

  • Was gendenkst du mit folgendem zu bezwecken:

    [autoit]

    For $i = 1 To UBound($a) - 1
    $Return = ProcessGetWindows($a[$i][1])
    Next

    [/autoit]

    ?

    Mit jedem Durchlauf wird $Return überschrieben und nur der letzte Eintrag wird dann im DLLCall verwendet.

    Welchen Wert hat $Return in Zeile 119?

    Ich kann da leider nix testen, weil ich kein Outlook hab ;)

    lgE

  • Habe den Fehler gefunden. Ich bin ja so doooooof :rofl:
    Habe meinen Skript auch Outlook.exe genannt. Dadurch hat sich der Skript immer selbst beendet.

    eukalyptus
    Du hast recht, diese Funktionen habe ich aber nicht selbst erstellt, sondern habe sie im Forum gefunden.
    Die Schleife soll eigentlich prüfen, ob der Prozess öfter läuft, ist aber nicht schön gemacht, da er immer den letzten schließt den er findet.
    Ich muss das mal ein bisschen umschreiben.

    Danke euch für die Hilfe.
    cu Herra