amend windows hosts files says access denied?

Comments

11 comments

  • Brandon Bunnelle

    Have you tried running this step in PDQ Deploy as "Local System"?

    0
    Comment actions Permalink
  • Brandon Bunnelle

    Also post some screenshots of your package setup.

    0
    Comment actions Permalink
  • Mike Rowe

    I have tried running as system and hat also failed. Pretty sure it is the permissions that the accounts have as it is system file but strange it works when logged in normally (Including running the batch file).

     

    No screen shots to show really just fails and when I check the output file says access is denied.

    batch is just this

    Echo >> c:\windows\system32\drivers\etc\hosts
    Echo 10.80.x.x collabnhl.xxxxxx.gov.uk
    Exit

    xxx just so I do not give out addresses etc.

    0
    Comment actions Permalink
  • Mike Rowe

    0
    Comment actions Permalink
  • Stephen Valdinger

    Try a Powershell step. It will execute Powershell with the RunAs administrator option, giving you access to the C:\windows directory et. al.

     

    Use this as the code, just edit it so the ip and hostname are correct. Check output.log after deployment, it should return the contents of the host file in full:

    #Create backup of hosts file
    Copy-Item -Path C:\windows\system32\drivers\etc\hosts -Destination C:\windows\system32\drivers\etc\hosts.bak

    #write data to file, utf8 format as its a hosts file
    Write-Output '10.80.x.x collabnhl.xxxxxx.gov.uk' | Out-File -NoClobber C:\Windows\System32\drivers\etc\hosts -Append -Force utf8


    Write-Output $(Get-Content 'C:\windows\system32\drivers\etc\hosts')
    1
    Comment actions Permalink
  • Dan Sadler

    I used a File Copy Step.  Just put the Host File with the correct changes on the DFS Share then copied to the correct location with the Overwrite Existing.. 

    0
    Comment actions Permalink
  • Mike Rowe

    Dan,

     Can't do a file copy as different hosts on different PC's so need to append it.

     

    Stephen,

    That looks like a possible solution. I will try that

     

    Many Thanks to you all

    0
    Comment actions Permalink
  • Mike Rowe

    Powershell seems to work but hosts file is not updated when I checked it on some PC's

     

    Strange

    0
    Comment actions Permalink
  • Stephen Valdinger

    Works on everything I've tested on. I've got Windows 8.1 everywhere, and Powershell v4, but the code I wrote should be good all the way back to v2.

    0
    Comment actions Permalink
  • Brandon Bunnelle

    have you checked the log files on the machines the script failed on?

    0
    Comment actions Permalink
  • Mike Rowe

     

    Think the server it was running from was version 1.0 still so I have upgraded it and I will test.

     

     

     

    Many thanks for your efforts they are much appreciated

     

     

     

    0
    Comment actions Permalink

Please sign in to leave a comment.