How i can edit & remove ip addresses from host file through lotusscript

to add ip address in host file i have the code but i don’t have the code to remove any entry.the code for adding is:

For Machines with Windows 95, 98, NT or 2000 click here →

Sub Click(Source As Button)

'Dim session As New NotesSession

'Dim db As NotesDatabase

Dim fileNum As Integer

Dim fileName As String

'Set db = session.CurrentDatabase

fileNum% = Freefile()



'envir = Environ("SystemRoot") 'Get the location where windows is installed

lsWindowsDir = Environ$("windir")

lsWindowsDir = Lcase$(lsWindowsDir)

If lsWindowsDir =  "c:\windows" Then

	filename = "c:\windows\hosts"

Else

	filename = "c:\winnt\system32\drivers\etc\hosts"

End If

Open filename For Append As fileNum%

’ Print two lines to the file and close it.

’ First line: two String values, with no separation between.

'Print #fileNum%,"176.0.0.41	myportal.tatasteel.co.in"

Print #fileNum%,"176.0.0.17	myportal.tatasteel.co.in"

’ Second line: NULL value, EMPTY value, Integer variable

’ value, and String value, separated on the line by tabs.

	'Print #fileNum%, nVar, eVar, fileNum%, "corrupted"

Close fileNum%

Msgbox " My Portal added to your host file.Thanks "

End Sub

AND For Windows XP machine( all black coloured new machines) →

Sub Click(Source As Button)

'Dim session As New NotesSession

'Dim db As NotesDatabase

Dim fileNum As Integer

Dim fileName As String

'Set db = session.CurrentDatabase

fileNum% = Freefile()



'envir = Environ("SystemRoot") 'Get the location where windows is installed

lsWindowsDir = Environ$("windir")

lsWindowsDir = Lcase$(lsWindowsDir)

filename = "c:\windows\system32\drivers\etc\hosts"



Open filename For Append As fileNum%

’ Print two lines to the file and close it.

’ First line: two String values, with no separation between.

’ Print #fileNum%,“176.0.0.41 myportal.tatasteel.co.in”

Print #fileNum%,"176.0.0.17	myportal.tatasteel.co.in"

’ Second line: NULL value, EMPTY value, Integer variable

’ value, and String value, separated on the line by tabs.

	'Print #fileNum%, nVar, eVar, fileNum%, "corrupted"

Close fileNum%

Msgbox " My Portal added to your host file.Thanks "

End Sub

if u can than plz help me out from this poblem

Subject: How i can edit & remove ip addresses from host file through lotusscript

You can’t remove an entry in the file – you need to get all of the existing entries into memory, remove the entry in memory, then overwrite the whole file.

Subject: RE: How i can edit & remove ip addresses from host file through lotusscript

I wouldn’t read the whole file into memory, because when it’s a big file, lets say 4GB, you would get problems.

Instead I would just read the file line by line, and output all lines to a new file which do not match the entry to be deleted,

and afterwards delete the original hosts file and rename the temporary output file as hosts.

For Windows machines I would also copy the hosts file as lmhosts.

Subject: RE: How i can edit & remove ip addresses from host file through lotusscript

On the positive side, a hosts file is never really big, as you would get into trouble with Windows if it was.But why this hassle with the hosts file? Why not simply create those entries in the company DNS server?

Subject: RE: How i can edit & remove ip addresses from host file through lotusscript

Sirs Please have a look on the following code & advise me if can do some changes in the given code so to remove/replace/delete 1 entry from host file. The code:

For Machines with Windows 95, 98, NT or 2000 click here ->To add ip code is:

Sub Click(Source As Button)

'Dim session As New NotesSession

'Dim db As NotesDatabase

Dim fileNum As Integer

Dim fileName As String

'Set db = session.CurrentDatabase

fileNum% = Freefile()



'envir = Environ("SystemRoot") 'Get the location where windows is installed

lsWindowsDir = Environ$("windir")

lsWindowsDir = Lcase$(lsWindowsDir)

If lsWindowsDir =  "c:\windows" Then

	filename = "c:\windows\hosts"

Else

	filename = "c:\winnt\system32\drivers\etc\hosts"

End If

Open filename For Append As fileNum%

’ Print two lines to the file and close it.

’ First line: two String values, with no separation between.

'Print #fileNum%,"176.0.0.41	myportal.tatasteel.co.in"

Print #fileNum%,"176.0.0.17	myportal.tatasteel.co.in"

’ Second line: NULL value, EMPTY value, Integer variable

’ value, and String value, separated on the line by tabs.

	'Print #fileNum%, nVar, eVar, fileNum%, "corrupted"

Close fileNum%

Msgbox " My Portal added to your host file.Thanks "

End Sub

AND for For Windows XP machine( all black coloured new machines) → code is:

Sub Click(Source As Button)

'Dim session As New NotesSession

'Dim db As NotesDatabase

Dim fileNum As Integer

Dim fileName As String

'Set db = session.CurrentDatabase

fileNum% = Freefile()



'envir = Environ("SystemRoot") 'Get the location where windows is installed

lsWindowsDir = Environ$("windir")

lsWindowsDir = Lcase$(lsWindowsDir)

filename = "c:\windows\system32\drivers\etc\hosts"



Open filename For Append As fileNum%

’ Print two lines to the file and close it.

’ First line: two String values, with no separation between.

’ Print #fileNum%,“176.0.0.41 myportal.tatasteel.co.in”

Print #fileNum%,"176.0.0.17	myportal.tatasteel.co.in"

’ Second line: NULL value, EMPTY value, Integer variable

’ value, and String value, separated on the line by tabs.

	'Print #fileNum%, nVar, eVar, fileNum%, "corrupted"

Close fileNum%

Msgbox " My Portal added to your host file.Thanks "

End Sub