troubleshooting Question

vbs add line if it does not exist

Avatar of bt707
bt707Flag for United States of America asked on
Visual Basic Classic
2 Comments1 Solution283 ViewsLast Modified:
I have a ini file that I need to replace a few lines in, with the code below I can replace the two lines I need and that works fine.

The problem I have is that some of the files does not contain a line of DefaultMailto, how can I check to see if the file contains the line of DefaultMailto and if not then add DefaultMailto=0. Also the file sometimes does have a line of WarnDefaultMailto= so also have to keep this line from being found when looking for DefautlMailto=.

Thanks,










Const ForReadingPRF = 1
Const ForWritingPRF = 2
Set objFSOPRF = CreateObject("Scripting.FileSystemObject")
Set objFilePRF = objFSOPRF.OpenTextFile(EiniPath, ForReadingPRF)
newPOPaccount = "POPAccount=" & MigrateAlias & "@NO_PoP_Mail"
 
strTextPRF = objFilePRF.ReadAll
objFilePRF.Close
strNewTextPRF = Replace(strTextPRF, "DefaultMailto=1", "DefaultMailto=0")
strNewTextLOS = Replace(strNewTextPRF, "POPAccount=NO_PoP_Mail", newPOPaccount)
 
Set objFilePRF = objFSOPRF.OpenTextFile(EiniPath, ForWritingPRF)
objFilePRF.WriteLine strNewTextLOS
objFilePRF.Close
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros