Can't edit 'hosts', nor run anything as admin

Discussion in 'Windows 8' started by Georgey, Aug 23, 2013.

  1. Georgey

    Georgey MDL Novice

    Dec 25, 2012
    27
    0
    0
    Hi,

    I don't even know if this is one problem or two.

    First, I tried to edit the 'hosts' file but wasn't let save the change as having no permission. I'm the only user and administrator. I took over ownership and gave full rights to myself, rebooted, still the same.

    Second, I tried to run notepad as administrator for the same reason. It wouldn't open. Then, I wanted to start it from an elevated command prompt, but cmd didn't start as admin either. This, like notepad, opened nicely as 'normal', neither as admin.

    I run Windows 8 Enterprise 64 bit.

    Thanks for any help.
     
  2. hbhb

    hbhb MDL Expert

    Dec 15, 2010
    1,017
    263
    60
    Open Command Prompt in Admin mode ,type the following command and then press Enter.

    sfc /scannow


    let it do its thing, slight chance it may repair any corrupted values your OS may have.
     
  3. s1ave77

    s1ave77 MDL Guide Dog/Dev

    Aug 15, 2012
    15,066
    20,293
    340
    Does the elevated CMD even refuse when started via Win+X?

    For the host file, i always copy to new location, edit it there and copy back :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. HeRoKaNe

    HeRoKaNe MDL Novice

    Aug 22, 2013
    1
    0
    0
    I always do the same thing. Edit it somewhere else and copy it back.
     
  5. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    6,818
    2,003
    210
    \I would do the same using an external Win2Go drive, not using the running Windows, change the file and replace with the original. That would give me the freedom for even if that file is locked within Windows.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. MrMagic

    MrMagic MDL Guru

    Feb 13, 2012
    5,726
    3,743
    180
    The problem with the hosts file is just the read-only flag you need to disable, then it will save
     
  7. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    7,714
    25,006
    240
    #7 abbodi1406, Aug 23, 2013
    Last edited by a moderator: Apr 20, 2017
    It's read-only file, you have to clear it first

    From elevated cmd:
    Code:
    SET hosts=%windir%\system32\drivers\etc\hosts
    attrib -r %hosts%
    notepad %hosts%
    attrib +r %hosts%
    
     
  8. MrMagic

    MrMagic MDL Guru

    Feb 13, 2012
    5,726
    3,743
    180
    #8 MrMagic, Aug 23, 2013
    Last edited by a moderator: Apr 20, 2017
    Or take ownership and uncheck the read-only box in properties
     
  9. HALIKUS

    HALIKUS MDL Addicted

    Jul 29, 2009
    527
    369
    30
    #9 HALIKUS, Aug 23, 2013
    Last edited by a moderator: Apr 20, 2017
    You can add a reference in your right click menu if you want with this. Save as a .reg and run. May need a reboot.

    Code:
    Windows Registry Editor Version 5.00
    
    ;Take Ownership of any File or Directory
    [HKEY_CLASSES_ROOT\*\shell\runas]
    @="Take Ownership"
    "NoWorkingDirectory"=""
    [HKEY_CLASSES_ROOT\*\shell\runas\command]
    @="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    [HKEY_CLASSES_ROOT\Directory\shell\runas]
    @="Take Ownership"
    "NoWorkingDirectory"=""
    [HKEY_CLASSES_ROOT\Directory\shell\runas\command]
    @="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
    
    
    ;add hosts file to right click
    [HKEY_CLASSES_ROOT\Directory\Background\shell\Edit HOSTS file]
    @="Edit HOSTS file"
    "HasLUAShield"=""
    ;"icon"="C:\Program Files\Internet Explorer\iexplore.exe"
    [HKEY_CLASSES_ROOT\Directory\Background\shell\Edit HOSTS file\command]
    @=hex(2):6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,\
      00,25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,73,00,79,00,73,00,\
      74,00,65,00,6d,00,33,00,32,00,5c,00,64,00,72,00,69,00,76,00,65,00,72,00,73,\
      00,5c,00,65,00,74,00,63,00,5c,00,68,00,6f,00,73,00,74,00,73,00,00,00
    
    
    
     
  10. Georgey

    Georgey MDL Novice

    Dec 25, 2012
    27
    0
    0
    The elevated command prompt wouldn't open from Win + X either. In all cases I see the whirling blue circle as the machine is working for a second, then nothing.

    The hosts file is not checked as read only.
    If I try to copy back an edited version, the paste option is grayed out.

    Neither me nor any program that I try to run can exercise administrator's rights. Maybe that's blocked somehow?
     
  11. MrMagic

    MrMagic MDL Guru

    Feb 13, 2012
    5,726
    3,743
    180
    Scan for malware
     
  12. LatinMcG

    LatinMcG Bios Borker

    Feb 27, 2011
    5,392
    1,465
    180
    disable UAC user access control then reboot and try it again
     
  13. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    5,857
    13,404
    180
    #13 Mr.X, Aug 23, 2013
    Last edited by a moderator: Apr 20, 2017
    Or simply copy it to the desktop, edit and then put it back overwriting it. It's easier, faster, isn't it?
     
  14. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    982
    60
    Never had a problem editing my host file- read only or not. I run CMD as admin and open notepad from inside it. Open host file, make changes and then save.

    @ Mister X, if read only is his problem, copying the file to the desktop will not nullify the read only file attribute.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    5,857
    13,404
    180
    #15 Mr.X, Aug 23, 2013
    Last edited: Aug 23, 2013
    You're right, I've checked the file and yes, again you are right. Sorry for the misleading info from me.
     
  16. fLOW.

    fLOW. MDL Senior Member

    Jul 28, 2009
    307
    222
    10
    let me ask something about this too.

    few days ago i needed to take control of a file in Windows folder, tried the .reg trick but it didn't worked... ended up doing it manually.

    isn't there a way of doin't it automatically? i've tried many things, none worked, im on windows 8 btw.
     
  17. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,773
    1,085
    60
  18. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,674
    10,073
    210
    If you open it by choosing to open with notepad or something, I'm not sure you can modify it.
    "Open With" does not open the program with admin permissions unless the program defaults to requiring admin permissions.
    Notepad definitely does NOT do that.

    Also, take ownership is neat, but you have to be careful how it is set up.
    The meat of a take ownership reg file is that it runs ICACLS to give permissions to administrator usually.
    If you don't open the editing program as administrator, how is it supposed to give you permission?

    What I suggest:
    Open admin notepad (winkey+r "notepad" ctrl-shift-enter)
    Opening with ctrl-shift-enter instead of regular enter will open it as admin.

    You still have to change the file so that it is not read-only.
    You can do that in file explorer. If it won't let you do it, copy it somewhere else, remove the read-only and copy it back and overwrite.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. LukasChan

    LukasChan MDL Novice

    Aug 27, 2013
    10
    16
    0
    No need to grant admin's permissions!

    just move hosts to your desktop, then you can edit now !!

    When done, move to etc folder.