Hi out there.

I want to append or add somelines to a ini file.

Example. I have a notes.ini file, at c:\notes\data\notes.ini
and i want to add or append some new lines to the existing Ini file.

Line 1 = XXXXX
Line 2 = KKKKK
Line 3 = PPPPPP

I have a another ini file or a text file, where above line have to added/append to the Notes.ini

Can anyone tell me a script to do it.
0 Comments   [ + ] Show Comments

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.

Answers

0
If you're trying to accomplish this from a Windows Installer you should be using the IniFile table. However, if you do require a script just use the file system object. The following code will append three lines to the end of the ini file:



Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\notes.ini", ForAppending)
objFile.WriteLine "XXXXX"
objFile.WriteLine "KKKKK"
objFile.WriteLine "PPPPPP"
objFile.Close

Answered 09/30/2008 by: captain_planet
Second Degree Brown Belt

Please log in to comment
0
Thnx mate, ur script works and append in the end of the file. [:D]

I was working on this script, and everytime i launch it it erase what i had in the Notes.ini file, and added the
text i wanted, so the problem was that i cant append the text in the end of a file.

If you can tell what had to be modify in my script. " just for learning and understand it" [&:]

Option Explicit
Dim objFSO, objFileCopy, objAddText
Dim strFilePath
Dim strFileText1, strFileText2, strFileText3
strFilePath = "C:\Notes\Data\Notes.ini"
strFileText1 = "XXXXXXX"
strFileText2 = "VVVVVVV"
strFileText3 = "NNNNNNN"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objAddText = objFSO.CreateTextFile(strFilePath, True)

objAddText.WriteLine (strFileText1)
objAddText.WriteLine (strFileText2)
objAddText.WriteLine (strFileText3)
objAddText.Close
Answered 09/30/2008 by: SKS
Orange Belt

Please log in to comment
0
ORIGINAL: SKS
I was working on this script, and everytime i launch it it erase what i had in the Notes.ini file, and added the
text i wanted, so the problem was that i cant append the text in the end of a file.
Your problem is that you're using the CreateTextFile method, rather than OpenTextFile. So your code needs changing to test for the file's existence and, if found, use OpenTextFile and if not, use CreateTextFile. See here http://www.devguru.com/technologies/vbscript/14048.asp for a reasonable reference to FileSystemObject (and VBScript in general).

Anyway, I think this is completely the wrong approach and fraught with potential for error. As Captain Planet said, if you're doing this in an MSI, use the INIFile table. If not, Google for 'clsINI' (or does my memory serve me that it can be found at http://www.jsware.net as part of a toolkit?) which is a rather nice INI class file which you can append to your script file. Don't be put off by the dreaded word 'class' - it's a snap to use.
Answered 09/30/2008 by: VBScab
Red Belt

Please log in to comment
0
Thnx for the info and the explanation Vbscab :-)
Answered 09/30/2008 by: SKS
Orange Belt

Please log in to comment
0
Nice script from captain_planet which works.
But if i want to make a check on a line exist ( "XXXXX" ), and if so, then quit the script, otherwise install the script.
Can you help me on that. Thnx.

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\notes.ini", ForAppending)
objFile.WriteLine "XXXXX"
objFile.WriteLine "KKKKK"
objFile.WriteLine "PPPPPP"
objFile.Close
Answered 10/03/2008 by: SKS
Orange Belt

Please log in to comment
0
Look up 'ReadLine' (or 'ReadAll'if you prefer) on DevGuru. http://www.devguru.com/technologies/vbscript/14126.asp
Answered 10/03/2008 by: VBScab
Red Belt

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