GUI kann "nur" einmal ausgeführt werden

  • Hallo Zusammen,

    irgendwie bin ich zu blöd. Ich bin derzeit am schreiben eines Scripts das meine GUI ausliest und dann die Daten die dort eingegeben worden sind per Mail zu verschicken. Jetzt probiere ich gerade ein Feld ($nm_firstname = GUICtrlCreateInput("", 144, 72, 121, 21)) "Vorname" als Pflichtfeld zu hinterlegen.

    Das sieht bei mir dann so aus:

    Spoiler anzeigen
    [autoit]


    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    ;##################################
    ;GUI auslesen
    ;##################################
    $nm_firstname = GUICtrlRead($nm_firstname)
    If $nm_firstname = "" Then
    MsgBox(16, "Sie haben ein Pflichtfeld vergessen", "Der Vorname des Mitarbeiters ist ein Pflichtfeld")
    _main ()
    Exit
    EndIf
    $nm_lastname = GUICtrlRead($nm_lastname)
    $nm_username = GUICtrlRead($nm_username)
    $nm_entry = GUICtrlRead($nm_entry)
    $akt_firstname = GUICtrlRead($akt_firstname)
    $akt_lastname = GUICtrlRead($akt_lastname)
    $akt_username = GUICtrlRead($akt_username)
    $domain_acc = GUICtrlRead($domain_acc)
    $LN_acc = GUICtrlRead($LN_acc)
    $psnext_acc = GUICtrlRead($psnext_acc)
    $vpn_acc = GUICtrlRead($vpn_acc)
    $telefon = GUICtrlRead($telefon)
    ; $ln_grouplist = GUICtrlRead($ln_grouplist)
    $adminlist = GUICtrlRead($adminlist)
    ;$admin_pw = GUICtrlRead($admin_pw)
    $FromName = $adminlist ; name from who the email was sent
    ;Umwandeln des Namens in Mailadresse
    Local $fname = StringSplit($adminlist, " ")
    $Mailname = $fname[1] & "." & $fname[2]
    $Mailname = StringLower($Mailname)
    $Mailname = $Mailname & "@gmail.com"
    Global $FromAddress = $Mailname ; address from where the mail should come
    Global $Username = $adminlist ; username for the account used from where the mail gets sent - REQUIRED
    Global $Password = "" ; password for the account used from where the mail gets sent - REQUIRED
    Global $BccAddress = $Mailname ; address for bcc - leave blank if not needed
    Local $sItems, $aItems, $hListBox
    $aItems = _GUICtrlListBox_GetSelItemsText($ln_grouplist)
    For $iI = 1 To $aItems[0]
    If $iI > 1 Then $sItems &= ", "
    $sItems &= $aItems[$iI]
    $ln_grouplist = $sItems
    Next
    _check ()
    MsgBox(0, "neue Accounts bestellt", "Alle Emails wurden erfolgreich gesendet. Bitte eigenen Posteingang prüfen.")
    Exit
    Case $Exit
    Exit
    EndSwitch
    WEnd

    [/autoit]


    In dieser Variante springt er zum Anfang zurück. Aber, er öffnet ein weiteres Fenster. Ich habe bereits auch andere Varianten probiert, allerdings habe ich das Gefühl das die GUI immer nur einmal ausgelesen wird.

    Fülle ich die GUI ganz normal aus und drücke start läuft das Script durch. Fülle ich die GUI erneut anders aus sind alle Eingabefelder = "0".

    Freue mich über sinnvolle Antworten.

    3 Mal editiert, zuletzt von AyKay (22. Juli 2013 um 15:51)

  • Zeile 49. Du gehst auch mit Exit raus. Und was soll Zeile 13+14. Wozu _main, wenn du sowieso das Script beendest?

  • Sorry, das mit dem Quellcode hab ich verplant. Habs im ersten Thread auch schon angepasst.

    Hier jetzt das komplette Script(gerne nehme ich auch allgemeine Verbesserungsvorschläge an):

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <DateTimeConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <GUIListView.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Include<file.au3>
    ;##################################
    ;GUI Design
    ;##################################
    Global $nm_firstname, $nm_lastname, $nm_username, $nm_entry, $no_reference, $akt_firstname, $akt_lastname, $akt_username, $domain_acc, $LN_acc, $ln_grouplist, $psnext_acc, $vpn_acc, $telefon, $adminlist, $Start, $Exit
    Global $customersupport, $psnextadmin
    Global $SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl
    _main ()

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

    Func _main ()
    #Region ### START Koda GUI section ### Form=h:\1data\public\autoit\forms\new_user.kxf
    $Form1_1 = GUICreate("Bestellung neuer Accounts", 1051, 511, 190, 123)
    $nm_firstname = GUICtrlCreateInput("", 144, 72, 121, 21)
    $nm_lastname = GUICtrlCreateInput("", 144, 112, 121, 21)
    $nm_username = GUICtrlCreateInput("", 144, 152, 121, 21)
    GUICtrlSetLimit(-1, 9)
    $nm_entry = GUICtrlCreateDate(@MDAY, 144, 192, 186, 21)
    $no_reference = GUICtrlCreateCheckbox("Kein Referenzbenutzer", 424, 72, 153, 17)
    $akt_firstname = GUICtrlCreateInput("", 480, 112, 121, 21)
    $akt_lastname = GUICtrlCreateInput("", 480, 152, 121, 21)
    $akt_username = GUICtrlCreateInput("", 480, 192, 121, 21)
    GUICtrlSetLimit(-1, 9)
    $domain_acc = GUICtrlCreateCheckbox("", 256, 256, 97, 17)
    $LN_acc = GUICtrlCreateCheckbox("", 256, 296, 97, 17)
    $ln_grouplist = GUICtrlCreateList("", 72, 328, 273, 149, BitOR($GUI_SS_DEFAULT_LIST,$LBS_MULTIPLESEL))
    GUICtrlSetData(-1, "LN-Group1|LN-Group2|LN-Group3|LN-Group4")
    $psnext_acc = GUICtrlCreateCheckbox("", 544, 256, 97, 17)
    $vpn_acc = GUICtrlCreateCheckbox("", 544, 296, 97, 17)
    $telefon = GUICtrlCreateCheckbox("", 544, 336, 97, 17)
    $adminlist = GUICtrlCreateList("", 808, 72, 121, 58)
    GUICtrlSetData(-1, "Admin1|Admin2|Admin3|Admin4")
    ;$admin_pw = GUICtrlCreateInput("", 808, 152, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) ;Wird nicht benötigt
    $Start = GUICtrlCreateButton("Start", 800, 272, 193, 73)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    $Exit = GUICtrlCreateButton("Exit", 800, 368, 193, 73)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Vorname*:", 56, 72, 49, 17)
    $Label2 = GUICtrlCreateLabel("Nachname*:", 56, 112, 59, 17)
    $Label3 = GUICtrlCreateLabel("Username*:", 56, 152, 55, 17)
    $Label4 = GUICtrlCreateLabel("Eintritt:", 56, 192, 36, 17)
    $Label5 = GUICtrlCreateLabel("Vorname:", 392, 112, 49, 17)
    $Label6 = GUICtrlCreateLabel("Nachname:", 392, 152, 59, 17)
    $Label7 = GUICtrlCreateLabel("Username:", 392, 192, 55, 17)
    $Label8 = GUICtrlCreateLabel("versenden von:", 712, 72, 78, 17)
    ;$Label9 = GUICtrlCreateLabel("Passwort:", 712, 152, 50, 17) ;Wird nicht benötigt
    $Label10 = GUICtrlCreateLabel("New Domain Account", 72, 256, 108, 17)
    $Label11 = GUICtrlCreateLabel("New Lotus Notes Account", 72, 296, 129, 17)
    $Label12 = GUICtrlCreateLabel("New PSNext Account", 376, 256, 108, 17)
    $Label13 = GUICtrlCreateLabel("New VPN Account", 376, 296, 94, 17)
    $neuer = GUICtrlCreateGroup("neuer Mitarbeiter", 40, 40, 313, 201)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group1 = GUICtrlCreateGroup("Berechtigung übernehmen von", 376, 40, 265, 201)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Label14 = GUICtrlCreateLabel("New phone", 376, 336, 59, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    ;##################################
    ;Standardvariablen
    ;##################################
    $SmtpServer = "xxx.xxx.xxx.xxx" ; address for the smtp-server to use - REQUIRED
    $Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
    $CcAddress = "" ; address for cc - leave blank if not needed
    $IPPort = 25 ; port used for sending the mail
    $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS
    ;~ $IPPort=465 ; GMAIL port used for sending the mail
    ;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
    $customersupport = "test@gmail.com"
    $psnextadmin = "test@gmail.com"

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

    ;##################################
    ;Username überprüfen
    ;##################################
    $WMI = ObjGet("WinMgmts:root/cimv2")
    $colQuery1 = $WMI.ExecQuery("Select UserName FROM Win32_ComputerSystem")
    For $item In $colQuery1
    $ID = $item.UserName
    Next
    $colQuery2 = $WMI.ExecQuery("Select * FROM Win32_NetworkLoginProfile")
    For $object In $colQuery2
    If $object.Name = $ID Then ;MsgBox(0, "", $object.Fullname)
    $Name = $object.Fullname
    EndIf
    Next

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

    ;##################################
    ;Checkboxen aktivieren / aktuellen Benutzer selektieren
    ;##################################
    GUICtrlSetData($adminlist, $Name)
    _GUICtrlListBox_SetSel($ln_grouplist, 3)
    GUIctrlsetstate($domain_acc, $GUI_CHECKED)
    GUIctrlsetstate($LN_acc, $GUI_CHECKED)
    GUIctrlsetstate($psnext_acc, $GUI_CHECKED)
    GUIctrlsetstate($vpn_acc, $GUI_CHECKED)
    GUIctrlsetstate($telefon, $GUI_CHECKED)

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

    ;##################################
    ;Waren auf Knopfdruck
    ;##################################
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $no_reference
    If GUICtrlRead($no_reference) = 1 Then
    GUIctrlsetstate($akt_firstname, $GUI_DISABLE)
    GUIctrlsetstate($akt_lastname, $GUI_DISABLE)
    GUIctrlsetstate($akt_username, $GUI_DISABLE)
    Else
    GUIctrlsetstate($akt_firstname, $GUI_ENABLE)
    GUIctrlsetstate($akt_lastname, $GUI_ENABLE)
    GUIctrlsetstate($akt_username, $GUI_ENABLE)
    EndIf
    Case $Start
    ;##################################
    ;GUI auslesen
    ;##################################
    $nm_firstname = GUICtrlRead($nm_firstname)
    If $nm_firstname = "" Then
    MsgBox(16, "Sie haben ein Pflichtfeld vergessen", "Der Vorname des neuen Mitarbeiters ist ein Pflichtfeld")
    _main ()
    Exit
    EndIf
    $nm_lastname = GUICtrlRead($nm_lastname)
    $nm_username = GUICtrlRead($nm_username)
    $nm_entry = GUICtrlRead($nm_entry)
    $akt_firstname = GUICtrlRead($akt_firstname)
    $akt_lastname = GUICtrlRead($akt_lastname)
    $akt_username = GUICtrlRead($akt_username)
    $domain_acc = GUICtrlRead($domain_acc)
    $LN_acc = GUICtrlRead($LN_acc)
    $psnext_acc = GUICtrlRead($psnext_acc)
    $vpn_acc = GUICtrlRead($vpn_acc)
    $telefon = GUICtrlRead($telefon)
    $adminlist = GUICtrlRead($adminlist)
    $FromName = $adminlist ; name from who the email was sent
    ;Umwandeln des Namens in Mailadresse
    Local $fname = StringSplit($adminlist, " ")
    $Mailname = $fname[1] & "." & $fname[2]
    $Mailname = StringLower($Mailname)
    $Mailname = $Mailname & "@gmail.com"
    Global $FromAddress = $Mailname ; address from where the mail should come
    Global $Username = $adminlist ; username for the account used from where the mail gets sent - REQUIRED
    Global $Password = "" ; password for the account used from where the mail gets sent - REQUIRED
    Global $BccAddress = $Mailname ; address for bcc - leave blank if not needed
    Global $signatur = FileRead("C:\Tools\Bestellung neuer Accounts\" & $adminlist & ".txt")
    Local $sItems, $aItems, $hListBox
    $aItems = _GUICtrlListBox_GetSelItemsText($ln_grouplist)
    For $iI = 1 To $aItems[0]
    If $iI > 1 Then $sItems &= ", "
    $sItems &= $aItems[$iI]
    $ln_grouplist = $sItems
    Next
    If $LN_acc = $GUI_CHECKED And $ln_grouplist = "12" Then
    MsgBox(16, "Keine Gruppe für Lotus Notes gewählt", "Das Programm wird geschlossen da keine Gruppe für Lotus Notes gewählt wurde.")
    Exit
    EndIf
    _check ()
    MsgBox(0, "neue Accounts bestellt", "Alle Emails wurden erfolgreich gesendet. Bitte eigenen Posteingang prüfen.")
    Exit
    Case $Exit
    Exit
    EndSwitch
    WEnd

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

    ;##################################
    ;Überprüfen welche Checkbox aktiv ist und dann entsprechende Funktion aufrufen
    ;##################################
    Func _check ()
    If $domain_acc = "1" Then
    _domainacc ()
    EndIf
    If $LN_acc = "1" Then
    _notesacc ()
    EndIf
    If $psnext_acc = "1" Then
    _psnextacc ()
    EndIf
    If $vpn_acc = "1" Then
    _vpnacc ()
    EndIf
    If $telefon = "1" Then
    _telefon ()
    EndIf
    EndFunc

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

    ;##################################
    ;Domainaccount bestellen
    ;##################################
    Func _domainacc ()
    ;Setze Variablen für Mail
    $textteil1 = "Sehr geehrte Damen und Herren," & @CRLF & @CRLF & "blabla" & @CRLF
    $textteil2 = "Name: " & $nm_lastname & @CRLF
    $textteil3 = "Vorname: " & $nm_firstname & @CRLF
    $textteil4 = "Username: " & $nm_username & @CRLF
    $textteil5 = "blabla" & @CRLF
    $textteil6 = "Eintritt: " & $nm_entry & @CRLF
    If GUICtrlRead($no_reference) = $GUI_CHECKED Then
    $textteil7 = ""
    Else
    $textteil7 = "Bitte übernehmen Sie die Berechtigungen von: " & $akt_firstname & " " & $akt_lastname & " " & $akt_username & "." & @CRLF
    EndIf
    $textteil8 = @CRLF & "Danke im Voraus."

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

    $bodytext = $textteil1 & $textteil2 & $textteil3 & $textteil4 & $textteil5 & $textteil6 & $textteil7 & $textteil8 & $signatur
    $ToAddress = $customersupport ; destination address of the email - REQUIRED
    $Subject = "New Domain Account " & $nm_firstname & " " & $nm_lastname & " " & $nm_username ; subject from the email - can be anything you want it to be
    $Body = $bodytext ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
    ;##################################
    ; Aufruf Sendmail
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf
    EndFunc

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

    ;##################################
    ;Lotus Notes Account bestellen
    ;##################################
    Func _notesacc ()
    ;Setze Variablen für Mail
    $textteil1 = "Sehr geehrte Damen und Herren," & @CRLF & @CRLF & "blabla" & @CRLF
    $textteil2 = "Name: " & $nm_lastname & @CRLF
    $textteil3 = "Vorname: " & $nm_firstname & @CRLF
    $textteil4 = "Eintritt: " & $nm_entry & @CRLF
    $textteil5 = "blabla" & @CRLF
    $textteil6 = "blabla" & @CRLF
    $textteil7 = "Aufnahme in die Mailgruppe(n): " & $ln_grouplist & @CRLF
    $textteil8 = @CRLF & "Danke im Voraus."
    $bodytext = $textteil1 & $textteil2 & $textteil3 & $textteil4 & $textteil5 & $textteil6 & $textteil7 & $textteil8 & $signatur
    $ToAddress = $customersupport ; destination address of the email - REQUIRED
    $Subject = "New Notes Account " & $nm_firstname & " " & $nm_lastname ; subject from the email - can be anything you want it to be
    $Body = $bodytext ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
    ;##################################
    ; Aufruf Sendmail
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf
    EndFunc

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

    ;##################################
    ;PSNext Account bestellen
    ;##################################
    Func _psnextacc ()
    ;Setze Variablen für Mail
    $textteil1 = "blabla" & @CRLF & @CRLF & "blabla " & @CRLF
    $textteil2 = "Name: " & $nm_lastname & @CRLF
    $textteil3 = "Vorname: " & $nm_firstname & @CRLF
    $textteil4 = "Username: " & $nm_username & @CRLF
    $textteil5 = "blabla" & @CRLF
    $textteil6 = @CRLF & "Danke im Voraus."
    $bodytext = $textteil1 & $textteil2 & $textteil3 & $textteil4 & $textteil5 & $textteil6 & $signatur
    $ToAddress = $psnextadmin ; destination address of the email - REQUIRED
    $Subject = "blabla " & $nm_firstname & " " & $nm_lastname & " " & $nm_username ; subject from the email - can be anything you want it to be
    $Body = $bodytext ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
    ;##################################
    ; Aufruf Sendmail
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf
    EndFunc

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

    ;##################################
    ;VPN Account bestellen
    ;##################################
    Func _vpnacc ()
    ;Setze Variablen für Mail
    $textteil1 = "Sehr geehrte Damen und Herren," & @CRLF & @CRLF & "blabla:" & @CRLF
    $textteil2 = "Name: " & $nm_lastname & @CRLF
    $textteil3 = "Vorname: " & $nm_firstname & @CRLF
    $textteil4 = "Username: " & $nm_username & @CRLF & @CRLF
    $textteil5 = "blabla" & @CRLF
    $textteil6 = @CRLF & "Danke im Voraus."
    $bodytext = $textteil1 & $textteil2 & $textteil3 & $textteil4 & $textteil5 & $textteil6 & $signatur
    $ToAddress = $psnextadmin ; destination address of the email - REQUIRED
    $Subject = "blabla " & $nm_firstname & " " & $nm_lastname & " " & $nm_username ; subject from the email - can be anything you want it to be
    $Body = $bodytext ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
    ;##################################
    ; Aufruf Sendmail
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf
    EndFunc

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

    ;##################################
    ;Telefon bestellen
    ;##################################
    Func _telefon ()
    ;Setze Variablen für Mail
    $textteil1 = "Sehr geehrte Damen und Herren," & @CRLF & @CRLF & "blabla" & @CRLF
    $textteil2 = "Name: " & $nm_lastname & @CRLF
    $textteil3 = "Vorname: " & $nm_firstname & @CRLF
    $textteil4 = "Username: " & $nm_username & @CRLF
    $textteil5 = "Eintritt: " & $nm_entry & @CRLF & @CRLF
    $textteil6 = "blabla" & @CRLF
    $textteil7 = @CRLF & "Danke im Voraus."
    $bodytext = $textteil1 & $textteil2 & $textteil3 & $textteil4 & $textteil5 & $textteil6 & $textteil7 & $signatur
    $ToAddress = $psnextadmin ; destination address of the email - REQUIRED
    $Subject = "New telephone " & $nm_firstname & " " & $nm_lastname ; subject from the email - can be anything you want it to be
    $Body = $bodytext ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
    ;##################################
    ; Aufruf Sendmail
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf
    EndFunc

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

    ;##################################
    ;Sendmail
    ;##################################
    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
    $objEmail.HTMLBody = $as_Body
    Else
    $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
    Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
    For $x = 1 To $S_Files2Attach[0]
    $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
    ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
    If FileExists($S_Files2Attach[$x]) Then
    ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
    $objEmail.AddAttachment($S_Files2Attach[$x])
    Else
    ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
    SetError(1)
    Return 0
    EndIf
    Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
    Case "High"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
    Case "Normal"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
    Case "Low"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
    SetError(2)
    Return $oMyRet[1]
    EndIf
    $objEmail=""
    EndFunc ;==>_INetSmtpMailCom

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

    ; Com Error Handler
    Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
    EndFunc ;==>MyErrFunc

    [/autoit]

    Einmal editiert, zuletzt von AyKay (22. Juli 2013 um 14:20)

  • Ein Tipp, auch wenn dir das nicht sehr viel helfen wird: Initialisiere die GUI nur 1x.
    Du kannst sie mit

    [autoit]

    GUISetState(@SW_HIDE)

    [/autoit]

    verstecken und mit

    [autoit]

    GUISetState(@SW_SHOW)

    [/autoit]

    anzeigen.

    Sonst hast du nämlich eine Rekursion drinne und nach etwa 1900 mal aufrufen der _main()-Funktion beendet sich das Programm automatisch damit das Rekursionslevel erreicht ist.

  • Ja, von mir aus mach ich _main komplett raus. Ich will das auch nicht mehrfach ausführen. Es geht mir darum das ich irgendwie die GUI gerne neustarten würde.

    Ziel ist, das

    1. die GUI gestartet wird

    2. die entsprechenden Daten eingegeben werden

    3. Auf "Start" gedrückt wird

    4. Die Emails entsprechend versendet werden

    5. wenn möglich die GUI erneut ausgefüllt werden kann und das Programm komplett nochmal abläuft

    Sollte der Vorname, Nachname oder Username des "neuen Mitarbeiters" fehlen soll eine Fehlermeldung erscheinen und der user hat die Möglichkeit einfach alles zu ergänzen und dann auf "Start" zu drücken.

  • Noch ein Tipp, wenn die Code-Snippets bisschen länger sind dann pack sie doch bitte in Spoiler.

    Das restarten einer GUI hab ich dir doch schon erklärt, aber hier Schritt für Schritt.

    Nachdem der User das benutzt hat, bzw. auf den Button gedrückt hat. Soll der erstmal das machen was dein Script machen soll und danach soll folgendes passieren:

    Erstmal die GUI mit GUISetState(@SW_HIDE) verstecken.
    Dann GUICtrlSetData auf alle Controls anwenden und die Werte auf die setzen die du haben möchtest, bsp.-weise: "".
    Zum Schluss wieder anzeigen mit GUISetState(@SW_SHOW).

  • Hi,

    irgendwie reden wir aneinander vorbei. Ich habe hier ein Beispiel. Wenn du dieses Script ausführst erscheint die GUI. Dann trägst du bsp. admin als "Vorname" ein. Drückst du auf "Start" Wird der Inhalt in einer MSGBox ausgegeben. Drückt man jetzt nochmal auf "Start" gibt die MsgBox nur noch "0" aus, egal was eingetragen ist. Das heist das Script liest das Feld irgendwie nicht mehr aus. Der Befehl @SW_HIDE versteckt das Fenster nur und ist meiner Meinung nach "nur" Kosmetik (bitte korrigiere mich wenn ich falsch liege). Und wieso sollte ich den Inhalt erneut per GUICtrlSetData setzen wenn ich den Inhalt einfach genau so wie es drin steht verwenden will?

    Spoiler anzeigen
    [autoit]


    #cs ----------------------------------------------------------------------------
    AutoIt Version: 3.3.8.1
    Author: myName
    Script Function:
    Template AutoIt script.
    #ce ----------------------------------------------------------------------------
    ; Script Start - Add your code below here
    #include <ButtonConstants.au3>
    #include <DateTimeConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=h:\1data\public\autoit\forms\new_user.kxf
    $Form1_1 = GUICreate("Form1", 1051, 511, 190, 123)
    $nm_firstname = GUICtrlCreateInput("nm_firstname", 144, 72, 121, 21)
    $nm_lastname = GUICtrlCreateInput("nm_lastname", 144, 112, 121, 21)
    $nm_username = GUICtrlCreateInput("nm_username", 144, 152, 121, 21)
    $nm_entry = GUICtrlCreateDate("2013/06/05 16:35:27", 144, 192, 186, 21)
    $akt_firstname = GUICtrlCreateInput("akt_firstname", 480, 112, 121, 21)
    $akt_lastname = GUICtrlCreateInput("akt_lastname", 480, 152, 121, 21)
    $akt_username = GUICtrlCreateInput("akt_username", 480, 192, 121, 21)
    $domain_acc = GUICtrlCreateCheckbox("", 256, 256, 97, 17)
    $LN_acc = GUICtrlCreateCheckbox("", 256, 296, 97, 17)
    $ln_grouplist = GUICtrlCreateList("", 72, 328, 273, 149, BitOR($GUI_SS_DEFAULT_LIST,$LBS_MULTIPLESEL))
    GUICtrlSetData(-1, "")
    $psnext_acc = GUICtrlCreateCheckbox("", 544, 256, 97, 17)
    $vpn_acc = GUICtrlCreateCheckbox("", 544, 296, 97, 17)
    $telefon = GUICtrlCreateCheckbox("", 544, 336, 97, 17)
    $adminlist = GUICtrlCreateList("", 808, 72, 121, 58)
    GUICtrlSetData(-1, "")
    $admin_pw = GUICtrlCreateInput("admin_pw", 808, 152, 121, 21)
    $Start = GUICtrlCreateButton("Start", 800, 272, 193, 73)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    $Exit = GUICtrlCreateButton("Exit", 800, 368, 193, 73)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Vorname:", 56, 72, 49, 17)
    $Label2 = GUICtrlCreateLabel("Nachname:", 56, 112, 59, 17)
    $Label3 = GUICtrlCreateLabel("Username:", 56, 152, 55, 17)
    $Label4 = GUICtrlCreateLabel("Eintritt:", 56, 192, 36, 17)
    $Label5 = GUICtrlCreateLabel("Vorname:", 392, 112, 49, 17)
    $Label6 = GUICtrlCreateLabel("Nachname:", 392, 152, 59, 17)
    $Label7 = GUICtrlCreateLabel("Username:", 392, 192, 55, 17)
    $Label8 = GUICtrlCreateLabel("versenden von:", 712, 72, 78, 17)
    $Label9 = GUICtrlCreateLabel("Passwort:", 712, 152, 50, 17)
    $Label10 = GUICtrlCreateLabel("New Domain Account", 72, 256, 108, 17)
    $Label11 = GUICtrlCreateLabel("New Lotus Notes Account", 72, 296, 129, 17)
    $Label12 = GUICtrlCreateLabel("New PSNext Account", 376, 256, 108, 17)
    $Label13 = GUICtrlCreateLabel("New VPN Account", 376, 296, 94, 17)
    $neuer = GUICtrlCreateGroup("neuer Mitarbeiter", 40, 40, 313, 201)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group1 = GUICtrlCreateGroup("Berechtigung übernehmen von", 376, 40, 265, 201)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Label14 = GUICtrlCreateLabel("New phone", 376, 336, 59, 17)
    $no_reference = GUICtrlCreateCheckbox("Kein Referenzbenutzer", 424, 72, 153, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    _test ()
    EndSwitch
    WEnd

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

    Func _test ()
    $nm_firstname = GUICtrlRead($nm_firstname)
    MsgBox(0, "Test", $nm_firstname)
    EndFunc

    [/autoit]


    PS: Spoiler sind jetzt auch eingebaut ;)

  • Ok, das war schonmal eine sehr gute Info. Danke. Ich hatte gedacht, das ich die Variable jedes Mal neu einsetzen kann(Denkfehler).

    Dann sollte das Script soweit funktionieren, auch nach mehrfachem ausführen.

    Wenn ich jetzt noch hinbekomme das gewisse "Inputs" Pflichtfelder sein müssen ist alles gut.

  • So, ist jetzt komplett gelöst.

    Ich habe die Pflichtfelder gelöst mit:

    [autoit]


    ;Pflichtfelder
    If $nm_firstname_read = "" Then
    MsgBox(16, "Sie haben ein Pflichtfeld vergessen", "Der Vorname des neuen Mitarbeiters ist ein Pflichtfeld")
    ContinueLoop
    ElseIf $nm_lastname_read = "" Then
    MsgBox(16, "Sie haben ein Pflichtfeld vergessen", "Der Nachname des neuen Mitarbeiters ist ein Pflichtfeld")
    ContinueLoop
    ElseIf $nm_username_read = "" Then
    MsgBox(16, "Sie haben ein Pflichtfeld vergessen", "Der Username des neuen Mitarbeiters ist ein Pflichtfeld")
    ContinueLoop
    EndIf

    [/autoit]

    So kann man jetzt auch wenn man bspweise den Vornamen vergessen hat, diesen Nachtragen und es wird trotzdem alles korrekt dargestellt. Danke Oscar & auch Danke alpines für deine Gedult und hilfsbereitschaft