I want to append a line to C:\Windows\System32\drivers\etc\hosts using VBScript. I tried to read this file first using this code:
Set filestreamIN = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Windows\System32\drivers\etc\hosts",2,true)
file = Split(filestreamIN.ReadAll(), vbCrLf)
for i = LBound(file) to UBound(file)
msgbox file(i)
Next
filestreamIN.Close()
Set filestreamIN = Nothing
But I got an error in the second line: Bad file mode. I ran it using this command:
cscript "D:\Project\AXA\AXADEPROJ-867\add host.vbs"
with cmd being run as an administrator. Any help would be great.