amend windows hosts files says access denied?
Trying to amend a windows hosts file to add an entry as not all host files are the same at the moment
I can edit the file manually on the PC's and then created a batch file to amend the file.
However when I run it It fails with an access denied error. I am running it thorough PDQ deploy with the same credentials as when I do it manually
Any suggestions please?
-
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
Exitxxx just so I do not give out addresses etc.
-
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')
Please sign in to leave a comment.
Comments
11 comments