Run as Administrator


  1. Posts : 1,702
    X
       #1

    Run as Administrator


    I have a registry setting that adds an item to the explorer context menu.
    When I right-click on a file I get a "Taboo" item in the menu.

    This is the registry entry:

    [HKEY_CLASSES_ROOT\*\shell\Taboo]
    @="Taboo"

    [HKEY_CLASSES_ROOT\*\shell\Taboo\command]
    @="C:\\Windows\\System32\\bash.exe -i -c \"/mnt/c/apps/scripts/taboo '%1'\""


    taboo is a shell script that runs under a bash shell.
    It needs to run as Administrator because it runs diskpart.exe
    But when invoked from the context menu it does NOT run as Administrator, so diskpart won't run: "Permission denied".

    If I open a shell from a regular shortcut (with the "Run as Administrator" checkbox in the shortcut), I can run taboo, and it can run diskpart without error.

    Question: Is there some modification to my registry setting that will cause bash (and taboo) to be invoked as Administrator?
      My Computer


  2. Posts : 8,689
    windows 10
       #2
      My Computer


  3. Posts : 1,702
    X
    Thread Starter
       #3

    I tried "runas" but it asks for a password.

    How does a regular .lnk shortcut get to run as Administrator? What's the magic behind that "Run as Administrator" check box?
      My Computer


  4. Posts : 8,689
    windows 10
       #4

    One way to do it, is by storing the password in a textfile along with an enter (new line) and then use the command as follows:

    runas /user:localadmin "c:\users\localuser\desktop\control.exe" < password.txt

    What this does is use password.txt as input as if these are entered in console by a user. Every keypress you make that produces a character will be transmitted to your command.

    The downside is that you store the password in a textfile that can be opened. You could generate the password.txt (or whatever you name the file) in your script, but then your script has the password in plain text stored which is not ideal either
      My Computer


  5. Posts : 17,103
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #5

    margrave55 said:
    Question: Is there some modification to my registry setting that will cause bash (and taboo) to be invoked as Administrator?
    margrave55 said:
    How does a regular .lnk shortcut get to run as Administrator? What's the magic behind that "Run as Administrator" check box?
    If you are content for an Admin prompt to appear
    Don't use the Registry entry to run the script.
    Use the Registry entry to run a shortcut to the script
    - The shortcut Target field should probably be [but I know nothing about bash] bash.exe -i -c "/mnt/c/apps/scripts/taboo '%1'"
    - When you've created the shortcut, set its Properties, Advanced to RunAsAdmin.

    If you want to bypass the Admin prompt
    Set up a Task scheduler task to run the script.
    - Start TS as Admin [you can, if necessary, see above about using a shortcut do this]
    - Set the task to run with highest privileges [which will demand that Admin's password when setting it up but not when running it].
    Use the Registry entry to invoke the task not the script e.g. SchTasks.exe /Run /TN "TaskManager"
    There's an example & fuller instructions in Create Elevated App Shortcut without Admin Prompt - TenForumsTutorials

    If you want to bypass the Admin prompt and have the script execute minimised & with an icon of your own choosing
    Combine the previous section with Make Task scheduler run a batch file minimised and with a specific icon - TenForums


    All the best,
    Denis
      My Computer


 

  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 10:35.
Find Us




Windows 10 Forums