Die Ini kannst du mit folgendem Code manipulieren:
Function INI_Write(INI_Path As String, INI_FileName As String,INI_Section As String,INI_Variable As String,INI_Value As String,ErrorMessage As String) As Variant
' this function will locate a given ini file and look for the given section and variable within that inifile. If it does not find the section it will add the section
' the variable and the value.
' if it does find the section it will look for the variable. if it does not find the variable within the given section it will add the variable and the value
' if it does find the variable it will add the new value.
' to use this function parameters MUST be specified in the given format....
' INI_PATH example ..... "C:\Windows\"
' INI_FileName example .... "notes.ini"
' INI_Section example .... "[Notes]"
' INI_Variable example .... "Directory"
' INI_Value example .... "c:\notes\data"
' ErrorMessage is used to hold the value of the error message. If the function fails you can find the error message here.
' return values for errors
' INIWrite_Path_Not_Found
' INIWrite_File_Not_Found
INI_Write = True
INI_Section = Ucase$(Trim$(INI_Section)) ' convert to uppercase and trim spaces
INI_Variable = Ucase$(Trim$(INI_Variable)) ' convert to uppercase and trim spaces
Dim FileName As String
Dim FileHandle As Integer
Dim TempLine As String
Dim Counter As Long
Dim IniFileLines() As String
Dim SectionFound As Variant
Dim VariableFound As Variant
Dim ArrayIndex1 As Long
Dim ArrayIndex2 As Long
Dim OutPutArray As Variant
Dim EqualSignPosition As Integer
' first thing to do is check for the existence of the path.
On Error 76 Resume Next ' Error is Path not found
FileName = Dir$(INI_Path & "*.*", 0)
If Error() = "Path not found" Then
Print "Path Not Found."
INI_Write = False
ErrorMessage = "INIWrite_Path_Not_Found"
Exit Function
End If
' second thing to do is check for the existence of the file.
FileName = Dir$(INI_Path & INI_FileName,0)
If FileName = "" Then
Print "File Not Found"
INI_Write = False
ErrorMessage = "INIWrite_File_Not_Found"
Exit Function
End If
' get a file handle
FileHandle = Freefile
' open the file
Open INI_Path & INI_FileName For Input Access Read As FileHandle
' now read in the file line by line into an array
Counter = 0
Do While Not Eof(FileHandle)
Line Input #FileHandle , TempLine
Redim Preserve IniFileLines(Counter) As String
IniFileLines(Counter) = Ucase$(Trim$(TempLine))
Counter = Counter + 1
Loop
Close #FileHandle
' now look for the section
SectionFound = False
VariableFound = False
For ArrayIndex1 = 0 To Counter - 1
If IniFileLines(ArrayIndex1) = INI_Section Then ' found the correct section
SectionFound = True
For ArrayIndex2 = ArrayIndex1 + 1 To Counter - 1 ' look for the variable
If Left$(IniFileLines(ArrayIndex2),1) = "[" And Right$(IniFileLines(ArrayIndex2),1) = "]" Then ' found next section without finding variable add the variable here.
' insert variable and value
Call InsertIntoArray(IniFileLines,Counter,ArrayIndex2,INI_Variable & " = " & INI_Value)
VariableFound = True
Exit For
Else
If Not Left$(IniFileLines(ArrayIndex2),1) = ";" Then ' is not a comment
' Locate equal sign in the string
EqualSignPosition = Instr(IniFileLines(ArrayIndex2),"=")
If Not EqualSignPosition = 0 Then ' found the equal sign
If Trim(Left$(IniFileLines(ArrayIndex2),EqualSignPosition - 1)) = INI_Variable Then ' found correct variable
VariableFound = True
' replace the variable and the value
IniFileLines(ArrayIndex2) = INI_Variable & " = " & INI_Value
Exit For
End If
Else
If Not IniFileLines(ArrayIndex2) = "" Then ' append equal sign to the line
IniFileLines(ArrayIndex2) = IniFileLines(ArrayIndex2) & " = "
End If
End If
End If
End If
Next
Exit For
End If
Next
If SectionFound = False Then ' section never found, insert section, variable and value
' insert section
Call InsertIntoArray(IniFileLines,Counter-1,Counter,INI_Section)
' insert variable and value
Call InsertIntoArray(IniFileLines,Counter,Counter+1,INI_Variable & " = " & INI_Value)
Else
If VariableFound = False Then 'variable never found, insert variable and value
' insert variable and value
Call InsertIntoArray(IniFileLines,Counter-1,Counter,INI_Variable & " = " & INI_Value)
End If
End If
' write the values of the array out to the ini file
' get a file handle
FileHandle = Freefile
' open the file
Open INI_Path & INI_FileName For Output Access Write As FileHandle
Print Cstr(Ubound(IniFileLines))
For ArrayIndex1 = 0 To Ubound(IniFileLines)
If Not IniFileLines(ArrayIndex1) = "" Then
If Left$(IniFileLines(ArrayIndex1),1) = "[" And Right$(IniFileLines(ArrayIndex1),1) = "]" Then ' found next section
Print #FileHandle , ""
End If
Print #FileHandle , IniFileLines(ArrayIndex1)
End If
Next
Close #FileHandle
End Function
Jetzt musst du nur noch ein bisschen Code um die Function herumschreiben, der die Ini in allen Verzeichnissen der User sucht und dann ensprechend anpasst.
eknori