the below is the best i have.
pass it the ini file name and the section you are interested in and you get a dict object.
i know its not editing but i use it alot so might be of some use.
Function ParseINI(strIniFileName, strSection2Find)
Set FSO = WScript.CreateObject("Scripting.FileSystemObject"
'strIniFileName = "d:\vbs\xp\w2kinst.ini"
Err.Clear
Set tsIni = FSO.OpenTextFile(strIniFileName)
If Err.Number <> 0 Then
msgbox "cant find ini file"
End If
Do While Not tsIni.AtEndOfStream
sLine = ""
sLine = Trim(tsIni.ReadLine)
If sLine <> "" Then
If Left(sLine,1) <> ";" Then
If Left(sLine,1) = "[" Then
'Msgbox sLine & " section found"
strSection = Left(sLine, Len(sLine) - 1)
strSection = Right(strSection, Len(strSection) - 1)
If LCase(strSection) = LCase(strSection2Find) Then
Set ParseINI = Wscript.CreateObject("Scripting.Dictionary"
End If
Else
'key and value logic
intEquals = InStr(1, sLine, "="
If (intEquals <= 1) Then
'msgbox "error: the following line is invalid " & sLine
Else
'weve found a valid line
sKey = Left(sLine, intEquals - 1)
sVal = Right(sLine, Len(sLine) - intEquals)
If LCase(strSection) = LCase(strSection2Find) Then
Err.Clear
ParseINI.Add sKey, sVal
If Err.Number <> 0 Then
msgbox "unable to add to dictionary object"
End If
'msgbox strSection & " " & sKey & ";;;;" & sVal
Else
'msgbox strSection & " " & skey & ";;;;" & sVal
End If
'key and value logic end if
End If
End If
End If
End If
Loop
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.