ini

  • Hab eine ini und möchte daraus einen Pfad auslesen. Ich brauch die Anzahl der Einträge(section) unter [Pfade] ! um weitere Einträge (key) hinzufügen zu können.

    Code
    [Profile]
    profil=C:\Program Files\AutoIt3\Include\test
    
    
    [Pfade]
    profile=C:\Program Files\AutoIt3\Include\Profil1
    profil1=C:\Program Files\AutoIt3\Include\Profil13
    profil2=C:\Program Files\AutoIt3\Include\Profil123

    Einmal editiert, zuletzt von gabischatz (1. März 2010 um 21:48)

  • Hier mal kompletten Quelltext , bekomme keine neuen Einträge hin!

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=chrome.ico
    #AutoIt3Wrapper_outfile=ChromeStarter.exe
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GuiStatusBar.au3>
    #include <GuiListBox.au3>
    #include <zip.au3>
    #include <IE.au3>

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

    Global $wertePfadeAusINI, $nameExplorerAusINI, $auswahlAusCombofeld, $anzahl, $pfadangaben
    Global $sSettingsName = "PFADE.ini"
    Global $menutext
    Global $dateiname = "profil.zip"
    Global $aktPfad = @ScriptDir
    Global $pfadangaben = "Profile"
    Global $i = 0
    #Region ### START Koda GUI section ### Form=
    $frm_Starter = GUICreate("Profilstarter", 284, 148, 499, 283, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
    GUISetIcon(@ScriptDir & "\Crome.ico")
    ;$cbo_box1 = GUICtrlCreateCombo("Profil", 8, 80, 265, 25)
    Global $btn_starter = GUICtrlCreateButton("Start", 200, 112, 75, 25, $WS_GROUP)
    Global $btn_abbrechen = GUICtrlCreateButton("Abbrechen", 120, 112, 75, 25, $WS_GROUP)
    Global $inp_Profil = GUICtrlCreateInput("", 8, 24, 265, 21)
    Global $btn_gohttp = GUICtrlCreateButton("Download", 120, 48, 75, 25, $WS_GROUP)
    Global $btn_goNeu = GUICtrlCreateButton("Erstellen", 200, 48, 75, 25, $WS_GROUP)
    $lbl_neu = GUICtrlCreateLabel("Neues Profil / Name eingeben", 8, 6, 147, 17)
    $lbl_profiel = GUICtrlCreateLabel("Zu startendes Profil", 8, 62, 95, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    If Not FileExists ($sSettingsName) Then IniWrite ($sSettingsName, "Profile", "profil", @ScriptDir&"\Profil");prüfen ob PFADE.ini existiert
    ;_____________________________________________________________________________

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

    $cbo_box1 = GUICtrlCreatecombo ("", 8, 80, 265, 25)
    _PfadeAusINI()

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

    Func _PfadeAusINI()
    $wertePfadeAusINI = IniReadSection($aktPfad & "\" & $sSettingsName, $pfadangaben)
    For $anzahl = 1 To $wertePfadeAusINI[0][0]
    if @error = 2 then
    else
    GUICtrlSetData(-1,$wertePfadeAusINI[$anzahl][1])
    endif
    next
    ; ;Return $wertePfadeAusINI[$anzahl][0]
    EndFunc

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

    Func MeinKopieren()
    $auswahlAusCombofeld = GUICtrlRead($cbo_box1, 1)
    ClipPut($auswahlAusCombofeld)
    EndFunc
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE,$btn_abbrechen
    Exit
    ;_________________________________________
    Case $cbo_box1
    Call ("MeinKopieren")
    If FileExists ($auswahlAusCombofeld) Then
    IniWrite ($sSettingsName, "Pfade", "profile", $auswahlAusCombofeld)
    GUICtrlSetState($btn_starter,$GUI_ENABLE)
    else
    MsgBox(48," << Benutzerfehler >>", $auswahlAusCombofeld & @CRLF & @CRLF & "existiert NICHT !!!")
    GUICtrlSetState($btn_starter,$GUI_DISABLE)
    EndIf
    ;_______________________________________________
    Case $btn_starter
    Local $val = Run('GoogelChromeLoader.exe',@ScriptDir)
    $PID = ProcessExists('GoogelChromeLoader.exe') ; Gibt die PID des Prozesses zurück oder 0, falls der Prozess nicht gefunden wurde.
    ProcessWait('GoogelChromeLoader.exe',3)
    ;MsgBox(8256,'Information',"ist da")
    If $PID Then ProcessClose($PID)
    Exit
    ;_______________________________________________
    Case $btn_gohttp

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

    $vorher = 0

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

    $ort = @ScriptDir ;FileSelectFolder("Speicherort auswählen", "", 3, @ScriptDir)
    $Refresh = 1000
    If Not @error Then
    FileDelete($ort & "" & $dateiname)
    InetGet("https://sites.google.com/site/99947lgs/home/download/profil.zip?attredirects=0&d=1", $ort & "\" & $dateiname, 1, 1)
    While @InetGetActive
    $speed = ((@InetGetBytesRead - $vorher) / 1024) * (1000 / $Refresh)
    $vorher = @InetGetBytesRead
    ;ToolTip("KiloBytes = " & @InetGetBytesRead / 1024 & @CRLF & "Geschwindigkeit:" & $speed & " kb/s", 10, 16)
    Sleep($Refresh)
    WEnd
    Else
    MsgBox(16, "", "Kein Pfad ausgewählt!")
    EndIf
    MsgBox(48, "Download & Update", "Der Download war Erfolgreich."&@CRLF _
    & "Das Programm ist nun auf dem Neusten stand.")

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

    Case $btn_goNeu
    ;MsgBox(4096, "Ergebnis", $var)
    $menutext=GUICtrlRead($inp_Profil)
    dim $Phat=@ScriptDir & "\" & $menutext
    dim $PhatTemp=@ScriptDir&"\Temp"
    dim $var_zip = @ScriptDir & "\" & $dateiname
    If $menutext<>"" Then
    DirCreate ($PhatTemp)

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

    ;MsgBox(4096,"Ergebnis", $Phat & @CRLF _
    ;& $PhatTemp& @CRLF _
    ;& $Phat)
    _Zip_UnzipAll($var_zip, $PhatTemp, 4) ; quelle, ziel, flag

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

    _DirRename($PhatTemp, $Phat)

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

    While 1 ; Endlosschleife bis ExitLoop aufgerufen wird
    $wertePfadeAusINI = IniReadSection($aktPfad & "\" & $sSettingsName, $pfadangaben)
    MsgBox(4096, " << Benutzerfehler >>",$wertePfadeAusINI[$anzahl][0] ) ; <-------Hier
    If $i = $wertePfadeAusINI[$anzahl][0] Then
    ;MsgBox(4096, " << Benutzerhinweis >>",$i&" Sie müssen einen Profilname eintragen.")
    IniWrite ($sSettingsName, "Pfade", "profil"& $i+1 , $Phat)
    ExitLoop
    EndIf
    $i = $i + 1

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

    WEnd

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

    IniWrite ($sSettingsName, "Profile", "profil", $Phat)
    GUICtrlSetData ($cbo_box1,$Phat)

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

    EndIf
    EndSwitch
    WEnd
    ;===============================================================================
    ; Function Name: _DirRename($sSourcePath, $sNewFolderName, $sComputer='.')
    ; Description:: Ordner auf lokalem oder Remote-PC umbenennen
    ; Parameter(s): $sSourcePath der volle Pfad des umzubenennenden Ordners
    ; $sNewFolderName der neue Ordnername (Name oder Pfad möglich)
    ; wenn Pfad mit angegeben, wird dieser autom. entfernt
    ; [optional] $sComputer Computername, Standard: der lokale PC
    ; Return Value(s): Erfolg 1
    ; Fehler 0 @error 1 Ordner existiert nicht
    ; 2 Zielordner existiert bereits
    ; 3 Umbenennen fehlgeschlagen
    ; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
    ;
    ;; Aufruf:
    ;_DirRename('C:\test', 'C:\Neu')
    ; oder auch
    ;_DirRename('C:\test', 'Neu')

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

    ;===============================================================================
    Func _DirRename($sSourcePath, $sNewFolderName, $sComputer='.')
    If Not FileExists($sSourcePath) Then Return SetError(1,0,0)
    $sSourcePath = StringRegExpReplace($sSourcePath, '\\+\z', '')
    Local $sParent = StringLeft($sSourcePath, StringInStr($sSourcePath, '\', 1, -1))
    $sSourcePath = StringRegExpReplace($sSourcePath, '\\', '\\\\')
    $sNewFolderName = StringRegExpReplace($sNewFolderName, '\\+\z', '')
    Local $ret = StringRegExp($sNewFolderName, '(?:\\)(\w+\z)|\w+', 3)
    $sNewFolderName = $ret[UBound($ret)-1]
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sComputer & "\root\cimv2")
    Local $colFolders = $objWMIService.ExecQuery ("Select * from Win32_Directory where name = '" & $sSourcePath & "'")
    Local $err
    For $objFolder In $colFolders
    $err = $objFolder.Rename($sParent & $sNewFolderName)
    If $err = 0 Then
    Return 1
    ElseIf $err = 10 Then
    Return SetError(2,0,0)
    Else
    Return SetError(3,0,0)
    EndIf
    Next
    EndFunc ;==>_DirRename

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

    Einmal editiert, zuletzt von gabischatz (2. März 2010 um 17:02)

  • geht immer noch nicht , sind immer noch nur 2 Einträge

    Spoiler anzeigen
    [autoit]


    While 1 ; Endlosschleife bis ExitLoop aufgerufen wird
    $wertePfadeAusINI = IniReadSection($aktPfad & "\" & $sSettingsName, $pfadangaben)
    If $i = $wertePfadeAusINI[$anzahl][0] Then
    IniWrite ($sSettingsName, "Pfade", "profil"& UBound($wertePfadeAusINI)+1, $Phat)
    ExitLoop
    EndIf
    $i = $i + 1
    WEnd

    [/autoit]
  • ist mir doch durch den Sturm der Pc abgestürzt. bekomme jetzt folgende Fehlermeldung und weis nicht was sie bedeutet
    C:\Program Files\AutoIt3\Include\_Chromestart.au3 (45) : ==> Subscript used with non-Array variable.:

  • Bin heut etwas neben der Spur und blick das auch nicht wirklich ....
    Du willst doch nur einen Pfad in die INI schreiben, oder? Wozu diese While Schleife? Selbst wenn da mehrere Pfade eingetragen werden sollen erscheint mir der Ansatz etwas merkwürdig.

    einen einzigen Pfad kannst du doch so einfügen ....

    [autoit]

    $wertePfadeAusINI = IniReadSection($aktPfad & "\" & $sSettingsName, $pfadangaben)
    IniWrite ($sSettingsName, "Pfade", "profil" & UBound($wertePfadeAusINI), $Phat) ;$wertePfadeAusINI)+1 dürfte nicht nötig sein da in $result[0][0] lediglich die Länge des Arrays steht.

    [/autoit]


    (ob du die Länge per UBound() ermittelst oder aus $array[0][0] liest musst du wissen. Ich benutz lieber UBound)

    Wenn es mehrere Pfade sein sollen, ermittle die Anzahl der einzutragenden Pfade und bau eine For Schleife drumrum. For $i=0 To $anzahlpfade -1 .... .

  • Hallo

    hier ein allgemeines Beispiel zu IniWriteSection mit einem Array:

    Spoiler anzeigen
    [autoit]

    #include <array.au3>

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

    Local $sIni = @ScriptDir & "\test.ini"
    Local $aData1[99][2]

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

    For $i = 1 To UBound($aData1) - 1
    $aData1[$i][0] = "Profil" & $i
    $aData1[$i][1] = random(1,9,1)
    Next

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

    IniWriteSection($sIni, "Sektion1", $aData1) ; Schreibt in eine neue Sektion

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

    _ArrayDisplay($aData1,"Original")
    $aData1 = IniReadSection($sIni,"Sektion1")
    _ArrayDisplay($aData1,"aus Ini")

    [/autoit]

    mfg (Auto)Bert

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

    $cbo_box1 = GUICtrlCreatecombo ("", 8, 80, 265, 25)
    _PfadeAusINI()

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

    Func _PfadeAusINI()

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

    Local $sIni = @ScriptDir & "\" & "\test.ini" ;$sSettingsName
    $aData1 = IniReadSection($sIni,"Profil")
    _ArrayDisplay($aData1,"aus Ini")

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

    ;$wertePfadeAusINI = IniReadSection($aktPfad & "\" & $sSettingsName, $pfadangaben)
    $i = 0
    While 1 ; Endlosschleife bis ExitLoop aufgerufen wird
    if @error = 2 then
    ExitLoop
    else
    GUICtrlSetData(-1,$aData1[0][$i]) ; <-------fehler
    endif
    $i = $i+ 1
    WEnd

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

    ; ;Return $wertePfadeAusINI[$anzahl][0]
    EndFunc

    [/autoit]
  • Ich würds so machen, spart Codezeilen und umgeht diese doofe While...WEnd Schleife:

    Spoiler anzeigen
    [autoit]

    $cbo_box1 = GUICtrlCreatecombo ("", 8, 80, 265, 25)
    _PfadeAusINI()

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

    Func _PfadeAusINI()
    Local $sIni = @ScriptDir & "\" & "\test.ini" ;$sSettingsName
    $aData1 = IniReadSection($sIni,"Profil")
    ;~ _ArrayDisplay($aData1)
    If Not @error Then
    For $i = 1 To $aData1[0][0]
    GUICtrlSetData($cbo_box1, $aData1[$i][0]
    Next
    EndIf
    EndFunc

    [/autoit]

    PS: Ich habs ausm Kopf geschrieben, kann sein, dass ein Fehler drin ist.