User einlesen

  • Moin Moin zusammen.

    Folgendes GUI besteht und ich möchte in das Listfeld alle Benutzer auswählen können, die sich an dem PC anmelden können.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("Sperrung / Freigabe", 417, 315, 287, 147)
    $Label1 = GUICtrlCreateLabel("Benutzername", 10, 72, 109, 24)
    $List1 = GUICtrlCreateList("Benutzer 1", 120, 72, 289, 24)
    $Label2 = GUICtrlCreateLabel("Montag", 29, 122, 49, 17)
    $Label3 = GUICtrlCreateLabel("Dienstag", 23, 150, 55, 20)
    $Label4 = GUICtrlCreateLabel("Mittwoch", 27, 176, 51, 19)
    $Label5 = GUICtrlCreateLabel("Donnerstag", 8, 204, 70, 18)
    $Label6 = GUICtrlCreateLabel("Freitag", 36, 231, 42, 20)
    $Label7 = GUICtrlCreateLabel("Samstag", 25, 258, 53, 19)
    $Label8 = GUICtrlCreateLabel("Sonntag", 29, 285, 49, 19)
    $Label9 = GUICtrlCreateLabel("von", 89, 104, 24, 16)
    $Label10 = GUICtrlCreateLabel("bis", 122, 105, 20, 14)
    $Input1 = GUICtrlCreateInput("0", 88, 120, 25, 24)
    $Input2 = GUICtrlCreateInput("23", 120, 120, 25, 24)
    $Input3 = GUICtrlCreateInput("0", 88, 147, 25, 24)
    $Input4 = GUICtrlCreateInput("23", 120, 147, 25, 24)
    $Input5 = GUICtrlCreateInput("0", 88, 174, 25, 24)
    $Input6 = GUICtrlCreateInput("23", 120, 174, 25, 24)
    $Input7 = GUICtrlCreateInput("0", 88, 201, 25, 24)
    $Input8 = GUICtrlCreateInput("23", 120, 201, 25, 24)
    $Input9 = GUICtrlCreateInput("0", 88, 228, 25, 24)
    $Input10 = GUICtrlCreateInput("23", 120, 228, 25, 24)
    $Input11 = GUICtrlCreateInput("0", 88, 255, 25, 24)
    $Input12 = GUICtrlCreateInput("23", 120, 255, 25, 24)
    $Input13 = GUICtrlCreateInput("0", 88, 282, 25, 24)
    $Input14 = GUICtrlCreateInput("23", 120, 282, 25, 24)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

    [/autoit]

    Eigentlich möchte ich, das ich die Benutzer nicht manuell ins Script eingeben muss, sondern das sie ausgelesen werden.

    Danke bereits hier für Eure Hilfe.

    Lieben Gruß,
    Alina

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

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

  • Kenne nur diese CMD Möglichkeit:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <array.au3>
    $Form1 = GUICreate("Sperrung / Freigabe", 417, 315, 287, 147)
    $Label1 = GUICtrlCreateLabel("Benutzername", 10, 72, 109, 24)
    $List1 = GUICtrlCreateList("", 120, 72, 289, 24)
    GUICtrlSetData(-1, _ReturnUser())
    $Label2 = GUICtrlCreateLabel("Montag", 29, 122, 49, 17)
    $Label3 = GUICtrlCreateLabel("Dienstag", 23, 150, 55, 20)
    $Label4 = GUICtrlCreateLabel("Mittwoch", 27, 176, 51, 19)
    $Label5 = GUICtrlCreateLabel("Donnerstag", 8, 204, 70, 18)
    $Label6 = GUICtrlCreateLabel("Freitag", 36, 231, 42, 20)
    $Label7 = GUICtrlCreateLabel("Samstag", 25, 258, 53, 19)
    $Label8 = GUICtrlCreateLabel("Sonntag", 29, 285, 49, 19)
    $Label9 = GUICtrlCreateLabel("von", 89, 104, 24, 16)
    $Label10 = GUICtrlCreateLabel("bis", 122, 105, 20, 14)
    $Input1 = GUICtrlCreateInput("0", 88, 120, 25, 24)
    $Input2 = GUICtrlCreateInput("23", 120, 120, 25, 24)
    $Input3 = GUICtrlCreateInput("0", 88, 147, 25, 24)
    $Input4 = GUICtrlCreateInput("23", 120, 147, 25, 24)
    $Input5 = GUICtrlCreateInput("0", 88, 174, 25, 24)
    $Input6 = GUICtrlCreateInput("23", 120, 174, 25, 24)
    $Input7 = GUICtrlCreateInput("0", 88, 201, 25, 24)
    $Input8 = GUICtrlCreateInput("23", 120, 201, 25, 24)
    $Input9 = GUICtrlCreateInput("0", 88, 228, 25, 24)
    $Input10 = GUICtrlCreateInput("23", 120, 228, 25, 24)
    $Input11 = GUICtrlCreateInput("0", 88, 255, 25, 24)
    $Input12 = GUICtrlCreateInput("23", 120, 255, 25, 24)
    $Input13 = GUICtrlCreateInput("0", 88, 282, 25, 24)
    $Input14 = GUICtrlCreateInput("23", 120, 282, 25, 24)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

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

    Func _ReturnUser()
    Local $CMDRead, $sUser
    $CMD = Run(@ComSpec & " /c net user", @SystemDir, @SW_HIDE, 0x2)
    While 1
    $CMDRead &= StdoutRead($CMD)
    If @error Then ExitLoop
    WEnd
    $CMDRead = StringRegExp($CMDRead, "(.+?) ", 3)
    For $i = 0 To UBound($CMDRead) - 1
    If StringStripWS($CMDRead[$i], 8) <> '' Then $sUser &= StringStripWS($CMDRead[$i], 8) & "|"
    Next
    Return StringTrimRight($sUser, 1)
    EndFunc ;==>_ReturnUser

    [/autoit]
  • Hi, also erstma würde ich eine "Combo" machen, ich denke, dass entspricht mehr deinen wünschen, denn bei der Liste kannst du nur einen Benutzer auswählen ;D. Und in deiner While Schleife fehlt noch "Case $Combo1", sobald du eine Combo erstellt hast (Bei Coda immer bei den Optionen unten auf mitteilen drücken, dann mird das automatisch gemacht). Aber noch eine Verständnisfrage: Willst du da unten auswählen können, wie lange jeder Benutzer am PC war?

  • Hallo Blubbstar.

    Wenn es fertig ist kommt es on ! ;)


    Edit:
    Sicherlich ist es um einiges besser zu scripten, aber ich hatte da was gelesen und geschaut, ob man es mit AutoIt umsetzen kann.

    Spoiler anzeigen
    [autoit]


    #cs
    Danke an :
    blubbstar = _ReturnUser()
    KingLoL = Combo statt List
    Blume = Zeile 87 und nachfolgende Zeilen
    #ce

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

    #include <GUIConstantsEx.au3>
    #include <String.au3>
    $Form1_1 = GUICreate("Logintimer", 417, 315, 287, 147)
    $Label1 = GUICtrlCreateLabel("Benutzername", 10, 72, 109, 24)
    $Combo1 = GUICtrlCreateCombo("", 160, 72, 249, 25)
    GUICtrlSetData(-1, _ReturnUser())
    $Label2 = GUICtrlCreateLabel("Montag", 29, 122, 49, 20)
    $Label3 = GUICtrlCreateLabel("Dienstag", 23, 150, 58, 20)
    $Label4 = GUICtrlCreateLabel("Mittwoch", 27, 176, 55, 20)
    $Label5 = GUICtrlCreateLabel("Donnerstag", 8, 204, 74, 20)
    $Label6 = GUICtrlCreateLabel("Freitag", 36, 231, 46, 20)
    $Label7 = GUICtrlCreateLabel("Samstag", 25, 258, 58, 20)
    $Label8 = GUICtrlCreateLabel("Sonntag", 29, 285, 54, 20)
    $Label9 = GUICtrlCreateLabel("von", 88, 104, 26, 14)
    $Label10 = GUICtrlCreateLabel("bis", 122, 104, 22, 14)
    $Input1 = GUICtrlCreateInput("0", 88, 120, 25, 24)
    $Input2 = GUICtrlCreateInput("24", 120, 120, 25, 24)
    $Input3 = GUICtrlCreateInput("0", 88, 147, 25, 24)
    $Input4 = GUICtrlCreateInput("24", 120, 147, 25, 24)
    $Input5 = GUICtrlCreateInput("0", 88, 174, 25, 24)
    $Input6 = GUICtrlCreateInput("24", 120, 174, 25, 24)
    $Input7 = GUICtrlCreateInput("0", 88, 201, 25, 24)
    $Input8 = GUICtrlCreateInput("24", 120, 201, 25, 24)
    $Input9 = GUICtrlCreateInput("0", 88, 228, 25, 24)
    $Input10 = GUICtrlCreateInput("24", 120, 228, 25, 24)
    $Input11 = GUICtrlCreateInput("0", 88, 255, 25, 24)
    $Input12 = GUICtrlCreateInput("24", 120, 255, 25, 24)
    $Input13 = GUICtrlCreateInput("0", 88, 282, 25, 24)
    $Input14 = GUICtrlCreateInput("24", 120, 282, 25, 24)
    $Label14 = GUICtrlCreateLabel("L O G I N - T I M E R", 104, 8, 227, 33)
    GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
    $Label15 = GUICtrlCreateLabel("Du entscheidest, wann wer sich an dem PC anmeldet", 88, 40, 256, 17)
    $plus = GUICtrlCreateButton("Einschränken setzen", 160, 248, 123, 25, 0)
    $minus = GUICtrlCreateButton("Freigabe aller Einschränkungen", 160, 280, 251, 25, 0)
    $ergebnis = GUICtrlCreateButton("Einschränken ansehen", 286, 248, 123, 25, 0)
    $Label11 = GUICtrlCreateLabel("Nutzungshinweise", 232, 112, 106, 17)
    GUICtrlSetFont(-1, 8, 800, 4, "MS Sans Serif")
    $Label12 = GUICtrlCreateLabel("+ Einschränkungen immer nur volle Stunden.", 174, 128, 215, 18)
    $Label13 = GUICtrlCreateLabel("+ Nutzung auf eigene Gefahr.", 204, 145, 144, 14)
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $plus
    ;net user Benutzer /times:Mo,7-21;Di,7-21;Mi,7-21;Do,7-21;Fr,7-21
    Run("net user " & GUICtrlRead($Combo1) & " /times:Mo," & GUICtrlRead($Input1) & "-" &GUICtrlRead($Input2) & ";Di,"& GUICtrlRead($Input3) & "-" & GUICtrlRead($Input4) & ";Mi,"& GUICtrlRead($Input5) & "-" & GUICtrlRead($Input6) & ";Do,"& GUICtrlRead($Input7) & "-" & GUICtrlRead($Input8) & ";Fr,"& GUICtrlRead($Input9) & "-" & GUICtrlRead($Input10) & ";Sa,"& GUICtrlRead($Input11) & "-" & GUICtrlRead($Input12) & ";So,"& GUICtrlRead($Input13) & "-" & GUICtrlRead($Input14))
    sleep(500)
    msgBox(0,"Einschränkungen", "Einschränkungen aktiviert")
    Case $minus
    ; net user Benutzer /times:all
    Run("net user " & GUICtrlRead($Combo1) & " /times:all")
    sleep(500)
    msgBox(0,"Einschränkungen", "Einschränkungen deaktiviert")
    Case $ergebnis
    ; net user Benutzer
    FileDelete(@ScriptDir & "/info.txt")
    sleep(200)
    Run(@ComSpec & " /c net user "& GUICtrlRead($Combo1) & " >>info.txt")
    Sleep(200)
    ; Blume's Idee; Diese Funktion heute gleich zwei mal verwendet. ;)
    $sText = FileRead(@ScriptDir & "/info.txt")
    Sleep(200)
    $sStart = "Anmeldezeiten"
    $sEnde = "Lokale"
    $sText = _StringBetween($sText, $sStart, $sEnde)
    $sText = $sText[0]
    $sText = $sStart & $sText
    MsgBox(0,"Ergebniss",$sText)
    EndSwitch
    WEnd
    Func _ReturnUser()
    Local $CMDRead, $sUser
    $CMD = Run(@ComSpec & " /c net user", @SystemDir, @SW_HIDE, 0x2)
    While 1
    $CMDRead &= StdoutRead($CMD)
    If @error Then ExitLoop
    WEnd
    $CMDRead = StringRegExp($CMDRead, "(.+?) ", 3)
    For $i = 0 To UBound($CMDRead) - 1
    If StringStripWS($CMDRead[$i], 8) <> '' Then $sUser &= StringStripWS($CMDRead[$i], 8) & "|"
    Next
    Return StringTrimRight($sUser, 1)
    EndFunc ;==>_ReturnUser

    [/autoit]

    Exe-Datei: autoit.de/wcf/attachment/12973/

    Dateien

    Lieben Gruß,
    Alina

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

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

    Einmal editiert, zuletzt von Alina (29. März 2011 um 22:00)

  • Hier die WMI Version, um die Benutzer auszulesen:

    Spoiler anzeigen
    [autoit]


    #include <GuiComboBox.au3>
    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("Sperrung / Freigabe", 417, 315, 287, 147)
    $Label1 = GUICtrlCreateLabel("Benutzername", 10, 72, 109, 24)
    $hCombo = GUICtrlCreateCombo("", 120, 72, 289, 24)
    GUICtrlSetData(-1, Get_Users())
    _GUICtrlComboBox_SetCurSel ($hCombo, 0)
    $Label2 = GUICtrlCreateLabel("Montag", 29, 122, 49, 17)
    $Label3 = GUICtrlCreateLabel("Dienstag", 23, 150, 55, 20)
    $Label4 = GUICtrlCreateLabel("Mittwoch", 27, 176, 51, 19)
    $Label5 = GUICtrlCreateLabel("Donnerstag", 8, 204, 70, 18)
    $Label6 = GUICtrlCreateLabel("Freitag", 36, 231, 42, 20)
    $Label7 = GUICtrlCreateLabel("Samstag", 25, 258, 53, 19)
    $Label8 = GUICtrlCreateLabel("Sonntag", 29, 285, 49, 19)
    $Label9 = GUICtrlCreateLabel("von", 89, 104, 24, 16)
    $Label10 = GUICtrlCreateLabel("bis", 122, 105, 20, 14)
    $Input1 = GUICtrlCreateInput("0", 88, 120, 25, 24)
    $Input2 = GUICtrlCreateInput("23", 120, 120, 25, 24)
    $Input3 = GUICtrlCreateInput("0", 88, 147, 25, 24)
    $Input4 = GUICtrlCreateInput("23", 120, 147, 25, 24)
    $Input5 = GUICtrlCreateInput("0", 88, 174, 25, 24)
    $Input6 = GUICtrlCreateInput("23", 120, 174, 25, 24)
    $Input7 = GUICtrlCreateInput("0", 88, 201, 25, 24)
    $Input8 = GUICtrlCreateInput("23", 120, 201, 25, 24)
    $Input9 = GUICtrlCreateInput("0", 88, 228, 25, 24)
    $Input10 = GUICtrlCreateInput("23", 120, 228, 25, 24)
    $Input11 = GUICtrlCreateInput("0", 88, 255, 25, 24)
    $Input12 = GUICtrlCreateInput("23", 120, 255, 25, 24)
    $Input13 = GUICtrlCreateInput("0", 88, 282, 25, 24)
    $Input14 = GUICtrlCreateInput("23", 120, 282, 25, 24)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

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

    Func Get_Users($system = ".")
    Local $Users
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $system & "\root\cimv2")
    Local $colItems = $objWMIService.ExecQuery("SELECT Caption FROM Win32_UserAccount WHERE Disabled = False", "WQL", 0x30)
    For $objItem In $colItems
    $Users &= $objItem.Caption & "|"
    Next
    Return $Users
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯