With this vbscript you will be able to read INI files.
Source:
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim sIniFile, sSectionName, sValueName, fso, sDefaultValue
Init
wscript.echo ReadIni(sIniFile, sSectionName, sValueName, sDefaultValue)
wscript.Quit(1) 'Exit successfully
Function ReadIni(sIniFile, sSectionName, sValueName, sDefaultValue)
Dim fi, sLine, bSectionFound
Set fi = fso.OpenTextFile(sIniFile, ForReading, False)
bSectionFound = False
ReadIni = sDefaultValue
Do While Not fi.AtEndOfStream
sLine = fi.ReadLine
If IsSection(sLine) Then
bSectionFound = IsSectionName(sLine, sSectionName)
Else
If bSectionFound Then
If Not IsComment(sLine) Then
If IsValueName(sLine, sValueName) Then
ReadIni = ExtractValue(sLine, sDefaultValue)
Exit Do
End If
End If
End If
End If
Loop
fi.Close
End Function
Function ExtractValue(sLine, sDefaultValue)
ExtractValue = sDefaultValue
If IsValue(sLine) Then
ExtractValue = Mid(sLine, Instr(sLine, "=") + 1)
End If
End Function
Function IsSection(sLine)
IsSection = Left(LTrim(sLine),1) = "["
End Function
Function IsValue(sLine)
IsValue = Not IsComment(sLine) And Not IsSection(sLine) And Instr(sLine,"=") > 0
End Function
Function IsSectionName(sLine, sSectionName)
Dim sTmpLine, sTmpSectionName
sTmpLine = LTrim(sLine)
IsSectionName = IsSection(sTmpLine)
sTmpSectionName = Mid(sTmpLine,2)
sTmpSectionName = Split(sTmpSectionName,"]")(0)
IsSectionName = IsSectionName And Cmp(sSectionName, sTmpSectionName)
End Function
Function IsComment(sLine)
IsComment = Left(LTrim(sLine),1) = ";"
End Function
Function IsValueName(sLine, sValueName)
Dim sTmpValueName
IsValueName = IsValue(sLine)
sTmpValueName =""
If Instr(sLine,"=") > 0 Then
sTmpValueName = Split(sLine,"=")(0)
End If
IsValueName = IsValueName And Cmp(sValueName, sTmpValueName)
End Function
Function Cmp(s0, s1)
Cmp = UCase(Trim(s0)) = UCase(Trim(s1))
End Function
Sub Init()
Set fso = CreateObject("Scripting.FileSystemObject")
If wscript.arguments.Count <> 3 And wscript.arguments.Count <> 4 Then
DoUsage "IniFile SectionName ValueName [DefaultValue]"
wscript.Quit(2) 'Exit on error
End If
sIniFile = wscript.arguments(0)
sSectionName = UCase(Trim(wscript.arguments(1)))
sValueName = UCase(Trim(wscript.arguments(2)))
If wscript.arguments.Count = 4 Then
sDefaultValue = Trim(wscript.arguments(3))
Else
sDefaultValue = ""
End If
End Sub
Sub DoUsage(sArg)
wscript.stderr.writeLine "Usage:" & vbCRLF
wscript.stderr.writeLine wscript.ScriptName & " " & sArg
End Sub
