Open Notepad as Administrator with Context Menu?

Page 1 of 2 12 LastLast

  1. Posts : 26
    Windows 10 Pro
       #1

    Open Notepad as Administrator with Context Menu?


    I'm often having to edit batch files in my C: drive or my windows hosts files and forever running into access permissions issues.

    I've seen a few posts showing how you can make a registry style hack to add a right-click option to open a file as notepad as admin, but none of them seem to work in Windows 10?

    Here's the code that I found to create an .inf file to do this for Win8 (it doesn't work for me in Win10). I'm wondering if any gurus here could help me modify it to work on Windows 10?

    Code:
    [version]Signature="$Windows NT$"Class="Open in Notepad As Admin for Win8.1"Provider="%Microsoft%"
    [OpeninNotepadAsAdminInstall]CopyFiles = OpeninNotepadAsAdmin.Files.InfAddReg    = OpeninNotepadAsAdmin.AddReg
    [DefaultInstall]
    CopyFiles = OpeninNotepadAsAdmin.Files.Inf
    AddReg    = OpeninNotepadAsAdmin.AddReg
    
    [DefaultUnInstall]
    DelFiles  = OpeninNotepadAsAdmin.Files.Inf
    DelReg    = OpeninNotepadAsAdmin.DelReg
    
    [SourceDisksNames]
    55="Open in Notepad as Admin","",1
    
    [SourceDisksFiles]
    OpeninNotepadAsAdmin.INF=55
    
    [DestinationDirs]
    OpeninNotepadAsAdmin.Files.Inf = 17
    
    [OpeninNotepadAsAdmin.Files.Inf]
    OpeninNotepadAsAdmin.INF
    
    [OpeninNotepadAsAdmin.AddReg]
    HKLM,%UDHERE%,DisplayName,,"%OpeninNotepadAsAdminName%"
    HKLM,%UDHERE%,DisplayIcon,,"C:\Windows\notepad.exe,0"
    HKLM,%UDHERE%,DisplayVersion,,"%DisplayVersion%"
    HKLM,%UDHERE%,DisplayPublisher,,"%DisplayPublisher%"
    HKLM,%UDHERE%,DisplaySize,,"%DisplaySize%"
    HKLM,%UDHERE%,UninstallString,,"rundll32.exe syssetup.dll, SetupInfObjectInstallAction DefaultUninstall 132 %17%\OpeninNotepadAsAdmin.inf"
    HKCR,*\Shell\runas,,,"%OpeninNotepadAsAdminAccel%"
    HKCR,*\Shell\runas,Icon,,"C:\\Windows\\system32\\notepad.exe,0"
    HKCR,*\Shell\runas\command,,,"%11%\notepad.exe ""%1"""
    HKCU,%IEHERE%,Secondary Start Pages,0x00010008,"%DisplayURL%";FLG_ADDREG_TYPE_MULTI_SZ | FLG_ADDREG_APPEND
    
    [OpeninNotepadAsAdmin.DelReg]
    HKLM,%UDHERE%HKCR,*\shell\runas
    HKCR,Directory\Shell\runas
    HKCR,Drive\Shell\runas;
    HKCU,%IEHERE%,Secondary Start Pages,0x00010020,"%DisplayURL%"; did not work to uninstall website, removed all 2nd websites now way to save what you had
    
    [Strings]
    DisplayPublisher = "Microsoft"
    OpeninNotepadAsAdminName="Open in Notepad as Admin [by MetadataConsulting.ca](Uninstall only)"
    DisplayVersion = "2014.04.27"
    DisplaySize = "4 Kb"
    DisplayURL = "http://metadataconsulting.blogspot.ca/"
    OpeninNotepadAsAdminAccel="Open in Notepad as Admin"
    UDHERE="Software\Microsoft\Windows\CurrentVersion\Uninstall\OpeninNotepadAsAdmin"
    IEHERE="Software\Microsoft\Internet Explorer\Main"
      My Computer


  2. Posts : 42,955
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hosts file: try Bluelife HostsEditor
    BlueLife Hosts Editor Download
    - no permissions issues. Freeware
      My Computers


  3. Posts : 14,005
    Win10 Pro and Home, Win11 Pro and Home, Win7, Linux Mint
       #3

    Don't know if it's what you are looking for but I right-clicked the Desktop, chose New, Shortcut then located notepad.exe in the C:\Windows Folder and finished. Then I right-clicked the shortcut, Properties and in the Shortcut tab clicked Advanced then put a checkmark in Run as Administrator. As has been noted various places since Win10 came out, can't do much with icons on the Start menu or the Tiles but once the Shortcut has been created you can do more with it.
      My Computers


  4. Posts : 41,460
    windows 10 professional version 1607 build 14393.969 64 bit
       #4

    See if these command lines/ methods work:

    1) Open administrative command prompt and type or copy and paste:

    runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc
    runas /noprofile /user:mymachine\administrator cmd

    2) Type notepad in the left lower corner search then right click on the best match notepad and run as administrator


    3) This one is similar to Berton's method above except you type the location
    Right click on the desktop and hover over new and select shortcut
    Type the location: %windir%\System32\notepad.exe
    next
    choose the name: Notepad
    Finish
    Right click on the short cut, click properties, click advanced, check run as administrator
    With the shortcut on the desktop it is left click opened automatically as administrator.
      My Computer


  5. Posts : 17,661
    Windows 10 Pro
       #5

    Berton said:
    As has been noted various places since Win10 came out, can't do much with icons on the Start menu or the Tiles .
    I have not nor have I had any issues in running any app elevated (including Notepad) from Start Menu or Start tile.

    Open Notepad as Administrator  with Context Menu?-image.png
      My Computer


  6. Posts : 26
    Windows 10 Pro
    Thread Starter
       #6

    These are all good suggestions, but not quite what I was hoping to achieve.

    Given the number of times I need to edit a host file or some of my custom .bat files located in various locations that might have protected permissions that prevent saving updated files, I was trying to find a context-menu driven option. Since I do this with a high-degree of frequency it's annoying having to open notepad and then use the Open menu option and navigate to the files I'm trying to work on.

    The other option is to use Notepad++ with the plugin for saving as an admin to get right-click edit/save options. I just saw this script that worked in Win8 and thought that maybe I could tweak/fix it and get it working in Win10 without having to go for a third-party software solution.
      My Computer


  7. Posts : 14,005
    Win10 Pro and Home, Win11 Pro and Home, Win7, Linux Mint
       #7

    On my computers the .txt files when double-clicked will open in Notepad by default. Can't do that with .bat file as double-clicking them will cause them do what they are programmed to do. Right-clicking a .bat file and choosing Edit lets me do it. I've been doing that way when needed since back in MS-DOS 5 and Windows 3.1 days. I'm sure an appropriate script will work but since I've quit programming I like simpler.
      My Computers


  8. Posts : 42,955
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #8

    Ok, here's a way to do it using Autohotkey.

    1. write an AHK script like this:
    Run, *runas notepad.exe %1%
    exit
    2. Compile it to e.g. Notepad admin.exe
    3. Using e.g. this program (for convenience) do this:
    Open Notepad as Administrator  with Context Menu?-snap-2017-06-02-08.45.41.jpg
    to add the compiled program to the context menu.
    (Sorry, I realise that prog is not free... there are others or you can achieve the same using regedit or the venerable Contextedit etc).

    (Here I've added it for all files- you can choose which one or ones you want).

    Now right clicking a file and clicking 'Notepad admin'
    Open Notepad as Administrator  with Context Menu?-untitled.png

    gives a UAC prompt ('cos Notepad's run as admin) and opens your file.
    Last edited by dalchina; 23 Oct 2017 at 00:39.
      My Computers


  9. Posts : 26
    Windows 10 Pro
    Thread Starter
       #9

    Genius, Dalchina. Works a treat. Even works properly after I replace notepad with notepad2! Thank you!
      My Computer


  10. Posts : 42,955
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #10

    Well done for understanding that!
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:33.
Find Us




Windows 10 Forums