Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Do you have a trick that edits & saves the HOSTS file in a single command?

6 views
Skip to first unread message

Arlen Holder

unread,
Dec 9, 2020, 4:48:31 PM12/9/20
to
Do you have a trick that edits & saves the HOSTS file in a single command?

1. It's easy to "edit" any file in a single command, e.g.,
Win+R > hosts

This edits the hosts file in your favorite editor if you've done two
things ahead of time by way of basic setup (which most people do).
a. You've set an App Paths key to point to the hosts file
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\hosts.exe]
hosts.exe=c:\windows\system32\drivers\etc\hosts
b. You've set extensionless files to open in your favorite editor

2. But the problem is _saving_ that hosts file, given default permissions.

You can _change_ permissions; but that sucks as a long-term solution.
You can also edit in an admin window; but that also sucks as a solution.
You can save the hosts file elsewhere & then copy it over, which sucks.
You can select "Run as Administrator" in "some" editors (like Notepad);
but that doesn't work for my editor of choice (AFAIK), which is vim.

Do you have a reliable Windows 10 trick that edits & saves in one command?

Idaho Homo Joe

unread,
Dec 9, 2020, 4:53:19 PM12/9/20
to
Do you know a trick to lick a dick?

Arlen Holder

unread,
Dec 9, 2020, 5:33:54 PM12/9/20
to
On Wed, 9 Dec 2020 21:48:30 -0000 (UTC), Arlen Holder wrote:

> a. You've set an App Paths key to point to the hosts file
> [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\hosts.exe]
> hosts.exe=c:\windows\system32\drivers\etc\hosts
> b. You've set extensionless files to open in your favorite editor

Minor update.
I realized I forgot to add reproducible commands for step "b" above
o Which I belatedly add now so that all benefit from every post.

This will allow you to edit extensionless files using the command:
o Win+R > hosts

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.]
[HKEY_CLASSES_ROOT\.\shell]
[HKEY_CLASSES_ROOT\.\shell\open]
[HKEY_CLASSES_ROOT\.\shell\open\command]
@="\"C:\\Windows\\System32\\NOTEPAD.EXE\" \"%1\""

I've substituted that last line with my favorite editor:
@="\"C:\\app\\editor\\txt\\vim\\vim82\\vim.exe\" \"%1\""

This works fine to _edit_ the hosts extionless file; but you can't save it.
o At least not directly.

But I'm working on a solution for that problem without having to resort to
running the editor all alone first, as admin, and then editing the file.

And without having to save the file elsewhere and then copying it back.

Arlen Holder

unread,
Dec 9, 2020, 5:46:50 PM12/9/20
to
This "might" be a solution for those who don't mind a special editor:
o How to Edit the Hosts File in Windows 10
<https://www.groovypost.com/howto/edit-hosts-file-windows-10/>

In the latter half of that article, they suggest a special hosts editor:
o <https://hostsfileeditor.com/>

Which also refers to:
o <https://github.com/scottlerch/HostsFileEditor>

There's a portable:
Name: HostsFileEditor-1.2.0.zip
Size: 218450 bytes (213 KiB)
CRC32: 629707E8
CRC64: 423CC0887565A00D
SHA256: 058B31CEE7CEB0C52407535F000DFA8FD01138BA294ABABF11937EECF402B81C
SHA1: 9B092CD5BDA6AE4F5F5925DE3AF146D5044869E7
BLAKE2sp: ED5CD80320BADC457F8F63C81EAE9C1426475F2226EBF46B62B74720BA8BF3DD

And an msi installer:
Name: HostsFileEditorSetup-1.2.0.msi
Size: 954368 bytes (932 KiB)
CRC32: C847FC38
CRC64: 4A62B7380E07643A
SHA256: 52DB892868E2094DE82690F2825E1CC08187B11E850463DAA33D9A829DA34753
SHA1: 8848D440802CCFAC9EBA709DE0EA7071D265B54A
BLAKE2sp: FC231521A138694DF9637D3FF013815441ECC0C507B33076C12F6F4DF464B48F

I ran the msi installer.
C:\Program Files (x86)\Hosts File Editor\
C:\app\editor\txt\hostsfileeditor\
(_)Everyone
(o)Just me

Bummer. It errored out with this fatal error:
"The installer has encountered an unexpected error installing
this package. This may indicate a problem with this package.
The error code is 2503."

Given I had just wanted to test it out, I'll give up on a "special"
hosts editor (I had just wanted to see how it handles permissions).

If you have experience with this special hosts editor, please let us know
how it handles the permission problem, which is really the main issue.













Arlen Holder

unread,
Dec 9, 2020, 5:52:44 PM12/9/20
to
On Wed, 9 Dec 2020 22:46:50 -0000 (UTC), Arlen Holder wrote:

> If you have experience with this special hosts editor, please let us know
> how it handles the permission problem, which is really the main issue.

Apparently there are plenty of specialized "hosts file editors", e.g.,
o Windows Hosts File Editor
<http://www.amazify.com/windows-hosts-file-editor/>

And, the Internet is filled with the "dumb" solutions, which are
a. Either start the editor first, as admin, or
b. Save the file elsewhere & copy it back, or
c. Change the permissions on the hosts file (which is a bad idea).

As documented in each of these related threads:
o How To Edit Hosts File Without Admin Password
<https://www.techjunkie.com/edit-hosts-file-without-admin-password/>

o How to Edit the Hosts File on Windows
<https://www.wikihow.com/Edit-the-Hosts-File-on-Windows>

o FIX: Access denied when editing hosts file in Windows 10
<https://windowsreport.com/access-denied-hosts-windows-10/>

o How to Edit Files That Require Admin Privileges
<https://www.labnol.org/software/edit-hosts-files-as-administrator/13673/>

But what I'm seeking is _not_ that sophomoric stuff above that everyone
knows; I want an elegant solution that works properly, the way it should.

Arlen Holder

unread,
Dec 9, 2020, 6:15:09 PM12/9/20
to
On Wed, 9 Dec 2020 22:52:43 -0000 (UTC), Arlen Holder wrote:

> But what I'm seeking is _not_ that sophomoric stuff above that everyone
> knows; I want an elegant solution that works properly, the way it should.

SOLVED!
In summary, typing "hosts" at the Run box executes the "hosts.exe" app key
value which runs the "hostsedit" shortcut which runs the "Task hosts edit"
task as administrator (without bringing up any UAC access control prompts).

OK. I came up with a solution that fits the problem set
a. Use any text editor you like (my favorite, of course, is vim)
b. No need for changing file permissions (which is a bad idea, overall)
c. No need to save the hosts file elsewhere, just to copy it back
d. No need for a specialized hosts file editor per se (vim is fine)
etc.

The solution turned out to be the same solution I've used in the past
o Tutorial to add a freeware killswitch which blocks software installations from phoning home during or after the initial install process
<https://groups.google.com/g/alt.msdos.batch/c/Tk8xlPZ-tKk>

o Expert help requested for removing UAC user account control task scheduler syntax
<https://groups.google.com/g/alt.comp.microsoft.windows/c/7wpgdNscZNA>

I'll write up a step by step tutorial later, so that all can benefit
o But for now, here is a summary of the steps I took that worked

This is the goal (which I have been able to accomplish):
o Win+R > hosts
(this edits the hosts file as a user & saves it back,
without changing permissions or copying the file anywhere)

The "trick" was to use the fact that "tasks" can be run as "admin".
o And to couple that with the fact the AppPaths creates a command

Quickly stated, the first thing I did was create an AppPaths key:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
hosts.exe=C:\data\sys\link\hostsedit.lnk

The second thing I did was create that specified shortcut:
FILE=C:\data\sys\link\hostsedit.lnk
TARGET=C:\Windows\System32\schtasks.exe /run /TN "Task hosts edit"
COMMENT=taskschd.msc > Task hosts edit

The third thing I did was create that scheduled task (run as admin):
Win+R > taskschd.msc
[Task Scheduler Library] > Create Task >
Name=Task hosts edit
Description=Edit & save hosts by typing "hosts" w/o needing to be admin.
(o)Run only when user is logged on
[x]Run with highest privileges
[Action] Start a program
[Program/Script] %comspec%
[Add arguments] /c start "" C:\app\editor\txt\vim\vim82\vim.exe c:\windows\system32\drivers\etc\hosts
[Start in] <blank>

In summary, typing "hosts" at the Run box executes the "hosts.exe" app key
value which runs the "hostsedit" shortcut which runs the "Task hosts edit"
task as administrator (without bringing up any UAC access control prompts).

Note: I use a "write bang" syntax to write (e.g., <esc><:><w!> in vim).

If you have a _better_ way to edit the hosts file, please advise
o That way everyone benefits from every thread on this Usenet newsgroup.
--
Posted out of the goodness of my heart to help others do what I just did.

Arlen Holder

unread,
Dec 10, 2020, 1:30:47 AM12/10/20
to
On Wed, 9 Dec 2020 23:15:08 -0000 (UTC), Arlen Holder wrote:

> SOLVED!
> In summary, typing "hosts" at the Run box executes the "hosts.exe" app key
> value which runs the "hostsedit" shortcut which runs the "Task hosts edit"
> task as administrator (without bringing up any UAC access control prompts).

I haven't seen any of these methods documented on the net, but in my files
I found I had previously solved this problem in 2017 by a different method.

As always, so that all benefit from everything we learn on Windows,
here's a paste from my old logs, which I had forgotten I had documented.

It's "similar" but a _different_ method of editing the hosts file where
this method only uses two of the three components of the previously
documented method (i.e., this method omits the task scheduler trick).

The goal is single-step hosts file editing using native Windows methods:
o Win+R > hosts

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: 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 cascade menu:
Rightclick in any folder "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 any desired 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:
Rightclick on the shortcut you just created to edit its properties.
Select "Properties" from the context menu that results.
Press the Advanced button
Check [x]Run as Administrator
Press OK

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

Taskbar > menu > network > hosts

6. Put the shortcut in a location that you confirm with the command line:
C:\Users\%username%\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 "Win+R > 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, which is easy to do if you have a decent Wi-Fi LAN.

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:
Win+R > Run > hosts <enter> (this should edit the hosts as admin)
Start > Programs > hosts (this should edit the hosts as admin)

Note: This was posted in 2017, which I cleaned up slightly for 2020.
I tested this method in 2017, but didn't test in 2020 so I'm not sure
if the UAC access prompt nag screen comes up or not using this method.
--
Posted out of the goodness of my heart so that others can benefit.

Arlen Holder

unread,
Dec 13, 2020, 4:57:06 PM12/13/20
to
On 13 Dec 2020 18:34:11 GMT, Frank Slootweg wrote:

> AFAIC, this "make an accurate profile of you" business is mostly
> (fully?) urban legend.

Which is (one reason) why I espouse the "multi-browser philosophy" (I need
a better name) of one browser, one task (e.g., one browser for YouTube).

o Discussion of easy-to-implement privacy-related browser philosophies
<https://groups.google.com/forum/#!topic/alt.comp.freeware/H4694--5znY>

There are about a score of free browsers to implement that strategy:
o Clickable list of full offline installers to all free browsers
<https://groups.google.com/forum/#!topic/alt.comp.freeware/krNaXA-YEbw>

> The only ads I see, are ads which are directly related to searches
> which I did, i.e. no 'profile' of any kind. "they" can't even tell the
> difference between 'me' (read: my searches) and 'her' (read; the
> searches which SWMBO did), we get ads for eachothers searches, 'because'
> we share the same (WAN) IP.

Which is (one reason) why Marek Novotny, bless his heart, wrote the scripts
which randomly switch my VPN service between six thousand servers.

> So "they" *apparently* don't know *anything* about me, because they
> can't even get my gender right and can't even distinguish my (search)
> interests from SWMBO's.

Which is (one reason) why Herbert Kleebauer wrote the scripts which
randomly switch between the most populous time zones in the world.

o Keeping your time zone random with a consistent timezone display
<https://groups.google.com/g/alt.msdos.batch/c/0EE2VwfKwYc/m/qWDgwB8-AwAJ>
--
See also:
o What method do you prefer for scheduling a batch file to run silently
<https://groups.google.com/g/alt.msdos.batch/c/JZMlGo_2__E/m/tWtTXTijAwAJ>

Arlen Holder

unread,
Dec 14, 2020, 4:27:39 PM12/14/20
to
On 14 Dec 2020 19:59:24 GMT, Frank Slootweg wrote:

> Yes, that's a good example. It doesn't apply to me/us (me+SWMBO) -
> because it needs at least one cooperating app on the phone and we don't
> have such apps -, but that doesn't matter, because the evil empires
> couldn't care less if there are a few loons like me, as long as the
> masses do have at least one such app.

Hi Frank,

As you know, I always doublecheck facts (it's why my facts are never wrong)
o Where I would just ask you to doublecheck your setup

I read Mayayana's reference, which, as you noted, said that some of the
bluetooth surveillance is via the weather app, the Target app, the WalMart
app, etc., which would require you to be using one of those cited apps.
o In Stores, Secret Surveillance Tracks Your Every Move
<https://www.nytimes.com/interactive/2019/06/14/opinion/bluetooth-wireless-tracking-privacy.html>

However, I (almost) always click and read all the secondary links (just as
I do when I read peer-reviewed papers, or even when I read Wikipedia).

Mayayana's initial cite referenced this article which describes a gotcha:
o Google can still use Bluetooth to track your Android phone when Bluetooth is turned off
<https://qz.com/1169760/phone-data/>

The gotcha is that you don't need to be using _any_ apps to _still_ be
tracked by bluetooth beacons (if I read the article correctly that is).

Which claims you don't need ANY bluetooth apps & you'll _still_ be tracked.
o <https://cms.qz.com/wp-content/uploads/2018/01/bluetooth_scanning_grid_andriod_004.png>

See also this (much older) article on being tracked & not knowing it:
o Your Apps Know Where You Were Last Night, and Theye Not Keeping It Secret
<https://www.nytimes.com/interactive/2018/12/10/business/location-data-privacy-apps.html>
--
See also this recent thread I posted just this morning:
o Israeli Surveillance Companies Are Siphoning Masses Of Location Data From Smartphone Apps
<https://groups.google.com/g/comp.mobile.android/c/g5QBU8F2Qh4>

Arlen Holder

unread,
Dec 14, 2020, 4:27:57 PM12/14/20
to
On Mon, 14 Dec 2020 14:06:29 -0500, Mayayana wrote:

> Here's another one, about watching you in stores
> via bluetooth communicating with your phone:
>
> https://www.nytimes.com/interactive/2019/06/14/opinion/bluetooth-wireless-tracking-privacy.html

That's a damn good article Mayayana just cited:
o <https://www.nytimes.com/interactive/2019/06/14/opinion/bluetooth-wireless-tracking-privacy.html>

The graphic alone in that article Mayayana suggested is _fantastic_!
o <https://int.nyt.com/data/videotape/finished/2019/06/1560523217/desktop_crop1-1254w.mp4>

General question to the group...

If I keep my bluetooth off on my phone, as I am wont to do
o Doesn't that protect me from bluetooth wireless tracking?

Maybe not, as this is what the article Mayayana cited claims:
"And last year, investigators at Quartz found that
Google Android can track you using Bluetooth beacons
even when you turn Bluetooth off in your phone."
<https://cms.qz.com/wp-content/uploads/2018/01/bluetooth_scanning_grid_andriod_004.png>

o Google can still use Bluetooth to track your Android phone when Bluetooth is turned off
<https://qz.com/1169760/phone-data/>
"When Location History is activated, Android phones try to send a
plethora of nuanced information back to Google...
including nearby Bluetooth devices."

"A spokesperson for Google confirmed that turning off Location History
would stop a phone's reporting of nearby Bluetooth beacons"

Hence I suggest people add the necessary shortcuts to your Android
homescreen shortcuts folder, so these Android settings bubble up high.
o Quick tutorial for creating Android homescreen shortcuts using custom icons
<https://groups.google.com/g/comp.mobile.android/c/if4FD2NFEnk>

Note: You can make a shortcut to most settings inside Android & the apps.
o Is there a way to make an Android homescreen shortcut to any given settings page such as the battery status?
<https://groups.google.com/g/comp.mobile.android/c/_1oTdgCIpkc>
--
Posted out of the goodness of my heart, so others can improve their skills.
0 new messages