none
deploying a change in hosts file RRS feed

  • Question

  • Hi

    I have a script that adds new entries in the hosts file. I want to deploy it in several machines, with no admin rights and with O.S. Windows 8.1

    The problem is that UAC is needed and always prompt for an admin user. I would like a solution, scripting or whatever that can deploy this without admin intervention.

    Thanks in advance.


    Wednesday, October 22, 2014 8:36 AM

Answers

  • You can't.  You need admin rights to amend the hosts files (for security reasons).

    You might be able to update this via Group Policy, but why do you need to update the hosts file.  This is old technology, and you should be using DNS for name resolution.

    Wednesday, October 22, 2014 9:33 AM

All replies

  • You can't.  You need admin rights to amend the hosts files (for security reasons).

    You might be able to update this via Group Policy, but why do you need to update the hosts file.  This is old technology, and you should be using DNS for name resolution.

    Wednesday, October 22, 2014 9:33 AM
  • # Input:
    $Computers = @("PC1","PC2")
    $StringToAdd = "1.1.1.1 onthemoon.com"
    
    # Processing:
    foreach ($Computer in $Computers) {
        $HostsPath = "\\$Computer\$($env:windir.Replace(":","$"))\system32\drivers\etc\hosts"
        $StringToAdd | Out-File $HostsPath -Encoding ascii -Append
        
        # Output:
        Write-Output (Get-Content $HostsPath)
    }

    User running the script must be local admin on each computer..

    Script must be run in elevated permissions..


    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________ Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    Wednesday, October 22, 2014 10:24 AM
  • Why do you need to do this? This is common malware behavior.

    This is why DNS got invented, after all: To resolve host names.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, October 22, 2014 2:19 PM
    Moderator
  • It's difficult to explain, we have an infrastructure with several branches that connect to a central office via F5 (VPN) and the F5 is not resolving properly the DNS queries. Thanks for your comments.
    Thursday, October 23, 2014 9:56 AM
  • It's difficult to explain, we have an infrastructure with several branches that connect to a central office via F5 (VPN) and the F5 is not resolving properly the DNS queries. Thanks for your comments.

    Contact the VPN software vendor for instructions on how to set VPN to properly resolve queries.  This is a common issue caused by incorrectly configured VPN client or incompletely configured VPN client.

    Editing the hosts file is never a solution for this.  When a VPN is active it will forward DNS queries to the VPN endpoint network if it is correctly configured.


    ¯\_(ツ)_/¯

    Thursday, October 23, 2014 10:06 AM
  • 100% agree with jrv. Editing the hosts file is never the solution for this kind of problem. The VPN needs to be set up correctly.

    -- Bill Stewart [Bill_Stewart]

    Thursday, October 23, 2014 2:26 PM
    Moderator