Feb 26, 2013

Edit Hosts File: Tips&Tricks

Hi everyone!

IT technicians, as well as web developers, often need to edit the Windows hosts file. This requires starting your favorite editor using elevated privileges (obviously only if UAC is active), browsing for the hosts file which is deep in the windows folder and enclosed in a hidden folder on top of that.

For your own machine you can create a shortcut to achieve your goal, but our experience tells us that most people don't bother with it, ending up losing precious minutes every time they must modify the hosts file.

What better tool then one that you use every day, which is already running in the notification area, to implement a solution with. If the machines you work on have the same setup, this will work on all of them.

Simply create a session with the proper settings.


Steps

1. Create a new Command Line session.
2. Enter a session name
3. Check the Run as Administrator check box.
4. Using the ellipsis button, select your editor of choice in the Run text box.
5. Paste the following after the name of the program, ensure a blank space separates the two and include the double quotes. "c:\Windows\System32\drivers\etc\hosts"

If your editor is already running, it will not elevate the privileges. You should close it
beforehand. I've implemented a AutoHotKey script that closes my editor of choice, but
being that it shuts off without saving pending changes, its not a solution for the faint
hearted. It depends on your chosen editor's reaction to the WM_QUIT message


That's it. Simple and efficient. You can use this for any tool you use regularly. Paired with shared data source it makes for a powerful library of tools for your team.

Alternative if you want to use the Parameters tab

Some people want to use the parameters tab because, upon launching, it will display a dialog where you can confirm the value of the parameters and even allows you to change them for whole new values.

Steps 1 to 4 are the same
Step 5 - Enter "{1}" after the name of the executable, keeping a space between the two values andincluding the quotes.
Step 6 - Uncheck "Use Shell Execute"
Step 7 - In the parameters tab, set parameter # 1 type to "Text"
Step 8 - Enter the following in the Default Value : c:\Windows\System32\drivers\etc\hosts


.

This is helpful if you mostly use the tool with a certain file, but occasionally need to edit another file. I'd rather have a separate entry for each file I commonly edit, but this shows how flexible Remote Desktop Manager really is.

3 comments:

  1. Editing host files tends to indicate a significant issue with the IT strategy.
    But I like the general idea!

    ReplyDelete
  2. Not always. In a DMZ environment where you do not want to publish your internal DNS zones editing the hosts file is the best answer.

    ReplyDelete