Avatar of Theo
 asked on

Am I an Administrator or not

I want to edit my hosts-file (W10), but I am not allowed. When I check the perimissions of the file I have Full Control, but nevertheless I cannot save any changes. According to the User Accounts I am administrator but when I right click on the Command Prompt or the Power shell, to enter as an administrator, nothing happens.

Avatar of undefined
Last Comment

8/22/2022 - Mon
Michael B. Smith

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Easy.  Right click on Notepad and select Run as Administrator. Navigate in Notepad to HOSTS. Edit and save. I do this whenever I have to edit HOSTS. Even if your are the Windows Admin, you still need to do this.

@ John: When I do this it tells me thet tha directory Etc does not contain any search results., whereas the Hosts file ought to be in here.

Once you have opened Notepad with Run as Administrator, navigate to the folder, and then for File Type (in Notepad), select All Files.  HOSTS will show up.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Here you go.

Lee W, MVP

Hosts and other systems files are protected.  You must EXPLICITLY access them as an administrator... not just be logged in as one.  John has explained what to do and you can also run a command prompt as an admin and then navigate to c:\windows\system32\drivers\etc and then run notepad hosts to edit the file.
David Johnson, CD

From Vista onwards we have the user access control technology to help secure our computer
Likewise in Linux if you are an administrator and you want to edit a protected item you would use
sudo command

In both cases an account that is an administrator will not be prompted for administrator credentials

When an administrator logs on, two separate access tokens are created for the user: a standard user access token and an administrator access token. The standard user access token contains the same user-specific information as the administrator access token, but the administrative Windows privileges and SIDs are removed. The standard user access token is used to start apps that do not perform administrative tasks (standard user apps). The standard user access token is then used to display the desktop (explorer.exe). Explorer.exe is the parent process from which all other user-initiated processes inherit their access token. As a result, all apps run as a standard user unless a user provides consent or credentials to approve an app to use a full administrative access token.

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Andrew Leniart

I struck this issue myself recently but found an easy workaround that I used.

  1. Right click on the Hosts file in File Explorer, copy and paste the existing hosts file to something like hosts.txt
  2. Edit the new hosts.txt file
  3. Rename the existing hosts file to something like hosts.bak (Windows allows me to rename for some reason, but not over write it)
  4. Save the edited hosts.txt file and rename to just hosts (no extension)
  5. Done

You'll get some UAC prompts to confirm the above rename operation, but it does work.

I hope that's helpful.

Regards, Andrew

could possibly do this as well :

$file = "$env:windir\System32\drivers\etc\hosts"
" bob" | Add-Content -PassThru $file
" john" | Add-Content -PassThru $file

Script isn't hard.  But, they'd have to set or bypass their script execution policy and run it as administrator.
Might be better off to give them an old fashion batch file to get around the execution policy, but they'd still have to run as.

Set file="%windir%\System32\drivers\etc\hosts"
echo bob >> %file%
echo john >>  %file%

Found on Spiceworks: https://community.spiceworks.com/topic/1070436-update-hosts-file-with-powershell?utm_source=copy_paste&utm_campaign=growth

reference : https://community.spiceworks.com/topic/1070436-update-hosts-file-with-powershell

Easier just to use Notepad as Administrator. Nothing else to do.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

Gentlemen, thanks,

as it has been mentioned - you still need to do rights elevation, even if logged in as admin.

if you have a regular need to edit - you can do it the following way -
1) create a shortcut to that file (i created it on desktop, but i use it REALLY often. you may choose your favorite location).
2) rightclick the shortcut and in properties preceed the filename by "notepad" (no quotes), and apply changes.
3) in advanced properties for shortcut tick "run as administrator" checkbox.

now when you invoke this shortcut, it immediately asks for access rights elevation, and - voila - save works as a charm.
also, you may just want to save a general shortcut for notepad (or whatever favorite plain text editor you have) with that "run as Administrator" checkbox, to be asked for access rights elevation immediately .