/build/static/layout/Breadcrumb_cap_w.png

how to write a .vbscript to write in .ini file

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.

Thanks,
Ramu

0 Comments   [ + ] Show comments

Answers (4)

Posted by: captain_planet 15 years ago
Black Belt
1
....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:


[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
9th Degree Black Belt
0
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.
Posted by: aogilmor 15 years ago
9th Degree Black Belt
0
Friggin awesome, it shows why this is such a great community. I'll know where to go if i need to do this :-) Thanks!
Posted by: anonymous_9363 15 years ago
Red Belt
0
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).
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ