I suddenly remembered the code bank when I did a post in the General VB Forum. Might be useful to some. Anyways, to delete a section from an INI file, you use the WritePrivateProfileString API. A typical code example would look something like this:
VB Code:
'this goes into the declaration section of the 'code Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long Public sub DeleteKey Dim sSection As String Dim sKey As String Dim sFileName as String sSection = "Section1" sKey = "Key1" sFileName="C:\MyINIFILE.INI" 'if the key exists, delete it from the section If len(trim(sKey)) <>0 Then WritePrivateProfilestring sSection, sKey, _ vbNullString, sFileName Else 'no key specified, then delete section WritePrivateProfileString _ sSection,sKey,vbNullString,sFileName End If End Sub




Reply With Quote