acunaara
asked on
How to search in a file an item and change the settings using VBS??
I want to look for an specify line and change the value from NO to YES.
For more info there is the attachment
For more info there is the attachment
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bill
It works nice!!
The line 33 was wrong but i fixed it as follows:
It works nice!!
The line 33 was wrong but i fixed it as follows:
' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
' Define string to replace
strOldText = "AUTOMATIC_TRIAL = NO"
strNewText = "AUTOMATIC_TRIAL = YES"
' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
sInfile = WScript.Arguments(0)
Else
WScript.Echo "No filename specified."
WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
sOutfile = WScript.Arguments(1)
Else
sOutfile = sInfile
End If
' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Read entire input file into a variable and close it
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
sData = oInfile.ReadAll
oInfile.Close
Set oInfile = Nothing
sData = Replace(sData, strOldText, strNewText)
' Write file with any changes made
Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
oOutfile.Write(sData)
oOutfile.Close
Set oOutfile = Nothing
' Cleanup and end
Set oFSO = Nothing
' MsgBox "Conversion done."
Wscript.Quit
Great, glad that helped. Sorry about that bug, as you imagine I repurpose code when possible, forgot to adjust that line from a prior question. Glad you sorted it out.
~bp
~bp
if you do prefer using some kind of VBS friendly editor, please check the below link for more information.
http://stackoverflow.com/questions/364283/what-is-your-favorite-vbscript-editor