Discussion:
What is the easiest way to edit the hosts file on Windows as admin?
(too old to reply)
Mayayana
2017-07-12 12:14:04 UTC
Permalink
** Posted in VBS group from a HOSTS file
discussion in Win10 group. **

"Auric__" <***@email.address> wrote
| Mayayana wrote:
|
| > I have a VBS file I keep on my Desktop. When I
| > visit a page that I think may have new muck I
| > download the webpage, drop it on the script, which
| > then parses the page for URLs and shows me a
| > list. I can select any on the list to be added to
| > both HOSTS files, cancel, and/or add other URLs.
|
| Would you be willing to post that script over in
| microsoft.public.scripting.vbscript ?
|

http://www.jsware.net/jsware/browsertips.php5#host

The download there (hosts.zip) is a package designed
to provide a basic primer about HOSTS files for people
concerned about privacy.

There are two versions, one for IE and one for other
browsers. The "iebut" subfolder has scripts and icons.
I wrote this some time ago. I don't know which version
of IE breaks it. Probably 11, which breaks IE-specific
functions. But I don't really know. It also predates IE
tabs, assuming there's just one actual browser window
of the IE variety running.
The IE package takes advantage of the ability to
add a custom button to the IE toolbar that then links to
a script. When you click the button, the script uses
Shell.Application to get the collection of Explorer/IE
windows, finds an IE instance, gets the document
content, and parses that. So it's a one-click approach.

If you wanted to use that I guess you might need
to edit the code to step down into the browser window
collection. I don't remember exactly how it works now.
I think the actual IE browser windows are embedded
inside windows of class IEFrame or some such. And I
don't know how the ShellApp.Windows collection deals
with that. But I suppose very few people care about
HOSTS and also use IE these days, anyway.

The CollectURLs script is for use with other browsers,
or any webpage. Use File -> SaveAs to get the webpage.
Drop the HTML file onto the script. It gets parsed to find
URLs. It's not perfect and could probably be improved.
The code just looks for ".com", ".net", etc. Many pages
now are mostly obfuscated javascript and sleazy
URLs are often obfuscated, assembled by script rather
than written in the page HTML. The script won't catch those.
It can still be handy, though; a lot easier than trying to
read the source code.
After parsing the page content it pops up a window
with a list of URLs found. The list can be edited, aded to,
or even just used to add a new URL instead of editing
HOSTS by hand.
I added Acrylic HOSTS to my version. For anyone with
experience scripting that would be easy to do. Around
line 160-ish the script adds the new URLs to HOSTS.
The same code can be repeated to do the same for
Acrylic HOSTS.

A final caveat: As has been touched on in this thread,
later versions of Windows can be a pain in the neck with
file restrictions. If you don't turn off UAC you can't drop
files onto VBS because there's no way to elevate. Also,
many AV programs now monitor HOSTS and may complain
or block editing. Maybe something like Lionel's approach
of clearing restrictions via BAT file first would work. I've
never tried that.
Lionel Muller
2017-07-12 12:31:47 UTC
Permalink
For alt.comp.os.windows-10,microsoft.public.scripting.vbscript Mayayana
many AV programs now monitor HOSTS and may complain or block editing.
That admonishement reminded me that I should mention that the solution we
came up with for editing the hosts file using:
Start > Run > hosts
or
Start > Programs > hosts
Does cause "Glasswire" to pop up a temporary notification that a system
file was changed, which is actually a good thing because it ensures me that
the change took place.

The beauty of this method is that it doesn't clutter the desktop with
shortcuts, and it works in a single step from the Start menu (by multiple
ways) which is how I like an elegant clean efficient system to be.
Dave "Crash" Dummy
2017-07-12 14:55:41 UTC
Permalink
** Posted in VBS group from a HOSTS file discussion in Win10 group.
**
What is the name of the Win10 group? My search of Usenet group names for
"win10" comes up empty. I can use all the help I can get with Windows 10!
--
Crash

If the donation is not anonymous, it's not charity, it's advertising.
Sam Hill
2017-07-12 15:25:54 UTC
Permalink
Post by Dave "Crash" Dummy
** Posted in VBS group from a HOSTS file discussion in Win10 group.
**
What is the name of the Win10 group? My search of Usenet group names for
"win10" comes up empty. I can use all the help I can get with Windows 10!
Take a closer look at the header of the message you replied to (and this
one as well)- specifically the "Newsgroups" header item.
Dave "Crash" Dummy
2017-07-12 22:41:26 UTC
Permalink
Post by Sam Hill
Post by Dave "Crash" Dummy
** Posted in VBS group from a HOSTS file discussion in Win10 group.
**
What is the name of the Win10 group? My search of Usenet group names for
"win10" comes up empty. I can use all the help I can get with Windows 10!
Take a closer look at the header of the message you replied to (and this
one as well)- specifically the "Newsgroups" header item.
Ah. I should have looked there. Rookie mistake. Thanks!
--
Crash

"Celibacy is the worst form of self-abuse."
~ Peter De Vries ~
Mayayana
2017-07-12 17:01:34 UTC
Permalink
"Dave "Crash" Dummy" <***@invalid.invalid> wrote

| What is the name of the Win10 group? My search of Usenet group names for
| "win10" comes up empty. I can use all the help I can get with Windows 10!

Don't you see it in your reply?

alt.comp.os.windows-10

There's no MS group, as they abandoned their
usenet servers and switched over to the moderated
Web forums before Win10 came out.
I get this group through Eternal September. It
should be provided by most servers.
Dave "Crash" Dummy
2017-07-12 22:46:34 UTC
Permalink
This post might be inappropriate. Click to display it.
Lionel Muller
2017-07-12 17:46:16 UTC
Permalink
For alt.comp.os.windows-10,microsoft.public.scripting.vbscript Dave "Crash"
Post by Dave "Crash" Dummy
What is the name of the Win10 group? My search of Usenet group names for
"win10" comes up empty. I can use all the help I can get with Windows 10!
Just for archival purposes, here's the summary of how we enabled, on
Windows 10, editing of the hosts file as administrator in a single step.

I was unable to solve the problem with a batch file because I don't know
anything about batch file sysntax, so a sample was supplied in the original
thread and is appended below.

Here is the original summary solution message.........

SOLVED!
To give back to the newsgroup...
****************************************************************************
Below are two tested ways to admin edit the hosts file in a single click!
****************************************************************************
The goal was single click admin edits using native Windows methods only.
For expert Windows users (who wish to streamline their every action).

1. Optionally download any of the well known HOSTS file on the net:
http://winhelp2002.mvps.org/hosts.txt
http://someonewhocares.org/hosts/
https://github.com/StevenBlack/hosts
etc.

Note: Always aiming to improve efficiency, I use the same hosts file
on all my devices, whether they are Android, Linux, or Windows,
which works for all browsers and for all modern consumer
operating systems.

As such, the steps I use to combine the files above, sorted unique,
and to incorporate my manual additions, are not part of this tutorial.

2. Create an administrator "hosts.lnk" shortcut for your start menu:
Rightclick in any folder (e.g., the Desktop) > New > Shortcut
Type a location of "cmd" (or "cmd.exe") sans quotes
Click Next
Type an optional "name" (e.g., "Admin edit hosts")
Click Finish

3. Set that new shortcut to edit the hosts file as admin:
Rightclick the new Shortcut > Properties
Change the Shortcut Target from:
C:\Windows\System32\cmd.exe
Change the Shortcut Target to:
C:\Windows\System32\cmd.exe /C "notepad
C:\Windows\System32\Drivers\etc\hosts"
NOTE: The "/C" tells the command window to die when you're done.
Note: I'm normalizing to Notepad for others as I use a different editor.

4. Set optional items in the new shortcut:
Optionally change the "Start in" directory from:
C:\WINDOWS\system32
Optionally change the "Start in" directory to:
C:\WINDOWS\system32\Drivers\etc\

Optionally add a comment line of:
The "/C" closes the command window.

5. You must set the shortcut to open as Administrator:
Press the Advanced button
Check [x]Run as Administrator
Press OK

That successfully creates a shortcut you can put in your
cascaded start menu which, when clicked, will edit the
hosts file as administrator using your editor of choice.

6. Put the shortcut in a location that you confirm with the command line:
C:\Users\me\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\hosts.lnk

Note: I'm normalizing to the Classic Start Menu path as I use a
different path (but I tested this path for you and it works).

7. Now create the command "Start > Run > hosts"
Add the following "App Paths" New Key.
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
hosts.exe (it must end with exe but it can be anything else)
(Default) =
C:\Users\me\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\hosts.lnk

8. Distribute the hosts file to all your Windows, Linux, Android, and
iOS devices.

Note: I haven't jailbroken my iOS devices, so I only distribute to all
the Windows, Linux, and Android devices on my network.

9. Test:
Start > Run > hosts <enter> (this should edit the hosts as admin)
Start > Run > menu > hosts (this should edit the hosts as admin)

Voila!
That's two ways to admin edit the hosts file in a single click!
https://www.bestvpn.com/use-your-hosts-file-to-block-ads-and-malware/
============================================================================
If you're a Windows expert, you already know why you'd want this.
And you'd already know about Acrylic DNS (if you want to go that route).

If you're not a Windows expert, read these two explanations please.
http://winhelp2002.mvps.org/hosts.htm
===========================================================================
See also:
Zeezicht:
Try HOSTSMAN ==> http://www.abelhadigital.com/hostsman
It has a very userfriendly "editor" onboard + other features ...
Mayayana:
http://mayakron.altervista.org/wikibase/show.php?id=AcrylicHome
Acrylic DNS proxy allows wildcard edits to its hosts file.
===========================================================================
For whatever reason, the batch file method failed.
Here is the batch file that works for opening a command prompt as admin.
===================
@ECHO OFF

REM Open a new shell "Run As Administrator"
REM Based on script by foxidrive on alt.msdos.batch

SETLOCAL ENABLEEXTENSIONS

IF NOT "%~1"=="" goto :START

SET MyFile=%TEMP%\Admin.vbs"
Echo Set UAC = CreateObject("Shell.Application") >"%MyFile%"
Echo UAC.ShellExecute "%~f0", "%cd%", "", "runas", 1 >>"%MyFile%"
Start "" /MIN "%MyFile%"
goto :EOF

:START
Cmd /k "CD /D "%*" & Echo Administrator: & color 4F"\
===================
I wasn't able to modify that batch file to edit the hosts file as admin.
===================
What would you modify in this batch file (which opens a command window as
admin) to make it edit the hosts file instead?
===================
@ECHO OFF

REM Open a new shell "Run As Administrator"
REM Based on script by foxidrive on alt.msdos.batch

SETLOCAL ENABLEEXTENSIONS

IF NOT "%~1"=="" goto :START

SET MyFile=%TEMP%\Admin.vbs"
Echo Set UAC = CreateObject("Shell.Application") >"%MyFile%"
Echo UAC.ShellExecute "%~f0", "%cd%", "", "runas", 1 >>"%MyFile%"
Start "" /MIN "%MyFile%"
goto :EOF

:START
Cmd /k "CD /D "%*" & Echo Administrator: & color 4F"\
===================
This didn't work but I really don't know what it's doing.
===================
@ECHO OFF
SET MyFile=C:\Windows\System32\Drivers\etc\hosts
Echo Set UAC = CreateObject("Shell.Application") >"%MyFile%"
Echo UAC.ShellExecute "%~f0", "%cd%", "", "runas", 1 >>"%MyFile%"
Start "" /MIN "notepad.exe %MyFile%"
===================
Loading...