Robust VBScript functions to read from and overwrite values in .ini
files, supporting any kind of file encoding.
Most of the code is a collection of snippets that have been modified and assembled together. :)
- VBScript (VBS) only
This project includes two files:
-
getFileEncoding.vbs
Determines the file's encoding type.
(Logic adapted from Rob van der Woude’s script and turned into a function that returns the correct parameter forOpenTextFile()
.) -
iniHandler.vbs
Provides two functions:WriteToIni(path, section, key, newValue)
readFromIni(path, section, key)
-
Copy both files into your working directory.
-
In your script, use the following to include the functions:
'-------------------------- ' Import other functions Sub Include(strFile) Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile(strFile, 1) ExecuteGlobal objTextFile.ReadAll objTextFile.Close Set objFSO = Nothing Set objTextFile = Nothing End Sub ' Include handlers Include("iniHandler.vbs") '--------------------------
-
Example usage:
value = readFromIni("file.ini", "section", "key") WriteToIni("file.ini", "section", "key", "newValue")
- Currently does not support appending new sections or keys. This may be added in the future.
Enjoy! 😃