FiberGhost
Instructor
I am using the following code to write to the Hosts file on a computer. Earlier code figures out what OS and then path to the Hosts file. If the file does not exist I want it to create the file and add two lines. The code is:
'If CheckFileExist is False then create the file.
If CheckFileExists = False Then
oFSO.CreateTextFile(sHostsPath,true).WriteLine("192.1.1.2 mris_sv1"
oFSO.CreateTextFile(sHostsPath,true).WriteLine("10.20.80.241 mris_rws"
'oFSO.CreateTextFile(sHostsPath,true).Close
End If
But only 192.1.1.2 mris_rws is written. If I change it to
'If CheckFileExist is False then create the file.
If CheckFileExists = False Then
oFSO.CreateTextFile(sHostsPath,ForAppending,true).WriteLine("192.1.1.2 mris_sv1"
oFSO.CreateTextFile(sHostsPath,ForAppending,true).WriteLine("10.20.80.241 mris_rws"
'oFSO.CreateTextFile(sHostsPath,true).Close
End If
It only writes the first line. I currently have the last line commented out ('oFSO.CreateTextFile(sHostsPath,true).Close) because if I don't the file is created, but is blank.
What am I doing wrong?
'If CheckFileExist is False then create the file.
If CheckFileExists = False Then
oFSO.CreateTextFile(sHostsPath,true).WriteLine("192.1.1.2 mris_sv1"
oFSO.CreateTextFile(sHostsPath,true).WriteLine("10.20.80.241 mris_rws"
'oFSO.CreateTextFile(sHostsPath,true).Close
End If
But only 192.1.1.2 mris_rws is written. If I change it to
'If CheckFileExist is False then create the file.
If CheckFileExists = False Then
oFSO.CreateTextFile(sHostsPath,ForAppending,true).WriteLine("192.1.1.2 mris_sv1"
oFSO.CreateTextFile(sHostsPath,ForAppending,true).WriteLine("10.20.80.241 mris_rws"
'oFSO.CreateTextFile(sHostsPath,true).Close
End If
It only writes the first line. I currently have the last line commented out ('oFSO.CreateTextFile(sHostsPath,true).Close) because if I don't the file is created, but is blank.
What am I doing wrong?