Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Edit INI file using VBS

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,65325
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Edit INI file using VBS
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Edit INI file using VBS - 10/20/2008 6:47:22 AM   
  iamchappy

 

Posts: 2
Score: 0
Joined: 10/20/2008
Status: offline
Hey everyone,

So I have this .ini file located at C:\GSI\Application\teleset.ini

This is what the teleset.ini file looks like:

[CTI]
teleset=

I would like to have a VBS script that will have an input box where I can enter a number and then have an OK button that will save the .ini file. So lets say I input 007 in the inputbox.  I would like the ini file then to look like this:

[CTI]
teleset=007

Is this even possible?  Any ideas would be great.  Thanks. 





 
 
Post #: 1
 
 RE: Edit INI file using VBS - 10/20/2008 7:00:48 AM   
  ebgreen


Posts: 5251
Score: 31
Joined: 7/12/2005
Status: offline
This is certainly possible. You would ask the user for input. Then you have some options. One way is to just delete the existing file and write a string out to a new file (with the same name) that has the correct user supplied string. Here are some search terms to get you started:

FileSystemObject
.ReadAll
.ReadLine
InputBox
.WriteLine
.Write

Here is some pseudo-code:

strNumber = Inputbox("Enter the number")
strOut = "[CTI]" & vbCrLf & "teleset=" & strNumber
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.DeleteFile("C:\Path\To\File\File.Name")
oFSO.CreateTextFile("C:\Path\To\File\File.Name").Write(strOut)

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to iamchappy)
 
 
Post #: 2
 
 RE: Edit INI file using VBS - 10/20/2008 7:18:37 AM   
  iamchappy

 

Posts: 2
Score: 0
Joined: 10/20/2008
Status: offline
Thanks ebgreen it worked!

OK.  Now to phase two of my little project here:

Now, I have another .ini file called cticonfig.ini which is located at C:\nextel\cti\config\cticonfig.ini

That ini file looks like this:

[Nextel Cti Config]

PERIPHERALID=5143
SIDEAHOST=server1a
SIDEBHOST=server1b
SIDEAPORT=42045
SIDEBPORT=42046
HEARTBEATINTERVAL=1000
AGENTEXTENSION=

I would pretty much like to do what I did before but this time, add a number for AGENTEXTENSION= with an input box

I could do that with what you showed me but is there any way where you could have two INPUT boxes that would add the numbers to both ini files?  Even if they are two different numbers?  So let me give you an example.

The first input box would be for the first ini file (teleset.ini): "Enter Teleset ID Number here:"   And I would input 007.
The second input box would be for the second ini file (cticonfig.ini): "Enter Extension Number here:" And I would input 8630074

Could that possibly work? 

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Edit INI file using VBS - 10/20/2008 7:23:03 AM   
  ebgreen


Posts: 5251
Score: 31
Joined: 7/12/2005
Status: offline
Yes it would work. You now know how to get user input and how to write a string to a file, so you should be able to come up with this on your own. I will point out however that I did the last task the way that I did because the contents of the file were small. This task is a little different in that if I were doing I would read the contents of the file into a variable then manipulate the variable to create the new text. Using the search terms that I already provided, see what you can come up with.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to iamchappy)
 
 
Post #: 4
 
 RE: Edit INI file using VBS - 10/20/2008 7:59:51 AM   
  Rischip


Posts: 510
Score: 2
Joined: 3/26/2007
Status: offline
I love to see people learn, but I hate to see people reinvent the wheel.....

Canned vbscript INI file editing and reading ---> http://www.fpschultze.de/smartfaq+faq.faqid+51.htm

_____________________________

Rischip
Author of - The Grim Linker

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Edit INI file using VBS - 10/20/2008 8:44:30 AM   
  ebgreen


Posts: 5251
Score: 31
Joined: 7/12/2005
Status: offline
That works too.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Rischip)
 
 
Post #: 6
 
 RE: Edit INI file using VBS - 10/21/2008 8:10:51 AM   
  Rischip


Posts: 510
Score: 2
Joined: 3/26/2007
Status: offline
There is a small issue with it. They way it is coded it doesn't open unicode files. It needs to be modified to open as a text stream.

_____________________________

Rischip
Author of - The Grim Linker

(in reply to ebgreen)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Edit INI file using VBS Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts