Hey,

Anyone know how to write a simple little script to modify the HOST file?

Thanks

Re: VBScript to Modify HOST file by Ray

Ray
Wed Apr 06 23:25:22 CDT 2005

''not sure how you want to pass your arguments
''For illustration purposes, I'll use an array
Dim aHosts(3,1)
aHosts(0,0) = "host1"
aHosts(0,1) = "192.168.1.15"

aHosts(1,0) = "host2"
aHosts(1,1) = "192.168.1.54"

aHosts(2,0) = "host3"
aHosts(2,1) = "192.168.1.29"

aHosts(3,0) = "host4"
aHosts(3,1) = "192.168.2.39"

Dim sHostsPath
sHostsPath = GetHostsPath()
msgbox sHostsPath


Dim oFSO, oFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(sHostsPath,8) ''for appending
For i = 0 To UBound(aHosts,1)
oFile.WriteLine aHosts(i,0) & " " & aHosts(i,1)
Next
oFile.Close : Set oFile = Nothing
Set oFSO = Nothing




Function GetHostsPath()
Dim oShell
Set oShell = CreateObject("WScript.Shell")
GetHostsPath =
oShell.ExpandEnvironmentStrings(oShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath"))
& "\hosts"
Set oShell = Nothing
End Function

Ray at home



"newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
news:%23d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
> Hey,
>
> Anyone know how to write a simple little script to modify the HOST
> file?
>
> Thanks
>



Re: VBScript to Modify HOST file by Rafael

Rafael
Wed Apr 06 23:40:22 CDT 2005

what exactly do you have in mind?
if it is a matter of adding entries, it is quite simple


Dim fsoObject, open_File, target_File
Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")

' ### set the file name to include the variable from the process above
target_File = "C:\WINDOWS\system32\drivers\etc\Hosts"

If (fsoObject.FileExists(target_File)) Then
Set open_File = fsoObject.OpenTextFile(target_File, 8)
Else
Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
End If


open_File.WriteLine "ip pcname"


msgbox "done"
open_File.Close()

hope this helps,
RT

"newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
news:%23d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
> Hey,
>
> Anyone know how to write a simple little script to modify the HOST
> file?
>
> Thanks
>



Re: VBScript to Modify HOST file by mayayana

mayayana
Thu Apr 07 07:30:05 CDT 2005

I've got an ad-blocking and snoop-blocking
"kit" that I put together, for adding URLs like
doubleclick to your HOSTS files (with a 127.0.0.1
address resolution) automatically:

http://www.jsware.net/jsware/cook.html#hosts

The download includes a script that will extract
URLs from the current webpage, display them in
a window, and let you select which URLs you want
added to your HOSTS file to block contact with that
domain. So you can just add new addresses whenever
you see a 3rd-party ad appear in a page (...and they're
almost all 3rd-party ads these days).
In IE it can install a button on the toolbar
to process the current page. In other browsers you
have to save the webpage and drop it onto the
script.
I don't know if that's what you want, but the script
provides a sample of writing to HOSTS.

--
_____________________________

mayayXXana1a@mindYYspring.com
For return email remove XX and YY.
_____________________________
newsgroups.comcast.net <chiller-fx@comcast.net> wrote in message
news:#d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
> Hey,
>
> Anyone know how to write a simple little script to modify the HOST
file?
>
> Thanks
>
>



Re: VBScript to Modify HOST file by newsgroups

newsgroups
Thu Apr 07 16:04:21 CDT 2005

Thank You, I put something together from your code to modify the file. Now
all I need is a way to check if the user logged in has Admin privileges?

Also if the user doesn't have admin privileges is there a way to run the
vbscript on a non-admin account as an admin assuming the username and
password of the admin account is known?

"Rafael T" <okinawapro@hotmail.com> wrote in message
news:OKc7cuyOFHA.3292@TK2MSFTNGP12.phx.gbl...
> what exactly do you have in mind?
> if it is a matter of adding entries, it is quite simple
>
>
> Dim fsoObject, open_File, target_File
> Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
>
> ' ### set the file name to include the variable from the process above
> target_File = "C:\WINDOWS\system32\drivers\etc\Hosts"
>
> If (fsoObject.FileExists(target_File)) Then
> Set open_File = fsoObject.OpenTextFile(target_File, 8)
> Else
> Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
> End If
>
>
> open_File.WriteLine "ip pcname"
>
>
> msgbox "done"
> open_File.Close()
>
> hope this helps,
> RT
>
> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
> news:%23d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
>> Hey,
>>
>> Anyone know how to write a simple little script to modify the HOST
>> file?
>>
>> Thanks
>>
>
>



Re: VBScript to Modify HOST file by Rafael

Rafael
Fri Apr 08 00:19:52 CDT 2005

the problem is that if you place the username and password on the vbscript
itself, it will be visible to the user who runs the script (not safe)

You can try "Run as..." to run the script from the user account. you will
have to type in the administrator account and password.

right click on the script and from the menu click on run as... then the
system will show you a log on screen. Only that script will run under the
new user security.

hope this helps,
Rafael



"newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
news:O1YlGS7OFHA.3788@tk2msftngp13.phx.gbl...
> Thank You, I put something together from your code to modify the file.
> Now all I need is a way to check if the user logged in has Admin
> privileges?
>
> Also if the user doesn't have admin privileges is there a way to run the
> vbscript on a non-admin account as an admin assuming the username and
> password of the admin account is known?
>
> "Rafael T" <okinawapro@hotmail.com> wrote in message
> news:OKc7cuyOFHA.3292@TK2MSFTNGP12.phx.gbl...
>> what exactly do you have in mind?
>> if it is a matter of adding entries, it is quite simple
>>
>>
>> Dim fsoObject, open_File, target_File
>> Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
>>
>> ' ### set the file name to include the variable from the process above
>> target_File = "C:\WINDOWS\system32\drivers\etc\Hosts"
>>
>> If (fsoObject.FileExists(target_File)) Then
>> Set open_File = fsoObject.OpenTextFile(target_File, 8)
>> Else
>> Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
>> End If
>>
>>
>> open_File.WriteLine "ip pcname"
>>
>>
>> msgbox "done"
>> open_File.Close()
>>
>> hope this helps,
>> RT
>>
>> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
>> news:%23d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
>>> Hey,
>>>
>>> Anyone know how to write a simple little script to modify the HOST
>>> file?
>>>
>>> Thanks
>>>
>>
>>
>
>



Re: VBScript to Modify HOST file by newsgroups

newsgroups
Fri Apr 08 14:45:26 CDT 2005

The way I'm running the vbscript is it's stored on a flash drive which only
admin people have, i figured there might be an easier way of doing this
other then logging the user off and logging in as an admin. So storing the
username/password in the file won't really be an issue.

The "Run as.." option for some reason doesn't show up, that was going to be
the way of doing it. It shows up when installing applications to the
computer, but not with a vbs file.


"Rafael T" <okinawapro@hotmail.com> wrote in message
news:O0iSKWAPFHA.3356@TK2MSFTNGP12.phx.gbl...
> the problem is that if you place the username and password on the vbscript
> itself, it will be visible to the user who runs the script (not safe)
>
> You can try "Run as..." to run the script from the user account. you will
> have to type in the administrator account and password.
>
> right click on the script and from the menu click on run as... then the
> system will show you a log on screen. Only that script will run under the
> new user security.
>
> hope this helps,
> Rafael
>
>
>
> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
> news:O1YlGS7OFHA.3788@tk2msftngp13.phx.gbl...
>> Thank You, I put something together from your code to modify the file.
>> Now all I need is a way to check if the user logged in has Admin
>> privileges?
>>
>> Also if the user doesn't have admin privileges is there a way to run the
>> vbscript on a non-admin account as an admin assuming the username and
>> password of the admin account is known?
>>
>> "Rafael T" <okinawapro@hotmail.com> wrote in message
>> news:OKc7cuyOFHA.3292@TK2MSFTNGP12.phx.gbl...
>>> what exactly do you have in mind?
>>> if it is a matter of adding entries, it is quite simple
>>>
>>>
>>> Dim fsoObject, open_File, target_File
>>> Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
>>>
>>> ' ### set the file name to include the variable from the process above
>>> target_File = "C:\WINDOWS\system32\drivers\etc\Hosts"
>>>
>>> If (fsoObject.FileExists(target_File)) Then
>>> Set open_File = fsoObject.OpenTextFile(target_File, 8)
>>> Else
>>> Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
>>> End If
>>>
>>>
>>> open_File.WriteLine "ip pcname"
>>>
>>>
>>> msgbox "done"
>>> open_File.Close()
>>>
>>> hope this helps,
>>> RT
>>>
>>> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
>>> news:%23d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
>>>> Hey,
>>>>
>>>> Anyone know how to write a simple little script to modify the HOST
>>>> file?
>>>>
>>>> Thanks
>>>>
>>>
>>>
>>
>>
>
>



Re: VBScript to Modify HOST file by Rafael

Rafael
Fri Apr 08 18:35:34 CDT 2005

what if an admin loses the flash drive? You don't want people to be able to
read the admin password.

anyway you can do:
- Call the vbscript from a one line batch file using:
runas /user:computer\administrator "cscript \"vbscriptName.vbs\" "

When run, it will ask for the administrator password.

- The other way around is to do something like this an include it on the
vscript itself. You can read it in:
http://www.tek-tips.com/faqs.cfm?fid=2760

- I thought there was a way to actually have it in vbscript, but I guess
that's for networking.

hope this helps,
RT



"newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
news:%23mG1%23KHPFHA.2704@TK2MSFTNGP15.phx.gbl...
> The way I'm running the vbscript is it's stored on a flash drive which
> only admin people have, i figured there might be an easier way of doing
> this other then logging the user off and logging in as an admin. So
> storing the username/password in the file won't really be an issue.
>
> The "Run as.." option for some reason doesn't show up, that was going to
> be the way of doing it. It shows up when installing applications to the
> computer, but not with a vbs file.
>
>
> "Rafael T" <okinawapro@hotmail.com> wrote in message
> news:O0iSKWAPFHA.3356@TK2MSFTNGP12.phx.gbl...
>> the problem is that if you place the username and password on the
>> vbscript itself, it will be visible to the user who runs the script (not
>> safe)
>>
>> You can try "Run as..." to run the script from the user account. you
>> will have to type in the administrator account and password.
>>
>> right click on the script and from the menu click on run as... then the
>> system will show you a log on screen. Only that script will run under
>> the new user security.
>>
>> hope this helps,
>> Rafael
>>
>>
>>
>> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
>> news:O1YlGS7OFHA.3788@tk2msftngp13.phx.gbl...
>>> Thank You, I put something together from your code to modify the file.
>>> Now all I need is a way to check if the user logged in has Admin
>>> privileges?
>>>
>>> Also if the user doesn't have admin privileges is there a way to run the
>>> vbscript on a non-admin account as an admin assuming the username and
>>> password of the admin account is known?
>>>
>>> "Rafael T" <okinawapro@hotmail.com> wrote in message
>>> news:OKc7cuyOFHA.3292@TK2MSFTNGP12.phx.gbl...
>>>> what exactly do you have in mind?
>>>> if it is a matter of adding entries, it is quite simple
>>>>
>>>>
>>>> Dim fsoObject, open_File, target_File
>>>> Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
>>>>
>>>> ' ### set the file name to include the variable from the process above
>>>> target_File = "C:\WINDOWS\system32\drivers\etc\Hosts"
>>>>
>>>> If (fsoObject.FileExists(target_File)) Then
>>>> Set open_File = fsoObject.OpenTextFile(target_File, 8)
>>>> Else
>>>> Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
>>>> End If
>>>>
>>>>
>>>> open_File.WriteLine "ip pcname"
>>>>
>>>>
>>>> msgbox "done"
>>>> open_File.Close()
>>>>
>>>> hope this helps,
>>>> RT
>>>>
>>>> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
>>>> news:%23d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
>>>>> Hey,
>>>>>
>>>>> Anyone know how to write a simple little script to modify the HOST
>>>>> file?
>>>>>
>>>>> Thanks
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Re: VBScript to Modify HOST file by newsgroups

newsgroups
Sun Apr 10 09:06:28 CDT 2005


batch file works, thank you very much.Does everything I need.


"Rafael T" <okinawapro@hotmail.com> wrote in message
news:eacFcNJPFHA.1884@TK2MSFTNGP15.phx.gbl...
> what if an admin loses the flash drive? You don't want people to be able
> to read the admin password.
>
> anyway you can do:
> - Call the vbscript from a one line batch file using:
> runas /user:computer\administrator "cscript \"vbscriptName.vbs\" "
>
> When run, it will ask for the administrator password.
>
> - The other way around is to do something like this an include it on the
> vscript itself. You can read it in:
> http://www.tek-tips.com/faqs.cfm?fid=2760
>
> - I thought there was a way to actually have it in vbscript, but I guess
> that's for networking.
>
> hope this helps,
> RT
>
>
>
> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
> news:%23mG1%23KHPFHA.2704@TK2MSFTNGP15.phx.gbl...
>> The way I'm running the vbscript is it's stored on a flash drive which
>> only admin people have, i figured there might be an easier way of doing
>> this other then logging the user off and logging in as an admin. So
>> storing the username/password in the file won't really be an issue.
>>
>> The "Run as.." option for some reason doesn't show up, that was going to
>> be the way of doing it. It shows up when installing applications to the
>> computer, but not with a vbs file.
>>
>>
>> "Rafael T" <okinawapro@hotmail.com> wrote in message
>> news:O0iSKWAPFHA.3356@TK2MSFTNGP12.phx.gbl...
>>> the problem is that if you place the username and password on the
>>> vbscript itself, it will be visible to the user who runs the script (not
>>> safe)
>>>
>>> You can try "Run as..." to run the script from the user account. you
>>> will have to type in the administrator account and password.
>>>
>>> right click on the script and from the menu click on run as... then the
>>> system will show you a log on screen. Only that script will run under
>>> the new user security.
>>>
>>> hope this helps,
>>> Rafael
>>>
>>>
>>>
>>> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
>>> news:O1YlGS7OFHA.3788@tk2msftngp13.phx.gbl...
>>>> Thank You, I put something together from your code to modify the file.
>>>> Now all I need is a way to check if the user logged in has Admin
>>>> privileges?
>>>>
>>>> Also if the user doesn't have admin privileges is there a way to run
>>>> the vbscript on a non-admin account as an admin assuming the username
>>>> and password of the admin account is known?
>>>>
>>>> "Rafael T" <okinawapro@hotmail.com> wrote in message
>>>> news:OKc7cuyOFHA.3292@TK2MSFTNGP12.phx.gbl...
>>>>> what exactly do you have in mind?
>>>>> if it is a matter of adding entries, it is quite simple
>>>>>
>>>>>
>>>>> Dim fsoObject, open_File, target_File
>>>>> Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
>>>>>
>>>>> ' ### set the file name to include the variable from the process above
>>>>> target_File = "C:\WINDOWS\system32\drivers\etc\Hosts"
>>>>>
>>>>> If (fsoObject.FileExists(target_File)) Then
>>>>> Set open_File = fsoObject.OpenTextFile(target_File, 8)
>>>>> Else
>>>>> Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
>>>>> End If
>>>>>
>>>>>
>>>>> open_File.WriteLine "ip pcname"
>>>>>
>>>>>
>>>>> msgbox "done"
>>>>> open_File.Close()
>>>>>
>>>>> hope this helps,
>>>>> RT
>>>>>
>>>>> "newsgroups.comcast.net" <chiller-fx@comcast.net> wrote in message
>>>>> news:%23d8mZKyOFHA.2680@TK2MSFTNGP09.phx.gbl...
>>>>>> Hey,
>>>>>>
>>>>>> Anyone know how to write a simple little script to modify the HOST
>>>>>> file?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>