Tipp 7.5 - Section in INI löschen

Wie kann ich eine komplette Section in einer INI-Datei löschen?

Mit dieser Funktion können Sie eine komplette Section in einer INI-Datei löschen. Kopieren Sie einfach nachfolgenden Quellcode in die Zwischenablage und fügen Sie anschließend den Inhalt der Zwischenablage in ein neues Modul ein. Die Aufrufparameter finden Sie im Quellcode beschrieben.

Api-AufrufeVerwendete Win32-Api-Aufrufe und Typen: WritePrivateProfileSection

Beispiel:

Option Explicit
 
Private Declare Function WritePrivateProfileSection Lib "kernel32.dll" Alias _
                        "WritePrivateProfileSectionA" _
                        (ByVal lpAppName As String, _
                         ByVal lpString As String, _
                         ByVal lpFileName As String) As Long
 
Public Function KillMyINISection(ByVal sIniFilePath As String, _
                                 ByVal sSection As String) As Boolean
'// -----------------------------------------------------------------
'// Methode:   | Löscht eine komplette Section in einer INI-Datei
'// -----------------------------------------------------------------
'// Parameter: | sIniFilePath = gültiger INI-Dateipfad
'//            | sSection = zu löschende Sektion
'// -----------------------------------------------------------------
'// Rückgabe:  | True bei Erfolg
'// -----------------------------------------------------------------
    On Error GoTo Err_KillMyINISection
 
    KillMyINISection = _
    WritePrivateProfileSection(sSection, vbNullString, sIniFilePath)
 
Exit_KillMyINISection:
    On Error GoTo 0
    Exit Function
 
Err_KillMyINISection:
    GoTo Exit_KillMyINISection
 
End Function