Reading an INI file using VBScript

I'm looking for code to read an INI file in VBScript.

Is there something already in VBScript that'll let me do this, or will I need to use FSO/TextStream/etc. for it?

I would prefer to read it into something like a Dictionary/Collection type object but not essential.

Please provide sample code to illustrate.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

U can use FSO in ur project to read and write into files and for all other file manipulation activities.
Please refer following sample code to explain FSO.

'Set References to Microsoft Scripting Runtime in your VB project.

strFileName = path to ini

Private Function AutoLogin(ByVal strFileName As String) As Boolean
Dim Fso As New FileSystemObject
Dim TxtStream As TextStream
Dim strReadLine As String
Dim strReadAll As String
Dim blnGotLogin As Boolean
Dim intPos As Long
Dim blnReplaceFile As Boolean

Set TxtStream = Fso.OpenTextFile(strFileName, ForReading)
Do Until TxtStream.AtEndOfStream = True
    strReadLine = TxtStream.ReadLine
    If blnGotLogin = False Then
        'you must obviously know what you are looking for
        'if you wish to adjust to check for more than just "AutoLogin" then just follow
        'same procedure
        intPos = InStr(1, strReadLine, "Auto Login=")
        If intPos <> 0 Then
            blnGotLogin = True
            'check if the option has been set
            If Len(strReadLine) < intPos + 1 Then
                strReadLine = "Auto Login=1"
                blnReplaceFile = True
                'check if a 1 has been set
                If InStr(intPos + 1, strReadLine, "1") <> 0 Then
                    AutoLogin = True
                    'no need to read anymore unless something else is required from ini
                    Exit Do
                    'if you want to set auto login
                    strReadLine = "Auto Login=1"
                    blnReplaceFile = True
                End If
            End If
        End If
    End If
    'add end of line character
    strReadLine = strReadLine & vbCrLf
    strReadAll = strReadAll & strReadLine


If blnReplaceFile = True Then
    Fso.DeleteFile strFileName, True
    Set TxtStream = Fso.OpenTextFile(strFileName, ForWriting, True)
    TxtStream.Write strReadAll
End If

End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.