https://github.com/naftaliprojects/vbs-.ini-file-handler
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. :)
https://github.com/naftaliprojects/vbs-.ini-file-handler
encoding include ini-parser parser vbscript
Last synced: 5 months ago
JSON representation
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. :)
- Host: GitHub
- URL: https://github.com/naftaliprojects/vbs-.ini-file-handler
- Owner: NaftaliProjects
- Created: 2025-05-21T18:35:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-21T18:41:04.000Z (about 1 year ago)
- Last Synced: 2025-06-24T06:40:02.743Z (12 months ago)
- Topics: encoding, include, ini-parser, parser, vbscript
- Language: VBScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vbs iniHandler
## About
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. :)
## Requirements
- VBScript (VBS) only
## Project Structure
This project includes two files:
1. **`getFileEncoding.vbs`**
Determines the file's encoding type.
_(Logic adapted from [Rob van der Woude’s script](https://www.robvanderwoude.com/vbstech_files_encoding.php) and turned into a function that returns the correct parameter for `OpenTextFile()`.)_
2. **`iniHandler.vbs`**
Provides two functions:
- `WriteToIni(path, section, key, newValue)`
- `readFromIni(path, section, key)`
## How to Use
1. Copy both files into your working directory.
2. In your script, use the following to include the functions:
```vbscript
'--------------------------
' 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")
'--------------------------
```
3. Example usage:
```vbscript
value = readFromIni("file.ini", "section", "key")
WriteToIni("file.ini", "section", "key", "newValue")
```
## Notes
- Currently does **not** support appending new sections or keys. This may be added in the future.
Enjoy! 😃
## References
- https://blog.ctglobalservices.com/scripting-development/jgs/include-other-files-in-vbscript/
- https://www.robvanderwoude.com/vbstech_files_encoding.php
- https://www.robvanderwoude.com/vbstech_files_ini.php
"# vbs-.ini-file-Handler"