Vbscript needed for reading value from a file.

Posted on 2008-06-17
Last Modified: 2012-05-05
I need to read the value of a parameter from a file.

Which code do I have to use if I the value of the parameter is present in the file in this format.


How can I retrieve eg. the value of parameter2 ?
Question by:itbabe
1 Comment

Accepted Solution

Zippit earned 500 total points
Comment Utility
Here is a function that will do so for you.
MsgBox getValue("C:\Documents and Settings\username\Desktop\sample.txt", "parameter1")

Function getValue(filePath, paramName)

    Dim fso     'As Scripting.FileSystemObject

    Dim ts      'As Scripting.TextStream

    Dim line    'As String

    Dim tokens  'As Variant

    Dim rv      'As String


    Set fso = CreateObject("Scripting.FileSystemObject")

    Set ts = fso.OpenTextFile(filePath, ForReading)


    Do While Not ts.AtEndOfStream

        line = ts.ReadLine


        tokens = Split(line, "=")


        If Trim(LCase(tokens(0))) = Trim(LCase(paramName)) Then

            rv = tokens(1)

            Exit Do

        End If


    Set fso = Nothing

    getValue = rv

End Function

Open in new window


Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now