mardi 4 avril 2017

edit ini file via vbscript using if

i would like to make vbscript to edit .ini file and then, run an executible file

the below script is working fine to only edit particular line of .ini file but, i want more

  1. check if "usbpermit=5" exists, quit the script

  2. if "usbpermit=" is not 5, change it to 9 and then run .exe file(test.exe)

could you please help me out on this...? :)

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ProgramData\test.ini", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "usbpermit=5", "usbpermit=9")

Set objFile = objFSO.OpenTextFile("C:\ProgramData\test.ini", ForWriting)
objFile.WriteLine strNewText
objFile.Close 

thanks

Aucun commentaire:

Enregistrer un commentaire