I am new Vb Scripting and looking for the help.

I am trying to write a VBscript file(.vbs) to edit .ini file.

Here is my requirement:

I have to put my system name in c:\program files\abc\xyz.ini\

I am able to get my system name? how can i proceed furthur to write in .ini file.

0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.


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.
Answered 10/05/2009 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
....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:

...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
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.
Answered 10/05/2009 by: captain_planet
Second Degree Brown Belt

Please log in to comment
Friggin awesome, it shows why this is such a great community. I'll know where to go if i need to do this :-) Thanks!
Answered 10/05/2009 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
There's a registry class in that pack which abstracts the WMI registry namespace rather nicely. I have an edited version which I use all the time (in fact, I'm writing a script today which uses it).
Answered 10/05/2009 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity