how to write a .vbscript to write in .ini file
0 Comments
[ + ] Show comments
Answers (4)
Please log in to answer
Posted by:
captain_planet
15 years ago
....to be honest, a 'proper' ini file will contain sections (in squared brackets) and parameters (name=whatever) so it's not quite as simple as you think. So.....
VBScab recommended a VBScript class with lots of ini file functions in it. Whilst at first I thought "Come off it VBScab - that's overkill....not to mention overwhelming...." I have actually warmed to his recommendation because it IS simple to use and is a ready made, robust script. So, follow these instructions:
- Find out the name of your section/parameter which corresponds to the machine name entry you want to update
- go here, and download the zip file (claspak.zip): http://www.jsware.net/jsware/scripts.php5#classpk
- extract the zip, navigate to the INI folder and open the vbs file called 'ClsINI.vbs'
- Delete all the examples (but NOT the disclaimer) above the line that says 'Class ClsINI'
- Assuming your ini file looks like this:
Then run it. Once you can see it works, you may want to splat the 'MsgBox' lines.
VBScab recommended a VBScript class with lots of ini file functions in it. Whilst at first I thought "Come off it VBScab - that's overkill....not to mention overwhelming...." I have actually warmed to his recommendation because it IS simple to use and is a ready made, robust script. So, follow these instructions:
- Find out the name of your section/parameter which corresponds to the machine name entry you want to update
- go here, and download the zip file (claspak.zip): http://www.jsware.net/jsware/scripts.php5#classpk
- extract the zip, navigate to the INI folder and open the vbs file called 'ClsINI.vbs'
- Delete all the examples (but NOT the disclaimer) above the line that says 'Class ClsINI'
- Assuming your ini file looks like this:
[mysection]
machinename=whatever
...and your ini file is C:\test.ini (which of course it wont be), you need to paste code like this:
Dim writeval
Set CI = New ClsINI
sPath = "C:\test.ini"
If CI.OpenINIFile(sPath) = False Then
'file not found
MsgBox("Ini file not found")
Set CI = Nothing
WScript.Quit
End If
'-----edit/write a value: (edits value if exists, or writes if doesnt exist)
writeval = CI.WriteINIValue("mysection", "machinename", "newmachinename")
MsgBox "Result of overwriting value to mysection:" & VbCrLf & "machinename=newmachinename" & VbCrLf & "Error code: " & writeval
Then run it. Once you can see it works, you may want to splat the 'MsgBox' lines.
Posted by:
aogilmor
15 years ago
i don't see any vbscript function that'll write an INI, look around on the net some people have created classes and done all kinds of fancy stuff with it. maybe be a Regex expression?....
Or use another tool (can wise script do that? dunno, i used it to read not sure about write).
sorry can't help more now.
Or use another tool (can wise script do that? dunno, i used it to read not sure about write).
sorry can't help more now.
Posted by:
aogilmor
15 years ago
Posted by:
anonymous_9363
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.