Hi, all! I have a script to replace text from an INS file, but I need it to not display an error AND end the wscript.exe process if it errors out, like when the path is not found on certain operating systems. The script will be tied to a GPO to run at logon.
Here is the script:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Windows\System32\GroupPolicy\User\MICROSOFT\IEAK\install.ins", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine, "FavoritesDelete") = 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("C:\Windows\System32\GroupPolicy\User\MICROSOFT\IEAK\install.ins", ForWriting)
objFile.Write strNewContents
objFile.Close
The way that it is, it works, but, again, errors out on some operating systems. I tried On Error Resume Next, which hides the error message, but then pegs the wscript.exe process at 99%. And the error message returns if I use the following code:
If Err <> 0 Then
Wscript.Quit
End If
Any help is appreciated. Thanks!
Brandon