Link to home
Start Free TrialLog in
Avatar of acunaara
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
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you may use any plain text editor, including the Windows built-in one Notepad, to do that. just open the VBS file in text mode and use SEARCH & REPLACE function to get it done.

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
Avatar of acunaara
acunaara

ASKER

Thanks Bill

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

Open in new window

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