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.
TheoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael B. SmithManaging ConsultantCommented:
These three lines of PowerShell tell you whether your current PowerShell session has administrative credentials

$identity  = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object System.Security.Principal.WindowsPrincipal( $identity )
$principal.IsInRole( [System.Security.Principal.WindowsBuiltInRole]::Administrator )

Open in new window

It will probably return $false.

From a cmd.exe session enter
net localgroup administrators

Open in new window

If your username is in that list, you should be able to "run as administrator".

I just thought of this: if you should be able to run as administrator, then you can start a normal PowerShell session and enter this command:
start-process -filepath powershell.exe -arg "-noexit" -verb runas

Open in new window

That will start an elevated PowerShell session and you should be able to edit the file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JohnBusiness Consultant (Owner)Commented:
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.
0
TheoAuthor Commented:
@ 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.
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

JohnBusiness Consultant (Owner)Commented:
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.
0
JohnBusiness Consultant (Owner)Commented:
Here you go.

Windows-10-Notepad-Admin-us
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
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.
0
David Johnson, CD, MVPOwnerCommented:
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.

https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works
1
Andrew LeniartEE Senior Editor & Independent IT ConsultantCommented:
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
0
ITguy565Commented:
could possibly do this as well :

$file = "$env:windir\System32\drivers\etc\hosts"
"192.168.1.1 bob" | Add-Content -PassThru $file
"192.168.1.2 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 192.168.1.1 bob >> %file%
echo 192.168.1.2 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
0
JohnBusiness Consultant (Owner)Commented:
Easier just to use Notepad as Administrator. Nothing else to do.
0
TheoAuthor Commented:
Gentlemen, thanks,
0
corowerIT AdministratorCommented:
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 .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.