IT Helpdesktool mit Mailversand

  • hallo,

    habe schon seit fast 2 jahren ein IT Helpdesktool am start!
    dieses habe ich nun etwas umgeschrieben und es kommen mit der neuen autoit version einige fehler!
    auch ist eine screenshotfunktion mit dabei, hier kommt es zu verzögerungen ( springt warscheinlich nicht sauber aus der while schleife) beim senden, wenn ich einen screenshot mit tastenkombi über hotkeyset erzeugt habe!

    hat einer eine idee? :?:
    kann man die fehler beseitigen, habe zumindest keinen festgestellt!

    hier das script

    Spoiler anzeigen
    [autoit]


    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=..\Icons\ICONGROUP_32515.ico
    #AutoIt3Wrapper_outfile=IT-Helpdesk_neu.exe
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GUIConstants.au3>
    #include <File.au3>
    #include <Array.au3>
    #include <adfunctions.au3>
    #include <ScreenCapture.au3>
    #include <Date.au3>

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

    $mail = _ADGetObjectAttribute(@UserName,"mail")
    ;$mail = _ADGetObjectAttribute("erfmkh","mail")
    ;MsgBox(0,"",$mail)

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

    ;-------begin username auflösen----
    ;$user = _ADSamAccountNameToFQDN(@UserName)

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

    ;$user_split = StringSplit($user, ",")
    ;$user_split1 = StringSplit($user_split[1], "=")

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

    ;$username = $user_split1[2]
    $username = @UserName

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

    ;-------ende username auflösen----

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

    $SourceFile1 = "Das IT-Helpdesk Tool wird gestartet!"
    $DestinationFile1 = ""

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

    _PStart()

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

    Func _PStart()

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

    #region------------------------------------Declare Variables-------------------------------
    Local $ByteBlock, $Counter
    Local Const $BlockSize = 99
    Local Const $Opt = Opt("GUIOnEventMode", 0)
    #endregion---------------------------------------------------------------------------------

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

    #region------------------------------------GUI create--------------------------------------
    Local $GUI = GUICreate('', 400, 105, Default, Default, 0x80880000)
    Local $Label1 = GUICtrlCreateLabel($SourceFile1, 8, 10)
    ;Local $Label2 = GUICtrlCreateLabel($DestinationFile1, 8, 30)
    Local $Label3 = GUICtrlCreateLabel("0%", 360, 25, 30, 20, 0x2)
    Local $Button = GUICtrlCreateButton("Abbrechen", 160, 75, 80)
    Local $PBar = GUICtrlCreateProgress(8, 50, 384, 20)
    GUISetState()
    #endregion---------------------------------------------------------------------------------
    #region----------------------------------Copy File-----------------------------------------
    Do
    $ByteBlock = $BlockSize
    If @error Then ExitLoop
    $Counter += 1
    GUICtrlSetData($PBar, $Counter)
    GUICtrlSetData($Label3, $Counter & ' %')

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

    If $Counter = 100 Then ExitLoop ;GUIDelete($GUI)

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

    If GUIGetMsg() = $Button Then EXIT
    ;~ Opt("GUIOnEventMode", $Opt)
    ;~ GUIDelete($GUI)
    ;~ Return SetError(4,4,0)
    ;~ EndIf

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

    Sleep(10) ;Bremse - Auskommentieren für maximale Geschwindigkeit

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

    Until 0
    #endregion---------------------------------------------------------------------------------

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

    Opt("GUIOnEventMode", $Opt)
    GUIDelete($GUI)
    Return 1
    EndFunc

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

    ;----------------------------------
    #Region ### START Koda GUI section ### Form=C:\it_tool_incl_tabs.kxf
    $Form1 = GUICreate("IT-Helpdesk", 341, 385, 198, 150)
    GUISetIcon("D:\005.ico")
    $PageControl1 = GUICtrlCreateTab(8, 8, 324, 368)
    ;------------------------------ tabsheet 1 ---------------------------------------------------
    $TabSheet1 = GUICtrlCreateTabItem("IT-Helpdesk")
    $Edit1 = GUICtrlCreateEdit("", 36, 122, 257, 73)
    GUICtrlSetData(-1, StringFormat(""))
    $Button1 = GUICtrlCreateButton("Senden", 36, 242, 121, 33)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    $Button2 = GUICtrlCreateButton("Abbruch", 172, 242, 121, 33)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    $Label2 = GUICtrlCreateLabel(@UserName & " / " & @ComputerName & " / " & @IPAddress1, 28, 322, 280, 17, 0x01)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    $Checkbox1 = GUICtrlCreateCheckbox("Dringend", 36, 210, 193, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Wähle das System!", 36, 42, 112, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Combobox1 = GUICtrlCreateCombo("", 36, 66, 129, 25)
    GUICtrlSetData(-1, "As400|Amadeus|Bistro|Blank|Buma|Drucker|Galileo|Jack|Mediatrix|Merlin|Ostteamtool|Pilot Pro|SK Produktdb|PC|Sonstiges|Telefon")
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    $Label1 = GUICtrlCreateLabel("Gib eine Fehlerbeschreibung ein!", 36, 98, 191, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    ;$Checkbox2 = GUICtrlCreateCheckbox("SMS Benachrichtigung (30 ct/SMS) 18:00 - 8:00 Uhr", 36, 290, 273, 17)
    ;GUICtrlSetState(-1, $GUI_DISABLE)
    ;GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    $Label4 = GUICtrlCreateLabel("xxxxxxxxxxxxxinfo", 95, 346, 150, 14)
    GUICtrlSetFont(-1, 7, 400, 0, "Arial")
    ;------------------------------ tabsheet 2 ---------------------------------------------------
    $TabSheet3 = GUICtrlCreateTabItem("UserAccount Infos")
    ;GUICtrlCreateLabel($fldname01 & @CRLF & $fldname02 & @CRLF & $fldname03 & @CRLF & $fldname04 & @CRLF & $fldname05 & @CRLF & $fldname06 & @CRLF & $fldname07 & @CRLF & $fldname08 & @CRLF & $fldname09 & @CRLF & $fldname10 & @CRLF & $fldname11, 32, 50, 114, 299)
    ;GUICtrlSetFont(-1, 10, 400, 0)
    $labeldb = GUICtrlCreateLabel("", 152, 50, 130, 299)
    ;GUICtrlSetFont(-1, 10, 400, 0)
    ;-------------------------------tabsheet 3 ---------------------------------------------------
    $TabSheet2 = GUICtrlCreateTabItem("Admin")
    $Label5 = GUICtrlCreateLabel("Bitte Rufnummer aktivieren!", 96, 64, 162, 19)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetState(-1, $GUI_HIDE)
    $Radio1 = GUICtrlCreateRadio("user2", 64, 104, 209, 17)
    ;GUICtrlSetState(-1,$GUI_CHECKED)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    GUICtrlSetState(-1, $GUI_HIDE)
    $Radio2 = GUICtrlCreateRadio("user1", 64, 136, 209, 17)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    GUICtrlSetState(-1, $GUI_HIDE)
    $Label6 = GUICtrlCreateLabel("Sie haben keine Rechte!", 104, 48, 140, 19)
    GUICtrlSetFont(-1, 9, 800, 0, "Arial")
    GUICtrlSetState(-1, $GUI_HIDE)
    $Button3 = GUICtrlCreateButton("Änderung senden", 80, 200, 83, 33, 0x0200)
    GUICtrlSetFont(-1, 7, 400, 0, "Arial")
    GUICtrlSetState(-1, $GUI_HIDE)
    $Button4 = GUICtrlCreateButton("Exit", 184, 200, 83, 33, 0)
    GUICtrlSetFont(-1, 7, 400, 0, "Arial")
    GUICtrlSetState(-1, $GUI_HIDE)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    ;Rufnummer festlegen
    $Ruf1 = "0174xxxxx@vodafone-sms.de"
    $Ruf2 = "0174xxxxx@vodafone-sms.de"

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

    ; feiertage festlegen
    $ft1 ="01.01"
    $ft2 ="01.05"
    $ft3 ="03.10"
    $ft4 ="31.10"
    $ft5 ="25.12"
    $ft6 ="26.12"

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

    ; datum (tag, monat) festlegen
    $day = @MDAY & "."& @MON

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

    While 1
    $nMsg = GUIGetMsg()

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

    Switch $nMsg

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

    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $PageControl1
    Switch GUICtrlRead($PageControl1)
    Case 0 ;------tabsheet 1 ------

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

    GUIctrlSetState($labeldb,$GUI_HIDE)
    Case 1 ;------tabsheet 2 ------

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

    Case 2 ;------tabsheet 3 ------
    GUIctrlSetState($labeldb,$GUI_HIDE)

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

    If @UserName = "user1" or @UserName = "user2" Then
    GUICtrlSetState($Label5, $GUI_SHOW)
    GUICtrlSetState($Radio1, $GUI_SHOW)
    GUICtrlSetState($Radio1, $GUI_ENABLE)
    GUICtrlSetState($Radio2, $GUI_SHOW)
    GUICtrlSetState($Radio2, $GUI_ENABLE)
    GUICtrlSetState($Button3, $GUI_SHOW)
    GUICtrlSetState($Button3, $GUI_ENABLE)
    GUICtrlSetState($Button4, $GUI_SHOW)
    GUICtrlSetState($Button4, $GUI_ENABLE)
    Else
    GUICtrlSetState($Label6, $GUI_SHOW)
    EndIf

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

    $strFilePath = ("\\sbserver\NETLOGON\Support\kontakt.txt")
    $file = FileOpen($strFilePath, 0)

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

    $line = FileReadLine($file,1)
    ;MsgBox(0, "Error", $line)
    FileClose($file)

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

    If $line = $Rufmonty Then
    GUICtrlSetState($Radio1,$GUI_CHECKED)
    Else
    GUICtrlSetState($Radio2,$GUI_CHECKED)
    EndIf
    EndSwitch

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

    Case $Button3

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

    ; RadioButton auf wert prüfen
    If GUICtrlRead($Radio1, $GUI_CHECKED)= $GUI_CHECKED Then
    $rb1 = GUICtrlRead($Radio1, $GUI_CHECKED)
    Else
    $rb1 = GUICtrlRead($Radio1, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    If GUICtrlRead($Radio2, $GUI_CHECKED)= $GUI_CHECKED Then
    $rb2 = GUICtrlRead($Radio2, $GUI_CHECKED)
    Else
    $rb2 = GUICtrlRead($Radio2, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    $strFilePath = ("\\server\NETLOGON\Support\kontakt.txt")
    $file = FileOpen($strFilePath, 2)
    IF $rb1 = False Then FileWriteLine($file,$Ruf1)
    IF $rb2 = False Then FileWriteLine($file,$Ruf2l)

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

    FileClose($file)

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

    Exit

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

    Case $Button4
    Exit
    Case $Combobox1
    GUICtrlSetState($Button1, $GUI_ENABLE)

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

    Case $Checkbox1

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

    ;checkbox überprüfen und anhand des rückgabewertes sms freischalten oder auch nicht
    If GUICtrlRead($Checkbox1, $GUI_CHECKED)= $GUI_CHECKED Then
    $cb1 = GUICtrlRead($Checkbox1, $GUI_CHECKED)
    Else
    $cb1 = GUICtrlRead($Checkbox1, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    Case $Button1
    GUICtrlSetState($Button2, $GUI_DISABLE)

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

    ;######################################
    ; combobox1 auf wert prüfen
    ;######################################
    If GUICtrlRead($Combobox1, $GUI_CHECKED)= $GUI_CHECKED Then
    $cbo1 = GUICtrlRead($Combobox1, $GUI_CHECKED)
    Else
    $cbo1 = GUICtrlRead($Combobox1, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    IF $cbo1 = False Then
    $cboa1 = GUICtrlRead($Combobox1, $GUI_CHECKED)
    Else
    $cboa1 = " "
    EndIf
    ;-----------
    ;MsgBox(0, "gewählt", $cba1)

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

    Global $answer_combo1 = GUICtrlRead($Combobox1)
    ;MsgBox(0, "gewählt", $answer_combo1)

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

    ;######################################
    ; checkbox1 auf wert prüfen
    ;######################################
    If GUICtrlRead($Checkbox1, $GUI_CHECKED)= $GUI_CHECKED Then
    $cb1 = GUICtrlRead($Checkbox1, $GUI_CHECKED)
    Else
    $cb1 = GUICtrlRead($Checkbox1, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    IF $cb1 = False Then
    $cba1 = GUICtrlRead($Checkbox1, $GUI_CHECKED)
    Else
    $cba1 = " "
    EndIf
    ;MsgBox(0, "gewählt", $cba2)
    $answer = GUICtrlRead($Edit1)

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

    ; begin file path for contact number
    $strFilePath = ("\\server\NETLOGON\Support\kontakt.txt")
    $file = FileOpen($strFilePath, 0)

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

    $line = FileReadLine($file,1)
    ;MsgBox(0, "Error", $line)
    FileClose($file)
    ; end file path
    If IsMemberOf("Callcenter",@UserName) = 1 Or IsMemberOf("Callcenter-Flug",@UserName) = 1 Then
    Global $CAddress = "steuerung@xxxxx.de"
    Else
    Global $CAddress = ""
    EndIf

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

    If IsMemberOf("team-buchhaltung",@UserName) = 1 Then
    Global $sCAddress = "userxy@xxxxxx.de"
    Else
    Global $CAddress = ""
    EndIf

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

    ; Frage --> Datei -- Screenshot anhängen
    ;----------------------------------------
    Global $var = (@MyDocumentsDir & "\Printscreen.jpg")
    Global $jn = MsgBox(4, "Hinweis!", "Screenshot anhängen JA/NEIN ?" & @CRLF & @CRLF & "Button JA anklicken, Fenster mit Fehlermeldung auswählen" & @CRLF & "und Tastenkombination STRG+F4 drücken!"& @CRLF)
    If $jn = 6 Then ;wenn ja gedrückt dann

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

    while 1
    Sleep(1)
    ;HotKeySet("{PRINTSCREEN}", "Capture_start")
    ;HotKeySet("+!d", "Capture_start") ;Shift-Alt-d
    HotKeySet("^{F4}", "Capture_start") ;Strg-F4
    WEnd

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

    Func Capture_start()
    ; Capture full screen
    _ScreenCapture_Capture(@MyDocumentsDir & "\Printscreen.jpg")
    MsgBox(0,"","Screenshot erstellt!",1)
    ExitLoop
    EndFunc

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

    ; nach aktueller zeit oder wochenende
    IF _NowTime() > "18:00:00" or _NowTime() < "08:00:00" or @WDAY = 7 or @WDAY = 1 Then
    Global $CAddress = "steuerung@xxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    ; nach feiertagen
    IF $day = $ft1 or $day = $ft2 or $day = $ft3 or $day = $ft4 or $day = $ft5 or $day = $ft6 Then
    Global $CAddress = "steuerung@xxxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    Sendmail()
    Exit
    ;###################
    Else ; nein gedrückt
    ;MsgBox(0,"","test")
    ; nach aktueller zeit oder wochenende
    IF _NowTime() > "18:00:00" or _NowTime() < "08:00:00" or @WDAY = 7 or @WDAY = 1 Then
    Global $CAddress = "steuerung@xxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    ; nach feiertagen
    IF $day = $ft1 or $day = $ft2 or $day = $ft3 or $day = $ft4 or $day = $ft5 or $day = $ft6 Then
    Global $CAddress = "steuerung@xxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    Sendmail()
    EndIf

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

    Exit
    Case $Button2
    Exit
    EndSwitch
    WEnd
    #Region------------------------------------Functions----------------------------
    Func Sendmail()

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

    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc_1")
    ;##################################
    ; Variables
    ;##################################
    $s_SmtpServer = "0.0.0.0" ; address for the smtp-server to use - REQUIRED
    $s_FromName = $username ; name from who the email was sent
    $s_FromAddress = $mail ; address from where the mail should come
    $s_ToAddress = "support@xxxxxx.de" ; destination address of the email - REQUIRED
    ;$s_Subject = "";$sb ; subject from the email - can be anything you want it to be
    $s_Subject = "Supportmeldung " & $answer_combo1 & " - " & @ComputerName &" --" & $cba1
    $s_Body = ("PC Login: " & @UserName & @CRLF & "IP Addresse: " & @IPAddress1 & @CRLF & "Computername: "& @ComputerName & @CRLF & "System: "& $answer_combo1 & @CRLF & @CRLF & "Fehlerbeschreibung: " & @CRLF & @CRLF & $answer) ; the messagebody from the mail - can be left blank but then you get a blank mail
    IF $jn = 6 Then ; the file you want to attach- leave blank if not needed
    $s_AttachFiles = $var
    Else
    $s_AttachFiles = ""
    EndIf
    ;$as_Body = "";$mbody1 ; the messagebody from the mail - can be left blank but then you get a blank mail
    ;$s_AttachFiles = "" ; the file you want to attach- leave blank if not needed
    $s_CcAddress = $CAddress ; address for cc - leave blank if not needed
    $s_BccAddress = "" ; address for bcc - leave blank if not needed
    $s_Username = "userl" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail)
    $s_Password = "xxxxxxxx" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail)
    $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

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

    ;##################################
    ; Script
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc_1")
    $rc = _INetSmtpMailCom_1($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf

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

    EndFunc ;==>Sendmail

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

    ;###################################################

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

    Func _INetSmtpMailCom_1($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)
    $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($s_Body,"<") and StringInStr($s_Body,">") Then
    $objEmail.HTMLBody = $s_Body
    Else
    $objEmail.Textbody = $s_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])
    If FileExists($S_Files2Attach[$x]) Then
    $objEmail.AddAttachment ($S_Files2Attach[$x])
    Else
    $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
    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
    $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
    ; Sent the Message
    $objEmail.Send
    If @error Then
    SetError(2)
    return $oMyRet[1]
    EndIf
    EndFunc ;==>_INetSmtpMailCom
    ;
    ;
    ; Com Error Handler
    Func MyErrFunc_1()
    $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_1
    ;---------------------------------------------------------

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

    ; IsMemberOf
    ; Takes the groupname (SamAccountName with or without the leading 'CN=', and the SamAccountName of the user
    ; Returns 1 if the the user is a member of the group, 0 otherwise

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

    Func IsMemberOf($group, $user)
    If StringLeft($group, 3) <> "CN=" Then
    $group = "CN=" & $group
    EndIf
    Dim $usergroups[1], $i = 1

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

    Dim $objConnection, $oUsr

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

    $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD
    $objConnection.Provider = "ADsDSOObject"
    $objConnection.Open ("Active Directory Provider") ; Open connection to AD

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

    $objRootDSE = ObjGet("LDAP://RootDSE")
    Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext") ; Retrieve the current AD domain name

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

    $strQuery = "<LDAP://" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the logged on user
    $ldap_entry = $objRecordSet.fields (0).value
    $oUsr = ObjGet($ldap_entry) ; Retrieve the COM Object for the logged on user
    $groups = $oUsr.groups ; Get the list of group objects from the user

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

    For $groupname In $groups
    If $groupname.name = $group Then Return 1

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

    Next
    Return 0

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

    EndFunc ;==>IsMemberOf

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

    Func _ReadOneFld($_sql, $_dbname, $_field)
    Dim $_output
    $adoCon = ObjCreate ("ADODB.Connection")
    $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $_dbname)
    $adoRs = ObjCreate ("ADODB.Recordset")
    $adoRs.CursorType = 1
    $adoRs.LockType = 3
    $adoRs.Open ($_sql, $adoCon)

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

    With $adoRs
    If .RecordCount Then
    While Not .EOF
    $_output = ": " & $_output & .Fields ($_field).Value & @CR ;(das & @CRKF macht einen zeilenumbruch)
    .MoveNext
    WEnd
    EndIf
    EndWith
    $adoCon.Close
    Return $_output
    EndFunc ;==>_ReadOneFld

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

    #EndRegion---------------------------------Endfunctions-------------------------

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

    danke

    gruß
    gmmg

    2 Mal editiert, zuletzt von gmmg (13. Juli 2009 um 12:55)

  • hier die adfunctions

    Spoiler anzeigen
    [autoit]


    ; Active Directory Function Library. Include this to allow access to Active Directory Functions

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

    ; Author : Jonthan Clelland
    ; Email : [email='jclelland@statestreet.com'][/email]
    ; Version : 3.0
    ; erweitert von M.Schröder, V3.03, am 25.07.2007

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

    ; _ADDoError : Error event handler for COM errors. This is global so will pick up errors from your program if you include this library
    ; _ADCreateUser : Creates a user in a particular OU
    ; _ADCreateGroup : Creates a group in a particular OU
    ; _ADAddUserToGroup : Adds a user to a group (if the user is not already a member of the group)
    ; _ADRemoveUserFromGroup : Removes a user from a group
    ; _ADObjectExists : Returns 1 if the given object (SamAccountName) exists in the local AD Tree
    ; _ADModifyAttribute : Sets the attribute of the given object to the value specified
    ; _ADIsMemberOf : Returns 1 if the user is a member of the group
    ; _ADGetUserGroups : Returns an array (byreference) containing the groups that the user is a member of
    ; _ADRecursiveGetMemberOf : Returns a recursed list of group membership for a group or user
    ; _ADGetGroupMembers : Returns an array of the group members
    ; _ADGetGroupMemberOf : Returns a simple list of group membership for a group
    ; _ADHasFullRights : Returns 1 if the given user has full rights over the given group
    ; _ADGroupMailEnable : Mail enables a group
    ; _ADUserCreateMailbox : Creates a mailbox for a user
    ; _ADUserDeleteMailbox : Deletes the mailbox for a user
    ; _ADGetObjectsInOU : Returns a filtered list of objects and attributes in a given OU
    ; _ADDNToSamAccountName : Returns the SamAccountName of an FQDN
    ; _ADSamAccountNameToFQDN : Returns a FQDN from a SamAccountName
    ; _ADDNToDisplayName :Returns the Display Name of an FQDN
    ; _ADCreateObject : Creates an object of a specified type
    ; _ADCreateComputer : Creates a computer and assigns permissions for a user/group to add the computer
    ; _ADDeleteObject : Deletes an object
    ; _ADGetObjectClass : Returns the class of an object
    ; _ADGetObjectClassFromFQDN : Returns the class of an object from it's FQDN
    ; _ADGetObjectAttribute : Returns a (single-value) attribute of an object
    ; _ADListDomainControllers : Returns a list of Domain Controllers for the current domain
    ; _ADOUObjectNames : Returns display names of filtered objects within an OU

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

    ; NOTES : Please use the following command to store the local user's groups for the function 'HasFullRights'. This is to allow cross-domain
    ; permission checks. $loggedonusergroups is a global variable declared in the 'Define AD Constants' region. If you are using this command
    ; in this library, move the command below the declaration of the variable and remove the comment charcater.

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

    ; _ADRecursiveGetMemberOf ($loggedonusergroups, _ADSamAccountNameToFQDN (@UserName))

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

    ; von M.Schröder hinzugefügt V3.03
    ; _ADGetAllGroups($grouparray, $LDAPPath) : Return an array of all AD-groups
    ; _ADGetWellKnownSIDName($DN) : Return a name for a WellKnownSID
    ; _ADGetPrimaryGroupID ($userdn) : Return the PrimaryGroupID of an given User
    ; _ADGetPrimaryGroupDN ($primarygroupID) : Return the DN of a given PrimaryGroupID

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

    ; include array functions (we use _arraysearch in some functions)
    #include <Array.au3>

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

    #region ; Define AD Constants

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

    Dim $oMyRet
    Global Const $ADS_GROUP_TYPE_GLOBAL_GROUP = 0x2
    Global Const $ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP = 0x4
    Global Const $ADS_GROUP_TYPE_UNIVERSAL_GROUP = 0x8
    Global Const $ADS_GROUP_TYPE_SECURITY_ENABLED = 0x80000000
    Global Const $ADS_GROUP_TYPE_GLOBAL_SECURITY = BitOR($ADS_GROUP_TYPE_GLOBAL_GROUP, $ADS_GROUP_TYPE_SECURITY_ENABLED)
    Global Const $ADS_GROUP_TYPE_UNIVERSAL_SECURITY = BitOR($ADS_GROUP_TYPE_UNIVERSAL_GROUP, $ADS_GROUP_TYPE_SECURITY_ENABLED)

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

    Global Const $ADS_UF_PASSWD_NOTREQD = 0x0020
    Global Const $ADS_UF_WORKSTATION_TRUST_ACCOUNT = 0x1000
    Global Const $ADS_ACETYPE_ACCESS_ALLOWED = 0x0
    Global Const $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = 0x5
    Global Const $ADS_FLAG_OBJECT_TYPE_PRESENT = 0x1
    Global Const $ADS_RIGHT_GENERIC_READ = 0x80000000
    Global Const $ADS_RIGHT_DS_SELF = 0x8
    Global Const $ADS_RIGHT_DS_WRITE_PROP = 0x20
    Global Const $ADS_RIGHT_DS_CONTROL_ACCESS = 0x100

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

    Global Const $ALLOWED_TO_AUTHENTICATE = "{68B1D179-0D15-4d4f-AB71-46152E79A7BC}"
    Global Const $RECEIVE_AS = "{AB721A56-1E2f-11D0-9819-00AA0040529B}"
    Global Const $SEND_AS = "{AB721A54-1E2f-11D0-9819-00AA0040529B}"
    Global Const $USER_CHANGE_PASSWORD = "{AB721A53-1E2f-11D0-9819-00AA0040529b}"
    Global Const $USER_FORCE_CHANGE_PASSWORD = "{00299570-246D-11D0-A768-00AA006E0529}"
    Global Const $USER_ACCOUNT_RESTRICTIONS = "{4C164200-20C0-11D0-A768-00AA006E0529}"
    Global Const $VALIDATED_DNS_HOST_NAME = "{72E39547-7B18-11D1-ADEF-00C04FD8D5CD}"
    Global Const $VALIDATED_SPN = "{F3A64788-5306-11D1-A9C5-0000F80367C1}"

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

    Global $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD
    $objConnection.ConnectionString = "Provider=ADsDSOObject"
    $objConnection.Open ("Active Directory Provider") ; Open connection to AD

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

    Global $objRootDSE = ObjGet("LDAP://RootDSE")
    Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext") ; Retrieve the current AD domain name
    Global $strHostServer = $objRootDSE.Get ("dnsHostName") ; Retrieve the name of the connected DC
    Global $strConfiguration = $objRootDSE.Get ("ConfigurationNamingContext") ; Retrieve the Configuration naming context

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

    Global $loggedonusergroups ; populate this with the logged on user groups in your own app

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

    #endregion

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

    Dim $oMyError
    $oMyError = ObjEvent("AutoIt.Error", "_ADDoError") ; Install a custom error handler

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

    ; MyErrFunc
    Func _ADDoError()
    $HexNumber = Hex($oMyError.number, 8)

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

    If $HexNumber = 80020009 Then
    SetError(3)
    Return
    EndIf

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

    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
    "Number is: " & $HexNumber & @CRLF & _
    "Windescription is: " & $oMyError.windescription)

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

    Select
    Case $oMyError.windescription = "Access is denied."
    $objConnection.Close ("Active Directory Provider")
    $objConnection.Open ("Active Directory Provider")
    SetError(2)
    Case 1
    SetError(1)
    EndSelect

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

    EndFunc ;==>DoError

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

    ; _ADCreateUser
    ; $userou = OU to create the group in. Form is "sampleou=ou, sampleparent=ou, sampledomain1=dc, sampledomain2=dc, sampledomain3=dc"
    ; $user = Username, form is SamAccountName without leading 'CN='
    ; $fname = First Name
    ; $lname = Last Name
    ; $description = optional - Description

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

    Func _ADCreateUser($userou, $user, $fname, $lname, $description = "User")
    If _ADObjectExists($user) Then Return 0

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

    $ObjOU = ObjGet("LDAP://" & $strHostServer & "/" & $userou)
    $cnname = "CN=" & $lname & "\, " & $fname
    $ObjUser = $ObjOU.Create ("User", $cnname)

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

    $ObjUser.Put ("sAMAccountName", $user)
    $ObjUser.Put ("description", $description)
    ;$ObjUser.Put ("givenName", $fname)
    ;$ObjUser.Put ("sname", $lname)

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

    $ObjUser.SetInfo
    Return 1
    EndFunc ;==>_ADCreateUser

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

    ; _ADCreateGroup
    ; $gruopou = OU to create the group in. Form is "sampleou=ou, sampleparent=ou, sampledomain1=dc, sampledomain2=dc, sampledomain3=dc"
    ; $group = groupname, form is SamAccountName without leading 'CN='
    ; $type = Group type. Defaults to Global Security. See the global constands for other types. NOTE Global security must be 'BitOr'ed with a scope.

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

    Func _ADCreateGroup($groupou, $group, $type = -2147483646)
    If _ADObjectExists($group) Then Return 0

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

    If StringLeft($group, 3) <> "CN=" Then
    $group = "CN=" & StringReplace($group, ",", "\,")
    EndIf
    $ObjOU = ObjGet("LDAP://" & $strHostServer & "/" & $groupou)
    $ObjGroup = $ObjOU.Create ("Group", $group)

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

    $ObjGroup.Put ("sAMAccountName", StringTrimLeft(StringReplace($group, "\,", " "), 3))
    $ObjGroup.Put ("grouptype", $type)

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

    $ObjGroup.SetInfo
    Return 1
    EndFunc ;==>_ADCreateGroup

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

    ; _ADAddUserToGroup
    ; Takes the group (SamAccountName without leading 'CN=') and the user (SamAccountName without leading 'CN=')
    ; Adds the user to the group
    ; Returns 0 if the user is already a member of the group,
    ; Returns 1 if the user was added to the group
    ; Returns -1 if there was an error

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

    Func _ADAddUserToGroup($group, $user)
    If _ADIsMemberOf($group, $user) Then Return 0
    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the user
    $ldap_entry = $objRecordSet.fields (0).value
    $oUsr = ObjGet($ldap_entry) ; Retrieve the COM Object for the user

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $group & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the group
    $ldap_entry = $objRecordSet.fields (0).value
    $oGroup = ObjGet($ldap_entry) ; Retrieve the COM Object for the group

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

    $OGroup.Add ($oUsr.AdsPath)
    $OGroup.SetInfo

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

    Return _ADIsMemberOf($group, $user)
    EndFunc ;==>_ADAddUserToGroup

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

    ; _ADRemoveUserFromGroup
    ; Takes the group (SamAccountName without leading 'CN=') and the user (SamAccountName without leading 'CN=')
    ; Removes the user from the group (if the user is a member of the group)
    ; Returns 0 if the user isn't a member of the group, 1 if the user was removed from the group
    ; Returns -1 if the removal failed.

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

    Func _ADRemoveUserFromGroup($group, $user)
    If _ADIsMemberOf($group, $user) = 0 Then Return 0

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the user
    $ldap_entry = $objRecordSet.fields (0).value
    $oUsr = ObjGet($ldap_entry) ; Retrieve the COM Object for the user

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $group & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the group
    $ldap_entry = $objRecordSet.fields (0).value
    $oGroup = ObjGet($ldap_entry) ; Retrieve the COM Object for the group

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

    $oGroup.Remove ($oUsr.AdsPath)
    $OGroup.SetInfo

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

    If _ADIsMemberOf($group, $user) Then
    Return -1
    Else
    Return 1
    EndIf

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

    EndFunc ;==>_ADRemoveUserFromGroup

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

    ; _ADObjectExists
    ; Takes an object name (SamAccountName without leading 'CN=')
    ; Returns 1 if the object exists in the tree, 0 otherwise

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

    Func _ADObjectExists($object)
    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $object & ");ADsPath;subtree"
    $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the group, if it exists

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

    If $objRecordSet.RecordCount = 1 Then
    Return 1
    Else
    Return 0
    EndIf
    EndFunc ;==>_ADObjectExists

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

    ; _ADModifyAttribute
    ; $object = Object to modify (samAccountName)
    ; $attribute = Attribute to modify
    ; $value = value to set attribute to

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

    Func _ADModifyAttribute($object, $attribute, $value)
    If _ADObjectExists($object) = 0 Then Return 0 ; Returns 0 if the object doesn't exist

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $object & ");ADsPath;subtree"
    $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the object

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

    $ldap_entry = $objRecordSet.fields (0).value
    $oObject = ObjGet($ldap_entry) ; Retrieve the COM Object for the object

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

    $oObject.GetInfo
    $oObject.GetInfo

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

    If $value = "" Then
    $oObject.PutEx (1, $attribute, 0)
    Else
    $oObject.Put ($attribute, $value)
    EndIf

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

    $oObject.SetInfo
    $oObject.PurgePropertyList

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

    Return 1
    EndFunc ;==>_ADModifyAttribute

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

    ; _ADIsMemberOf
    ; Takes samAccountNames for a group and a user
    ; Returns 1 if the the user is a member of the group, 0 otherwise

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

    Func _ADIsMemberOf($group, $user)
    $ObjGroup = ObjGet("LDAP://" & $strHostServer & "/" & _ADSamAccountNameToFQDN($group))
    $ismember = $objgroup.IsMember ("LDAP://" & $strHostServer & "/" & _ADSamAccountNameToFQDN($user))
    Return -$ismember
    EndFunc ;==>_ADIsMemberOf

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

    ; _ADGetUserGroups
    ; the currently logged on user is a member of. Returns an array of Full DNs of the Group names that the user is immediately a member of
    ; with element 0 containing the number of groups.
    ; $user - optional -- SamAccountName of a user, defaults to locally logged on user

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

    Func _ADGetUserGroups(ByRef $usergroups, $user = @UserName)
    Local $oUsr

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the logged on user
    $ldap_entry = $objRecordSet.fields (0).value
    $oUsr = ObjGet($ldap_entry) ; Retrieve the COM Object for the logged on user

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

    $usergroups = $oUsr.GetEx ("memberof")
    $count = UBound($usergroups)
    _ArrayInsert($usergroups, 0, $count)
    EndFunc ;==>_ADGetUserGroups

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

    ; _ADRecursiveGetMemberOf
    ; Takes a Full DN of a group or user and returns a recursively searched list of groups the object is a member of to the array
    ; This will traverse through groups that the object is immediately a member of and check their group membership as well.
    ; The return values are full DNs. For groups that are inherited, the return is the DN of the group, and the DN of the first group
    ; it was inherited from, seperated by '|'.
    Func _ADRecursiveGetMemberOf(ByRef $memberof, $fqdn)
    Local $objItem, $tempmemberof, $i = 0

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

    $objItem = ObjGet("LDAP://" & $strHostServer & "/" & $fqdn) ; Retrieve the COM Object for the logged on user

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

    $memberof = $objItem.GetEx ("memberof")

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

    If $memberof = 0 Then
    Dim $memberof[1] = [0]
    Return 0
    EndIf

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

    Do
    If StringInStr($memberof[$i],"|") Then
    $currgroup = StringLeft($memberof[$i],StringInStr($memberof[$i],"|")-1)
    Else
    $currgroup = $memberof[$i]
    EndIf
    _ADGetGroupMemberOf($tempmemberof, $currgroup)
    For $j = 1 To $tempmemberof[0]
    $exists = 0
    $k = UBound($memberof)
    Do
    $k -= 1
    If StringInStr($memberof[$k], $tempmemberof[$j]) Then $exists = 1
    Until $exists = 1 Or $k = 0
    If $exists = 0 Then _ArrayAdd($memberof, $tempmemberof[$j] & "|" & $currgroup)
    Next
    $i += 1
    Until $i = UBound($memberof)

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

    $count = UBound($memberof)
    _ArrayInsert($memberof, 0, $count)

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

    Return 1
    EndFunc ;==>_ADRecursiveGetMemberOf

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

    ; _ADGetGroupMembers
    ; Arguments,
    ; $members - Array that the result will be stored in
    ; $group - Group to retrieve members from
    ; $sort - optional, default 0 : Set to 1 to sort the array
    ; Returns an array to $members where $members[0] will be the number of users in the group and
    ; $members[1] to $members[$members[0]] are the distinguished names of the users

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

    Func _ADGetGroupMembers(ByRef $members, $groupdn, $sort = 0)
    ;If _ADObjectExists($group) = 0 Then Return 0

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

    Local $oUsr, $objCommand, $groups, $i, $rangemodifier
    Local $range, $objRecordSet, $membersadd, $strCmdText, $j

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

    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties ("Searchscope") = 2

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

    Dim $members[1]
    $i = 0

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

    While 1
    $rangemodifier = $i * 1000
    $range = "Range=" & $rangemodifier & "-" & $rangemodifier + 999
    $strCmdText = "<LDAP://" & $strHostServer & "/" & $groupdn & ">;;member;" & $range & ";base"
    $objCommand.CommandText = $strCmdText
    $objRecordSet = $objCommand.Execute
    $membersadd = $objRecordSet.fields (0).Value
    If $membersadd = 0 Then ExitLoop
    ReDim $members[UBound($members) + 1000]
    For $j = $rangemodifier + 1 To $rangemodifier + 1000
    $members[$j] = $membersadd[$j - $rangemodifier - 1]
    Next
    $i += 1
    $objRecordSet.Close
    WEnd

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

    $rangemodifier = $i * 1000
    $range = "Range=" & $rangemodifier & "-*"
    $strCmdText = "<LDAP://" & $strHostServer & "/" & $groupdn & ">;;member;" & $range & ";base"
    $objCommand.CommandText = $strCmdText
    $objRecordSet = $objCommand.Execute
    $membersadd = $objRecordSet.fields (0).Value

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

    ReDim $members[UBound($members) + UBound($membersadd)]

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

    For $j = $rangemodifier + 1 To $rangemodifier + UBound($membersadd)
    $members[$j] = $membersadd[$j - $rangemodifier - 1]
    Next

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

    $objRecordSet.Close

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

    $members[0] = UBound($members) - 1

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

    If $sort = 1 Then
    _ArraySort($members, 0, 1)
    EndIf

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

    Return 1
    EndFunc ;==>_ADGetGroupMembers

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

    ; _ADGetGroupMemberOf
    Func _ADGetGroupMemberOf(ByRef $memberof, $groupdn, $sort = 0)
    ;If _ADObjectExists($group) = 0 Then Return 0

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

    Local $oUsr, $objCommand, $groups, $rangemodifier, $i
    Local $range, $objRecordSet, $membersadd, $strCmdText, $j

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

    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties ("Searchscope") = 2

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

    Dim $memberof[1]
    $i = 0

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

    While 1
    $rangemodifier = $i * 1000
    $range = "Range=" & $rangemodifier & "-" & $rangemodifier + 999
    $strCmdText = "<LDAP://" & $strHostServer & "/" & $groupdn & ">;;memberof;" & $range & ";base"
    $objCommand.CommandText = $strCmdText
    $objRecordSet = $objCommand.Execute
    $membersadd = $objRecordSet.fields (0).Value
    If $membersadd = 0 Then ExitLoop
    ReDim $memberof[UBound($memberof) + 1000]
    For $j = $rangemodifier + 1 To $rangemodifier + 1000
    $memberof[$j] = $membersadd[$j - $rangemodifier - 1]
    Next
    $i += 1
    $objRecordSet.Close
    WEnd

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

    $rangemodifier = $i * 1000
    $range = "Range=" & $rangemodifier & "-*"
    $strCmdText = "<LDAP://" & $strHostServer & "/" & $groupdn & ">;;memberof;" & $range & ";base"
    $objCommand.CommandText = $strCmdText
    $objRecordSet = $objCommand.Execute
    $membersadd = $objRecordSet.fields (0).Value
    ReDim $memberof[UBound($memberof) + UBound($membersadd) ]

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

    For $j = $rangemodifier + 1 To $rangemodifier + UBound($membersadd)
    $memberof[$j] = $membersadd[$j - $rangemodifier - 1]
    Next
    $objRecordSet.Close

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

    $memberof[0] = UBound($memberof) - 1

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

    If $sort = 1 Then
    _ArraySort($memberof, 0, 1)
    EndIf

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

    Return $memberof[0]

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

    EndFunc ;==>_ADGetGroupMemberOf

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

    ; _ADHasFullRights
    ; Take an object's SamAccountName, a user's SamAccountName
    ; Returns 1 if User has full rights on the object
    ; Returns 0 otherwise

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

    Func _ADHasFullRights($object, $user = @UserName)
    Dim $hfr_groups
    If $user = @UserName Then
    $hfr_groups = $loggedonusergroups
    Else
    _ADGetUserGroups($hfr_groups, $user)
    EndIf

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $object & ");ADsPath;subtree"
    $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the object

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

    If $objRecordSet.RecordCount = 1 Then
    $ldap_entry = $objRecordSet.fields (0).value
    $oObject = ObjGet($ldap_entry) ; Retrieve the COM Object for the logged on user
    $security = $oObject.Get ("ntSecurityDescriptor")
    $dacl = $security.DiscretionaryAcl
    For $ace In $dacl
    $trusteearray = StringSplit($ace.Trustee, "\")
    $trusteegroup = $trusteearray[$trusteearray[0]]
    For $i = 0 To UBound($hfr_groups) - 1
    If StringInStr($hfr_groups[$i], "CN=" & $trusteegroup) And $ace.AccessMask = 983551 Then Return 1
    Next
    Next
    EndIf
    Return 0
    EndFunc ;==>_ADHasFullRights

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

    ; _ADGroupMailEnable
    ; Takes a group and enables mail on that group
    Func _ADGroupMailEnable($group)
    If _ADObjectExists($group) = 0 Then Return 0
    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $group & ");ADsPath;subtree"
    $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the group, if it exists

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

    $ldap_entry = $objRecordSet.fields (0).value
    $oGroup = ObjGet($ldap_entry) ; Retrieve the COM Object for the object

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

    $oGroup.MailEnable
    $OGroup.SetInfo
    Return 1
    EndFunc ;==>_ADGroupMailEnable

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

    ; _ADUserCreateMailbox
    ; $user - User to add mailbox to
    ; $mdbstore - Mailbox storename
    ; $store - Information store
    ; $server - Email server
    ; $admingroup - Administrative group in Exchange
    ; $domain - Domain name
    Func _ADUserCreateMailbox($user, $mdbstore, $store, $server, $admingroup, $domain)
    If _ADObjectExists($user) = 0 Then Return 0
    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the group, if it exists

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

    $ldap_entry = $objRecordSet.fields (0).value
    $oUser = ObjGet($ldap_entry) ; Retrieve the COM Object for the object

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

    If $oUser.HomeMDB <> "" Then Return 0

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

    $mailboxpath = "LDAP://CN="
    $mailboxpath = $mailboxpath & $mdbstore
    $mailboxpath = $mailboxpath & ",CN="
    $mailboxpath = $mailboxpath & $store
    $mailboxpath = $mailboxpath & ",CN=InformationStore"
    $mailboxpath = $mailboxpath & ",CN="
    $mailboxpath = $mailboxpath & $server
    $mailboxpath = $mailboxpath & ",CN=Servers,CN="
    $mailboxpath = $mailboxpath & $admingroup
    $mailboxpath = $mailboxpath & ",CN=Administrative Groups,CN=State Street,CN=Microsoft Exchange,CN=Services,CN=Configuration,"
    $mailboxpath = $mailboxpath & $domain

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

    $oUser.CreateMailbox ($mailboxpath)
    $oUser.SetInfo
    Return 1
    EndFunc ;==>_ADUserCreateMailbox

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

    ; _ADUserDeleteMailbox
    ; Deletes a user's mailbox
    Func _ADUserDeleteMailbox($user)
    If _ADObjectExists($user) = 0 Then Return 0

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the group, if it exists

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

    $ldap_entry = $objRecordSet.fields (0).value
    $oUser = ObjGet($ldap_entry) ; Retrieve the COM Object for the object

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

    If $oUser.HomeMDB = "" Then Return 0

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

    $oUser.DeleteMailbox
    $oUser.SetInfo
    Return 1
    EndFunc ;==>_ADUserDeleteMailbox

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

    ; _ADGetObjectsInOU
    ; Returns an array of the objects in an OU
    ; $ou : The OU to retrieve from
    ; $filter : optional, default "name'*'". An additional LDAP filter if required.
    ; $searchscope : optional, default 2. 0 = base, 1 = one-level, 2 = sub-tree
    ; $datatoretrieve : optional, default "Name". A comma-seperated list of values to retrieve. More than one value will create
    ; a 2-dimensional array, array[0][0] will contain the number of items returned, which start at array[1][0]

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

    Func _ADGetObjectsInOU(ByRef $ObjectArray, $ou, $filter = "name='*'", $searchscope = 2, $datatoretrieve = "sAMAccountName", $sortby = "sAMAccountName")
    Local $objRecordSet
    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties ("Page Size") = 1000
    $objCommand.Properties ("Searchscope") = $searchscope

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

    $strCmdText = "Select " & $datatoretrieve & " FROM 'LDAP://" & $strHostServer & "/" & $ou & "' WHERE " & $filter & " ORDER BY " & $sortby

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

    $objCommand.CommandText = $strCmdText
    $objRecordSet = $objCommand.Execute

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

    If StringInStr($datatoretrieve, ",") Then
    $dtrArray = StringSplit($datatoretrieve, ",")

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

    Dim $ObjectArray[$objRecordSet.RecordCount + 1][$dtrArray[0]]

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

    $ObjectArray[0][0] = $objRecordSet.RecordCount
    $ObjectArray[0][1] = $dtrArray[0]

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

    If $ObjectArray[0][0] = 0 Then Return 0

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

    $count = 1
    $objRecordSet.MoveFirst
    Do
    For $i = 1 To $dtrArray[0]
    $ObjectArray[$count][$i - 1] = $objRecordSet.Fields ($dtrArray[$i]).Value
    Next
    $objRecordSet.MoveNext
    $count += 1
    Until $objRecordSet.EOF
    Else
    Dim $ObjectArray[$objRecordSet.RecordCount + 1]
    $ObjectArray[0] = UBound($ObjectArray)-1
    If $ObjectArray[0] = 0 Then
    $ObjectArray = 0
    Return 0
    Else
    $count = 1
    $objRecordSet.MoveFirst
    Do
    $ObjectArray[$count] = $objRecordSet.Fields ($datatoretrieve).Value
    $objRecordSet.MoveNext
    $count += 1
    Until $objRecordSet.EOF
    EndIf
    EndIf
    Return 1

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

    EndFunc ;==>_ADGetObjectsInOU

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

    ; _ADDNToSamAccountName
    ; Takes a FQDN and returns the SamID of the account

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

    Func _ADDNToSamAccountName($fqdn)
    Local $obj

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

    $obj = ObjGet("LDAP://" & $strHostServer & "/" & $fqdn)
    If $obj = 0 Then
    MsgBox(0, "", "Failed to retrieve AD object")
    Return 0
    EndIf

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

    Return $obj.sAMAccountName
    EndFunc ;==>_ADDNToSamAccountName

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

    ; _ADSamAccountNameToFQDN
    ; Takes a SamID and returns the FQDN of the account

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

    Func _ADSamAccountNameToFQDN($samname)
    Local $strQuery, $objRecordSet

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $samname & ");distinguishedName;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery)

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

    If $objRecordSet.RecordCount = 1 Then
    Return $objRecordSet.fields (0).value
    Else
    Return ""
    EndIf
    EndFunc ;==>_ADSamAccountNameToFQDN

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

    ; _ADDNToDisplayName
    ; Returns the Display Name of an FQDN
    Func _ADDNToDisplayName($fqdn)
    Local $strQuery, $objRecordSet

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(distinguishedname=" & $fqdn & ");name;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the logged on user
    If $objRecordSet.EOF Then
    MsgBox(0, "", "Error, object not found")
    Else
    Return $objRecordSet.fields (0).value
    EndIf
    EndFunc ;==>_ADDNToDisplayName

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

    ; _ADCreateObject
    ; $objectou = OU to create the group in. Form is "sampleou=ou, sampleparent=ou, sampledomain1=dc, sampledomain2=dc, sampledomain3=dc"
    ; $object = Object name, form is SamAccountName without leading 'CN='
    ; $type = Type of object to create

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

    Func _ADCreateObject($objectou, $object, $type)
    Local $ObjOU, $ObjADObj

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

    If _ADObjectExists($object) Then Return 0

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

    If StringLeft($object, 3) <> "CN=" Then
    $object = "CN=" & $object
    EndIf

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

    $ObjOU = ObjGet("LDAP://" & $strHostServer & "/" & $objectou)
    $ObjADObj = $ObjOU.Create ($type, $object)

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

    $ObjADObj.Put ("sAMAccountName", StringTrimLeft($object, 3))
    If $type = "Computer" Then
    $ObjADObj.Put ("UserAccountControl", BitOR(0x0020, 0x1000))
    EndIf

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

    $ObjADobj.SetInfo
    Return 1
    EndFunc ;==>_ADCreateObject

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

    ; _ADCreateComputer
    ; $strComputer = Name of the computer object to create
    ; $computerOU = Full DN of the OU to create the computer in
    ; $strComputerUser = User or group that will be allowed to add the computer to the domain (SamAccountName)
    Func _ADCreateComputer($strComputer, $computerOU, $strComputerUser)
    Local $objContainer, $objComputer, $objSecurityDescriptor, $objDACL
    Local $objACE1, $objACE2, $objACE3, $objACE4, $objACE5, $objACE6
    Local $objACE7, $objACE8, $objACE9

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

    $objContainer = ObjGet("LDAP://" & $strHostServer & "/" & $computerOU)

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

    $objComputer = $objContainer.Create ("Computer", "cn=" & $strComputer)
    $objComputer.Put ("sAMAccountName", $strComputer & "$")
    $objComputer.Put ("userAccountControl", BitOR($ADS_UF_PASSWD_NOTREQD, $ADS_UF_WORKSTATION_TRUST_ACCOUNT))
    $objComputer.SetInfo

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

    $objSecurityDescriptor = $objComputer.Get ("ntSecurityDescriptor")
    $objDACL = $objSecurityDescriptor.DiscretionaryAcl

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

    $objACE1 = ObjCreate("AccessControlEntry")
    $objACE1.Trustee = $strComputerUser
    $objACE1.AccessMask = $ADS_RIGHT_GENERIC_READ
    $objACE1.AceFlags = 0
    $objACE1.AceType = $ADS_ACETYPE_ACCESS_ALLOWED

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

    $objACE2 = ObjCreate("AccessControlEntry")
    $objACE2.Trustee = $strComputerUser
    $objACE2.AccessMask = $ADS_RIGHT_DS_CONTROL_ACCESS
    $objACE2.AceFlags = 0
    $objACE2.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE2.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE2.ObjectType = $ALLOWED_TO_AUTHENTICATE

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

    $objACE3 = ObjCreate("AccessControlEntry")
    $objACE3.Trustee = $strComputerUser
    $objACE3.AccessMask = $ADS_RIGHT_DS_CONTROL_ACCESS
    $objACE3.AceFlags = 0
    $objACE3.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE3.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE3.ObjectType = $RECEIVE_AS

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

    $objACE4 = ObjCreate("AccessControlEntry")
    $objACE4.Trustee = $strComputerUser
    $objACE4.AccessMask = $ADS_RIGHT_DS_CONTROL_ACCESS
    $objACE4.AceFlags = 0
    $objACE4.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE4.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE4.ObjectType = $SEND_AS

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

    $objACE5 = ObjCreate("AccessControlEntry")
    $objACE5.Trustee = $strComputerUser
    $objACE5.AccessMask = $ADS_RIGHT_DS_CONTROL_ACCESS
    $objACE5.AceFlags = 0
    $objACE5.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE5.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE5.ObjectType = $USER_CHANGE_PASSWORD

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

    $objACE6 = ObjCreate("AccessControlEntry")
    $objACE6.Trustee = $strComputerUser
    $objACE6.AccessMask = $ADS_RIGHT_DS_CONTROL_ACCESS
    $objACE6.AceFlags = 0
    $objACE6.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE6.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE6.ObjectType = $USER_FORCE_CHANGE_PASSWORD

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

    $objACE7 = ObjCreate("AccessControlEntry")
    $objACE7.Trustee = $strComputerUser
    $objACE7.AccessMask = $ADS_RIGHT_DS_WRITE_PROP
    $objACE7.AceFlags = 0
    $objACE7.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE7.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE7.ObjectType = $USER_ACCOUNT_RESTRICTIONS

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

    $objACE8 = ObjCreate("AccessControlEntry")
    $objACE8.Trustee = $strComputerUser
    $objACE8.AccessMask = $ADS_RIGHT_DS_SELF
    $objACE8.AceFlags = 0
    $objACE8.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE8.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE8.ObjectType = $VALIDATED_DNS_HOST_NAME

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

    $objACE9 = ObjCreate("AccessControlEntry")
    $objACE9.Trustee = $strComputerUser
    $objACE9.AccessMask = $ADS_RIGHT_DS_SELF
    $objACE9.AceFlags = 0
    $objACE9.AceType = $ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
    $objACE9.Flags = $ADS_FLAG_OBJECT_TYPE_PRESENT
    $objACE9.ObjectType = $VALIDATED_SPN

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

    $objDACL.AddAce ($objACE1)
    $objDACL.AddAce ($objACE2)
    $objDACL.AddAce ($objACE3)
    $objDACL.AddAce ($objACE4)
    $objDACL.AddAce ($objACE5)
    $objDACL.AddAce ($objACE6)
    $objDACL.AddAce ($objACE7)
    $objDACL.AddAce ($objACE8)
    $objDACL.AddAce ($objACE9)

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

    $objSecurityDescriptor.DiscretionaryAcl = $objDACL
    $objComputer.Put ("ntSecurityDescriptor", $objSecurityDescriptor)
    $objComputer.SetInfo

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

    EndFunc ;==>_ADCreateComputer

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

    ; _ADDeleteObject
    ; $object = SamAccountName of object to delete. $type="user" or "group".
    ; Returns 0 if object doesn't exist, otherwise Returns 1
    Func _ADDeleteObject($ou, $object, $type)
    Local $objcn, $ObjOU

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

    $objcn = "CN=" & StringReplace($object, ",", "\,")
    $ObjOU = ObjGet("LDAP://" & $strHostServer & "/" & $ou)
    $objOU.Delete ($type, $objcn)

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

    Return 1
    EndFunc ;==>_ADDeleteObject

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

    ; _ADGetObjectClass
    ; Returns the Class of an object. Returns 0 if the object does not exist.
    Func _ADGetObjectClass($object)
    Local $strQuery, $objRecordSet, $ldap_entry, $oObject

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

    If _ADObjectExists($object) = 0 Then Return 0
    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $object & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the object
    $ldap_entry = $objRecordSet.fields (0).value
    $oObject = ObjGet($ldap_entry) ; Retrieve the COM Object for the object
    Return $oObject.Class

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

    EndFunc ;==>_ADGetObjectClass

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

    ; _ADGetObjectClassFromFQDN
    ; Returns the Class of an objectfrom an objects FQDN. Returns 0 if the object does not exist.
    Func _ADGetObjectClassFromFQDN($object)
    Local $oObject

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

    $object = StringReplace($object, "/", "\/")

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

    $oObject = ObjGet("LDAP://" & $strHostServer & "/" & $object) ; Retrieve the COM Object for the object
    If IsObj($oObject) = 0 Then Return 0
    Return $oObject.Class
    EndFunc ;==>_ADGetObjectClassFromFQDN

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

    ; _ADGetObjectAttribute
    ; Retrieves the specified (single-value) attribute for the given SamAccountName
    ; Returns 0 if the object does not exist, the attribute does not exist for that
    ; object or if the value is multi-string.
    ; Otherwise returns the result
    Func _ADGetObjectAttribute($object, $attribute)
    Local $strQuery, $objRecordSet, $ldap_entry, $oObject
    Local $result

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

    If _ADObjectExists($object) = 0 Then Return 0

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

    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $object & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the object
    $ldap_entry = $objRecordSet.fields (0).value
    $oObject = ObjGet($ldap_entry) ; Retrieve the COM Object for the object
    $result = $oObject.Get ($attribute)
    $oObject.PurgePropertyList

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

    If $result = "" Then
    Return ""
    Else
    Return $result
    EndIf

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

    EndFunc ;==>_ADGetObjectAttribute

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

    ; _ADListDomainControllers
    ; Retrieves the names of all domain controllers in the current Domain
    Func _ADListDomainControllers(ByRef $DCList)
    Local $objCommand, $objRecordSet, $temparray, $objRecSet2

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

    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties ("Page Size") = 1000
    $objCommand.Properties ("Searchscope") = 2

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

    $objCommand.CommandText = "Select distinguishedName FROM 'LDAP://" & $strHostServer & "/ou=Domain Controllers," & $strDNSDomain & "' WHERE objectclass='computer'"

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

    $objRecordSet = $objCommand.Execute
    Dim $DCList[$objRecordSet.RecordCount + 1]
    $objRecordSet.MoveFirst

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

    Do
    $DCList[0] += 1

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

    $objCommand.CommandText = "<LDAP://" & $strHostServer & "/" & $objRecordSet.Fields ("distinguishedName").Value & ">;;serverReferenceBL;Range=0-*;base"
    $objRecSet2 = $objCommand.Execute

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

    $objRecSet2.MoveFirst
    Do
    $temparray = $objRecSet2.Fields (0).Value
    $DCList[$DCList[0]] = $temparray[0]
    $objRecSet2.MoveNext
    Until $objRecSet2.EOF

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

    $objRecordSet.MoveNext
    Until $objRecordSet.EOF
    EndFunc ;==>_ADListDomainControllers

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

    ; _ADOUObjectNames
    ; A faster call for returning the Display Name of objects in a given OU
    Func _ADOUObjectNames(ByRef $objects, $ou, $filter = 0)
    Local $i, $objOU, $object, $j, $tempstr

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

    $objOU = ObjGet("LDAP://" & $strHostServer & "/" & $ou)

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

    If $filter <> 0 Then $objOU.Filter = $filter

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

    Dim $tempobjects[100000]

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

    $i = 0

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

    For $object In $objOU
    $tempobjects[$i] = $object.name
    $i+=1
    Next

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

    If $i = 0 Then
    $objects = 0
    Return
    EndIf

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

    Dim $objects[$i+1]
    $objects[0] = $i

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

    For $j = 1 To $i
    $tempstr = $tempobjects[$j-1]
    $tempstr = StringTrimLeft($tempstr,3)
    $objects[$j] = StringReplace($tempstr,"\,",",")
    Next

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

    EndFunc ;==>_ADOUObjectNames

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

    ; Function _ADGetAllGroups
    Func _ADGetAllGroups(ByRef $groups,$path)
    Local $objects, $item

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

    $objects = ObjGet("LDAP://" & $strHostServer & "/" & $path)
    For $item In $objects
    If $item.class = "group" then
    _ArrayAdd ($groups, $item.distinguishedName)
    $groups[0] = Ubound($groups)-1
    Else
    _ADGetAllGroups($groups,$item.distinguishedName)
    EndIf
    Next
    Return
    EndFunc
    ; End Function _ADGetAllGroups

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

    ; Function _ADGetAllUsers
    Func _ADGetAllUsers(ByRef $users,$path)
    Local $objects, $item

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

    $objects = ObjGet("LDAP://" & $strHostServer & "/" & $path)
    For $item In $objects
    If $item.class = "user" then
    _ArrayAdd ($users, $item.distinguishedName)
    $users[0] = Ubound($users)-1
    Else
    _ADGetAllUsers($users,$item.distinguishedName)
    EndIf
    Next
    Return
    EndFunc
    ; End Function _ADGetAllUsers

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

    ; Function _ADGetWellKnownSIDName
    Func _ADGetWellKnownSIDName($dn)
    Local $sid
    $sid = StringMid($dn,StringInStr($dn,"CN=")+3)
    $sid = StringStripWS(StringLeft($sid,StringInStr($sid,",")-1),2)
    Select
    Case $sid = "S-1-5-32-544"
    Return("Administratoren")
    Case $sid = "S-1-5-32-547"
    Return("Hauptbenutzer")
    Case $sid = "S-1-5-32-551"
    Return("Sicherungs-Operatoren")
    Case $sid = "S-1-5-32-545"
    Return("Benutzer")
    Case $sid = "S-1-5-7"
    Return("Anonymous-Anmeldung")
    Case $sid = "S-1-5-11"
    Return("Authentifizierte Benutzer")
    Case $sid = "S-1-5-3"
    Return("Batch")
    Case $sid = "S-1-3-0"
    Return("Ersteller-Besitzer")
    Case $sid = "S-1-3-1"
    Return("Erstellergruppe")
    Case $sid = "S-1-5-1"
    Return("Dialup")
    Case $sid = "S-1-1-0"
    Return("Jeder")
    Case $sid = "S-1-5-4"
    Return("Interaktiv")
    Case $sid = "S-1-5-18"
    Return("System")
    Case $sid = "S-1-5-2"
    Return("Netzwerk")
    Case $sid = "S-1-5-10"
    Return("Selbst")
    Case $sid = "S-1-5-6"
    Return("Service")
    Case $sid = "S-1-5-13"
    Return("TerminalserverBenutzer")
    Case $sid = "S-1-5-1000"
    Return("Andere Organisation")
    Case $sid = "S-1-5-15"
    Return("Diese Organisation")
    Case Else
    Return("")
    EndSelect
    EndFunc
    ; End Function _ADGetWellKnownSIDName

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

    ; Function _ADGetPrimaryGroupID
    Func _ADGetPrimaryGroupID($userdn)
    Local $item
    $item = ObjGet("LDAP://" & $userdn)
    Return ($item.primaryGroupID)
    EndFunc
    ; End Function _ADGetPrimaryGroupID

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

    ; Function _ADGetPrimaryGroupDN
    Func _ADGetPrimaryGroupDN($sid)
    Local $objCon, $objCom, $RS, $PrimaryGroup
    $PrimaryGroup = ""
    $objCon = ObjCreate("ADODB.Connection")
    $objCon.Provider = "ADsDSOObject"
    $objCon.Open ("Active Directory Provider")
    $objCom = ObjCreate("ADODB.Command")
    $objCom.ActiveConnection = $objCon
    $objCom.CommandText = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;" & "(&(objectcategory=group)" & ");" & "distinguishedName,primaryGroupToken,cn;" & "subtree;"
    $objCom.Properties("Page Size") = 1000
    $RS = $objCom.Execute
    While Not $RS.EOF And $PrimaryGroup = ""
    If ($RS.Fields("primaryGroupToken").value) = $sid then $PrimaryGroup = $RS.Fields("distinguishedName").Value
    $RS.moveNext()
    Wend
    $objCon.Close()
    Return ($PrimaryGroup)
    EndFunc
    ; Function _ADGetPrimaryGroupDN

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

    hat einer noch eine idee? vielleicht ist etwas zu umständlich programmiert!

    gruß gmmg

    Einmal editiert, zuletzt von gmmg (26. Juni 2009 um 22:37)

  • hallo zusammen,

    im folgenden quellcode abschnitt, bekommen ich fehlermeldungen!

    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(316,15) : ERROR: 'ExitLoop' not allowed outside loop.
    ExitLoop
    ~~~~~~~~^
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(336,5) : ERROR: syntax error
    Else
    ^

    hat einer ne idee?

    [autoit]


    zeile 303 If $jn = 6 Then ;wenn ja gedrückt dann

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

    while 1
    Sleep(1)
    ;HotKeySet("{PRINTSCREEN}", "Capture_start")
    ;HotKeySet("+!d", "Capture_start") ;Shift-Alt-d
    HotKeySet("^{F4}", "Capture_start") ;Strg-F4
    WEnd

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

    Func Capture_start()
    ; Capture full screen
    _ScreenCapture_Capture(@MyDocumentsDir & "\Printscreen.jpg")
    MsgBox(0,"","Screenshot erstellt!",1)
    ExitLoop
    EndFunc

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

    ; nach aktueller zeit oder wochenende
    IF _NowTime() > "18:00:00" or _NowTime() < "08:00:00" or @WDAY = 7 or @WDAY = 1 Then
    Global $CAddress = "steuerung@xxxxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    ; nach feiertagen
    IF $day = $ft1 or $day = $ft2 or $day = $ft3 or $day = $ft4 or $day = $ft5 or $day = $ft6 Then
    Global $CAddress = "steuerung@xxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    Sendmail()
    Exit
    ;###################
    Else ; nein gedrückt
    ;MsgBox(0,"","test")
    ; nach aktueller zeit oder wochenende
    IF _NowTime() > "18:00:00" or _NowTime() < "08:00:00" or @WDAY = 7 or @WDAY = 1 Then
    Global $CAddress = "steuerung@xxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    ; nach feiertagen
    IF $day = $ft1 or $day = $ft2 or $day = $ft3 or $day = $ft4 or $day = $ft5 or $day = $ft6 Then
    Global $CAddress = "steuerung@xxxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    Sendmail()
    EndIf

    [/autoit]

    oder kommt die fehlermeldung nur mit dem AutoIt3Wrapper v.2.0.0.1?

    hier die fehlermeldun gen mit dem tidy:

    Spoiler anzeigen


    Tidy AutoIt3 v2.0.28.3 Copyright (c) Jos van der Zande April 29, 2009
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(314) : ### Tidy Error -> "if" Not closed before "Func" statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(314) : ### Tidy Error -> "func" cannot be inside any IF/Do/While/For/Case/Func statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(361) : ### Tidy Error -> "endswitch" is closing previous "case" on line 160
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(363) : ### Tidy Error -> "wend" is closing previous "switch" on line 158
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(367) : ### Tidy Error -> "while" Not closed before "Func" statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(367) : ### Tidy Error -> "func" cannot be inside any IF/Do/While/For/Case/Func statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(412) : ### Tidy Error -> "while" Not closed before "Func" statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(412) : ### Tidy Error -> "func" cannot be inside any IF/Do/While/For/Case/Func statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(465) : ### Tidy Error -> "while" Not closed before "Func" statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(465) : ### Tidy Error -> "func" cannot be inside any IF/Do/While/For/Case/Func statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(481) : ### Tidy Error -> "while" Not closed before "Func" statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(481) : ### Tidy Error -> "func" cannot be inside any IF/Do/While/For/Case/Func statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(513) : ### Tidy Error -> "while" Not closed before "Func" statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(513) : ### Tidy Error -> "func" cannot be inside any IF/Do/While/For/Case/Func statement.
    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(155) : ### Tidy Error -> "while" is never closed in your script.
    !> there were 15 error(s) encountered. look in your source for:### Tidy Error:

    gruß gmmg

  • Wenn du die Fehlermeldung liest, sollte es doch eigentlich klar werden oder?

    Zitat

    C:\scripte\01_Helpdesk\it_helpdesktool_mailsversand_und_SMS_incl.tabs_incl.screenshot_aktuell.au3(316,15) : ERROR: 'ExitLoop' not allowed outside loop.
    ExitLoop

    In der Funktion wo du es aufrufst, gibt es keine Schleife. Das muß bestimmt EXIT sein.

    Auszu aus der Hilfe
    Exit Beendet das Skript.
    ExitLoop Beendet eine While-, Do- oder For-Schleife.

    Wieso dein Else net funktioniert sehe ich auf die schnelle auchnet.

    MfG
    Der_Doc

  • @ Der_Doc

    das script selbst funktioniert auch, wenn ich beim ausführen dann auf "continue anyway" klicke! (scite version 1.78 als editor)
    das exit_loop ist dafür da, um aus der while wend schleife zu springen!

    deshalb ja auch meine frage, ob das vielleicht falsch od. zu umständlich programmiert ist!

    zum verständnis ... folgendes will ich erreichen: wenn ich auf den senden button klicke öffnet sich eine msgbox mit JA/Nein, hier wird abgefragt, ob ein screenshot gemacht werden soll oder nicht! wenn ja, dann soll das tool so lange in der schleife warten, bis eine tastenkombi gedrückt wird!
    wenn dies dann gedrückt wurde, soll ein screenshot erzeugt werden und das ganze dann an die smtp function zum senden ausgeführt werden!

    hast du da ne idee?

    gruß gmmg

  • hallo zusammen,

    benötige hilfe bei einem code schnipsel!
    der betroffene bereich ist im script auskommentiert!

    hier das script!

    Spoiler anzeigen
    [autoit]


    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=..\Icons\ICONGROUP_32515.ico
    #AutoIt3Wrapper_outfile=IT-Helpdesk.exe
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GUIConstants.au3>
    #include <File.au3>
    #include <Array.au3>
    #include <adfunctions.au3>
    #include <ScreenCapture.au3>
    #include <Date.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>

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

    $mail = _ADGetObjectAttribute(@UserName,"mail")
    $username = @UserName

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

    ;----------------------------------
    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("", 341, 390, 198, 150, 0x00040000, 0x00000080)
    ;WinSetTrans($Form1, "", 500) ;fenster transparent machen
    GUICtrlSetDefColor(0xFF0000) ;setzt textfarbe für alle elemente
    GUISetBkColor(0xFFFF00) ; setzt hintergrundfarbe
    ;GUICtrlSetColor(-1, 0xFFFFFF)
    ;DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 7)
    $Group2 = GUICtrlCreateGroup("IT-Helpdesk - Call: 0700-0000000 (14 Cent/Min)", 8, 8, 324, 354)
    $Edit1 = GUICtrlCreateEdit("", 36, 122, 257, 73)
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetData(-1, StringFormat(""))
    $Button1 = GUICtrlCreateButton("Senden", 36, 242, 121, 33)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    $Button2 = GUICtrlCreateButton("Abbruch", 172, 242, 121, 33)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    $Label2 = GUICtrlCreateLabel(@UserName & " / " & @ComputerName & " / " & @IPAddress1, 28, 316, 280, 17, 0x01)
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
    $Checkbox1 = GUICtrlCreateCheckbox("Dringend", 36, 210, 193, 17)
    GUICtrlSetColor(-1, 0xFF0000)
    DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 7)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Wähle das System!", 36, 42, 112, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Combobox1 = GUICtrlCreateCombo("", 36, 66, 129, 25)
    GUICtrlSetData(-1, "As400|Amadeus|Bistro|Blank|Buma|Drucker|Galileo|Jack|Mediatrix|Merlin|Produktdb|PC|Sonstiges|Telefon")
    GUICtrlSetFont(-1, 9, 400, 0, "Arial")
    $Label1 = GUICtrlCreateLabel("Gib eine Fehlerbeschreibung ein!", 36, 98, 191, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label4 = GUICtrlCreateLabel("testf", 95, 336, 150, 14)
    GUICtrlSetFont(-1, 7, 400, 0, "Arial")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    ; feiertage festlegen
    $ft1 ="01.01"
    $ft2 ="01.05"
    $ft3 ="03.10"
    $ft4 ="31.10"
    $ft5 ="25.12"
    $ft6 ="26.12"

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

    ; datum (tag, monat) festlegen
    $day = @MDAY & "."& @MON

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

    While 1
    $nMsg = GUIGetMsg()

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

    Switch $nMsg

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

    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $Combobox1
    GUICtrlSetState($Button1, $GUI_ENABLE)

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

    Case $Checkbox1

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

    ;checkbox überprüfen und anhand des rückgabewertes sms freischalten oder auch nicht
    If GUICtrlRead($Checkbox1, $GUI_CHECKED)= $GUI_CHECKED Then
    $cb1 = GUICtrlRead($Checkbox1, $GUI_CHECKED)
    Else
    $cb1 = GUICtrlRead($Checkbox1, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    Case $Button1
    GUICtrlSetState($Button2, $GUI_DISABLE)

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

    ;######################################
    ; combobox1 auf wert prüfen
    ;######################################
    If GUICtrlRead($Combobox1, $GUI_CHECKED)= $GUI_CHECKED Then
    $cbo1 = GUICtrlRead($Combobox1, $GUI_CHECKED)
    Else
    $cbo1 = GUICtrlRead($Combobox1, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    IF $cbo1 = False Then
    $cboa1 = GUICtrlRead($Combobox1, $GUI_CHECKED)
    Else
    $cboa1 = " "
    EndIf
    ;-----------
    ;MsgBox(0, "gewählt", $cba1)

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

    Global $answer_combo1 = GUICtrlRead($Combobox1)
    ;MsgBox(0, "gewählt", $answer_combo1)

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

    ;######################################
    ; checkbox1 auf wert prüfen
    ;######################################
    If GUICtrlRead($Checkbox1, $GUI_CHECKED)= $GUI_CHECKED Then
    $cb1 = GUICtrlRead($Checkbox1, $GUI_CHECKED)
    Else
    $cb1 = GUICtrlRead($Checkbox1, $GUI_UNCHECKED)= $GUI_UNCHECKED
    EndIf

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

    IF $cb1 = False Then
    $cba1 = GUICtrlRead($Checkbox1, $GUI_CHECKED)
    Else
    $cba1 = " "
    EndIf
    ;MsgBox(0, "gewählt", $cba2)
    $answer = GUICtrlRead($Edit1)

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

    If IsMemberOf("Callcenter",@UserName) = 1 Or IsMemberOf("Callcenter-Flug",@UserName) = 1 Then
    Global $CAddress = "steuerung@xxxxxx.de"
    Else
    Global $CAddress = ""
    EndIf

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

    If IsMemberOf("team-buchhaltung",@UserName) = 1 Then
    Global $sCAddress = "bhaltung@xxxxx.de"
    Else
    Global $CAddress = ""
    EndIf

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

    ; Frage --> Datei -- Screenshot anhängen
    ;----------------------------------------
    Global $var = (@MyDocumentsDir & "\Printscreen.jpg")
    Global $jn = MsgBox(4, "Hinweis!", "Screenshot anhängen JA/NEIN ?" & @CRLF & @CRLF & "Button JA anklicken, Fenster mit Fehlermeldung auswählen" & @CRLF & "und Tastenkombination STRG+F4 drücken!"& @CRLF)
    If $jn = 6 Then ;wenn ja gedrückt dann

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

    ;~ while 1
    ;~ Sleep(1)
    ;~ ;HotKeySet("{PRINTSCREEN}", "Capture_start")
    ;~ ;HotKeySet("+!d", "Capture_start") ;Shift-Alt-d
    ;~ HotKeySet("^{F4}", "Capture_start") ;Strg-F4
    ;~ WEnd

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

    ;~ Func Capture_start()
    ;~ ; Capture full screen
    ;~ _ScreenCapture_Capture(@MyDocumentsDir & "\Printscreen.jpg")
    ;~ MsgBox(0,"","Screenshot erstellt!",1)
    ;~ ExitLoop
    ;~ EndFunc

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

    ;~ ; nach aktueller zeit oder wochenende
    ;~ IF _NowTime() > "18:00:00" or _NowTime() < "08:00:00" or @WDAY = 7 or @WDAY = 1 Then
    ;~ Global $CAddress = "steuerung@xxxxx.de"
    ;~ Sendmail()
    ;~ MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    ;~ Exit
    ;~ EndIf
    ;~ ; nach feiertagen
    ;~ IF $day = $ft1 or $day = $ft2 or $day = $ft3 or $day = $ft4 or $day = $ft5 or $day = $ft6 Then
    ;~ Global $CAddress = "steuerung@xxxxxxx.de"
    ;~ Sendmail()
    ;~ MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    ;~ Exit
    ;~ EndIf
    ;~ Sendmail()
    ;~ Exit
    ;###################
    Else ; nein gedrückt
    ;MsgBox(0,"","test")
    ; nach aktueller zeit oder wochenende
    IF _NowTime() > "18:00:00" or _NowTime() < "08:00:00" or @WDAY = 7 or @WDAY = 1 Then
    Global $CAddress = "steuerung@xxxxxxxm.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    ; nach feiertagen
    IF $day = $ft1 or $day = $ft2 or $day = $ft3 or $day = $ft4 or $day = $ft5 or $day = $ft6 Then
    Global $CAddress = "steuerung@xxxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    Sendmail()
    EndIf

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

    Exit
    Case $Button2
    Exit
    EndSwitch
    WEnd
    #Region------------------------------------Functions----------------------------

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

    Func Sendmail()

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

    ; message definieren
    $bodymsg = ("PC Login: " & @UserName & @CRLF & "IP Addresse: " & @IPAddress1 & @CRLF & "Computername: "& @ComputerName & @CRLF & "System: "& $answer_combo1 & @CRLF & @CRLF & "Fehlerbeschreibung: " & @CRLF & @CRLF & $answer)

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

    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc_1")
    ;##################################
    ; Variables
    ;##################################
    $s_SmtpServer = "0.0.0.0" ; address for the smtp-server to use - REQUIRED
    $s_FromName = $username ; name from who the email was sent
    $s_FromAddress = $mail ; address from where the mail should come
    $s_ToAddress = "support@xxxxx.de" ; destination address of the email - REQUIRED
    ;$s_Subject = "";$sb ; subject from the email - can be anything you want it to be
    $s_Subject = "Supportmeldung " & $answer_combo1 & " - " & @ComputerName &" --" & $cba1
    $s_Body = $bodymsg ; the messagebody from the mail - can be left blank but then you get a blank mail
    IF $jn = 6 Then ; the file you want to attach- leave blank if not needed
    $s_AttachFiles = $var
    Else
    $s_AttachFiles = ""
    EndIf
    $s_CcAddress = $CAddress ; address for cc - leave blank if not needed
    $s_BccAddress = "" ; address for bcc - leave blank if not needed
    $s_Username = "tool" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail)
    $s_Password = "xxxxxxx" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail)
    $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

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

    ;##################################
    ; Script
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc_1")
    $rc = _INetSmtpMailCom_1($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf

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

    EndFunc ;==>Sendmail

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

    ;###################################################

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

    Func _INetSmtpMailCom_1($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)
    $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($s_Body,"<") and StringInStr($s_Body,">") Then
    $objEmail.HTMLBody = $s_Body
    Else
    $objEmail.Textbody = $s_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])
    If FileExists($S_Files2Attach[$x]) Then
    $objEmail.AddAttachment ($S_Files2Attach[$x])
    Else
    $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
    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
    $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
    ; Sent the Message
    $objEmail.Send
    If @error Then
    SetError(2)
    return $oMyRet[1]
    EndIf
    EndFunc ;==>_INetSmtpMailCom
    ;
    ;
    ; Com Error Handler
    Func MyErrFunc_1()
    $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_1
    ;---------------------------------------------------------

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

    ; IsMemberOf
    ; Takes the groupname (SamAccountName with or without the leading 'CN=', and the SamAccountName of the user
    ; Returns 1 if the the user is a member of the group, 0 otherwise

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

    Func IsMemberOf($group, $user)
    If StringLeft($group, 3) <> "CN=" Then
    $group = "CN=" & $group
    EndIf
    Dim $usergroups[1], $i = 1

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

    Dim $objConnection, $oUsr

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

    $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD
    $objConnection.Provider = "ADsDSOObject"
    $objConnection.Open ("Active Directory Provider") ; Open connection to AD

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

    $objRootDSE = ObjGet("LDAP://RootDSE")
    Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext") ; Retrieve the current AD domain name

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

    $strQuery = "<LDAP://" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute ($strQuery) ; Retrieve the FQDN for the logged on user
    $ldap_entry = $objRecordSet.fields (0).value
    $oUsr = ObjGet($ldap_entry) ; Retrieve the COM Object for the logged on user
    $groups = $oUsr.groups ; Get the list of group objects from the user

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

    For $groupname In $groups
    If $groupname.name = $group Then Return 1

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

    Next
    Return 0

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

    EndFunc ;==>IsMemberOf

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

    #EndRegion---------------------------------Endfunctions-------------------------

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

    bekomme im folgenden code fehler!
    kann da mal einer schauen, ob man das optimaler lösen kann?

    nach dem drücken auf den senden button kommt die abfraghe ob ein screenshot gemacht werden soll, wenn ja ist das script in einer while schleife u. da gibts dann probleme!

    [autoit]


    ; Frage --> Datei -- Screenshot anhängen
    ;----------------------------------------
    Global $var = (@MyDocumentsDir & "\Printscreen.jpg")
    Global $jn = MsgBox(4, "Hinweis!", "Screenshot anhängen JA/NEIN ?" & @CRLF & @CRLF & "Button JA anklicken, Fenster mit Fehlermeldung auswählen" & @CRLF & "und Tastenkombination STRG+F4 drücken!"& @CRLF)
    If $jn = 6 Then ;wenn ja gedrückt dann

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

    while 1
    Sleep(1)
    ;HotKeySet("{PRINTSCREEN}", "Capture_start")
    ;HotKeySet("+!d", "Capture_start") ;Shift-Alt-d
    HotKeySet("^{F4}", "Capture_start") ;Strg-F4
    WEnd

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

    Func Capture_start()
    ; Capture full screen
    _ScreenCapture_Capture(@MyDocumentsDir & "\Printscreen.jpg")
    MsgBox(0,"","Screenshot erstellt!",1)
    ExitLoop
    EndFunc

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

    ; nach aktueller zeit oder wochenende
    IF _NowTime() > "18:00:00" or _NowTime() < "08:00:00" or @WDAY = 7 or @WDAY = 1 Then
    Global $CAddress = "steuerung@xxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    ; nach feiertagen
    IF $day = $ft1 or $day = $ft2 or $day = $ft3 or $day = $ft4 or $day = $ft5 or $day = $ft6 Then
    Global $CAddress = "steuerung@xxxxxx.de"
    Sendmail()
    MsgBox(0,"Info", "Bitte an die Steuerung wenden!",5)
    Exit
    EndIf
    Sendmail()
    Exit

    [/autoit]

    fehlermeldungen:

    Spoiler anzeigen

    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(157,20) : ERROR: missing EndIf.
    Func
    ~~~~~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(148,55) : REF: missing EndIf.
    If $jn = 6 Then ;wenn ja gedrückt dann
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(157,20) : ERROR: missing EndSwitch.
    Func
    ~~~~~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(67,16) : REF: missing EndSwitch.
    Switch $nMsg
    ~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(157,20) : ERROR: missing Wend.
    Func
    ~~~~~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(64,1) : REF: missing Wend.
    While
    ^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(161,32) : ERROR: 'ExitLoop' not allowed outside loop.
    ExitLoop
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(181,16) : ERROR: syntax error
    Else
    ~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(132,52) : ERROR: IsMemberOf(): undefined function.
    If IsMemberOf("Callcenter",@UserName)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3(167,33) : ERROR: Sendmail(): undefined function.
    Sendmail()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\scripte\01_Helpdesk\IT-Helpdesk.au3 - 7 error(s), 0 warning(s)

    danke im voraus ;)

    gruß gmmgl

  • lösung meines problems, hab es nun selbst herausgefunden!
    in der wile schleife rufe ich durch hotkeyset die screenshot funktion auf!
    um nun nach gemachten screenshot die schleife zu beenden, muss ich in der funktion eine variable setzen, die ich dann in der schleife abfrage!

    [autoit]


    ;-----------codeauschnitt ------------------
    If $jn = 6 Then ;wenn ja gedrückt dann

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

    Dim $sc = 0
    while 1
    Sleep(1)
    HotKeySet("^{F4}", "Capture_start") ;Strg-F4
    If $sc = 1 Then ExitLoop
    WEnd

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

    Func Capture_start()
    ; Capture full screen
    _ScreenCapture_Capture(@MyDocumentsDir & "\Printscreen.jpg")
    MsgBox(0,"","Screenshot erstellt!",1)
    $sc = 1
    EndFunc

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