Add "Run as TrustedInstaller" to Context menu

Discussion in 'Scripting' started by freddie-o, Dec 3, 2019.

  1. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    899
    1,146
    30
    #1 freddie-o, Dec 3, 2019
    Last edited: Nov 30, 2021
    Run as TRustedInstaller.png



    Right click any Windows Process and run them as TrustedInstaller / NT Authority\System.

    All we need is PowerRun to elevate a Windows process to TrustedInstaller / NT Authority\System privileges.


    Download
    PowerRun v1.5
    (Credits to @wtarkan)



    Batch scripts
    Note: Put the scripts in the same folder as PowerRun.



    To install "Run as TrustedInstaller"
    Code:
    @echo off
    if defined PROCESSOR_ARCHITEW6432 start %SystemRoot%\Sysnative\cmd.exe /c "%~dpnx0" %* & exit
    cls
    >NUL 2>&1 REG QUERY "HKU\S-1-5-19" ||(
      echo.Run as Admin !
       >nul pause
    exit
    )
    cd /d "%~dp0"
    set "arch=x64"
    if /i %PROCESSOR_ARCHITECTURE%==x86 if not defined PROCESSOR_ARCHITEW6432 set "arch=x86"
    if %arch%==x64 (
      copy PowerRun_x64.exe %SystemRoot%\system32\PowerRun.exe /y
      copy PowerRun.exe %SystemRoot%\SysWOW64\PowerRun.exe /y
    ) else (
      copy PowerRun.exe %SystemRoot%\system32\PowerRun.exe /y
    )
    Reg add "HKCR\*\shell\Run as TrustedInstaller"
    Reg add "HKCR\*\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "imageres.dll,1" /f
    Reg add "HKCR\*\shell\Run as TrustedInstaller\command" /v "" /t REG_SZ /d "PowerRun.exe \"%%1\"" /f
    echo.Install completed.
    >nul pause
    


    To uninstall "Run as TrustedInstaller"
    Code:
    @echo off
    if defined PROCESSOR_ARCHITEW6432 start %SystemRoot%\Sysnative\cmd.exe /c "%~dpnx0" %* & exit
    cls
    >NUL 2>&1 REG QUERY "HKU\S-1-5-19" ||(
      echo.Run as Admin !!!
      >nul pause
      exit
    )
    cd /d "%~dp0"
    set "arch=x64"
    if /i %PROCESSOR_ARCHITECTURE%==x86 if not defined PROCESSOR_ARCHITEW6432 set "arch=x86"
    if %arch%==x64 (
      del /q %SystemRoot%\system32\PowerRun.exe
      del /q %SystemRoot%\SysWOW64\PowerRun.exe
    ) else (
      del /q %SystemRoot%\system32\PowerRun.exe
    )
    Reg delete "HKCR\*\shell\Run as TrustedInstaller" /f
    echo.Uninstall completed.
    >nul pause
    



    Alternatively you can just use a REG file. However you cannot move or delete the PowerRun folder

    REG file
    Modify the location of your PowerRun folder.

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\*\shell\Run as TrustedInstaller]
    "Icon"="imageres.dll,1"
    
    [HKEY_CLASSES_ROOT\*\shell\Run as TrustedInstaller\command]
    @="X:\\PowerRun Folder\\PowerRun_x64.exe \"%1\""
    

     
  2. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    899
    1,146
    30
  3. Mouri_Naruto

    Mouri_Naruto MDL Developer

    Jul 10, 2014
    469
    1,564
    10
    I need some "programs and scripts would not run or would hang using NSudo" for testing and try to solve the issue.
     
  4. boyonthebus

    boyonthebus MDL Expert

    Sep 16, 2018
    1,005
    651
    60
    I have not experienced this. All my programs (the ones I have tried) run fine with Nsudo.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    899
    1,146
    30
    #5 freddie-o, Dec 4, 2019
    Last edited: Dec 4, 2019
    (OP)
    EDIT:

    Hi. This is the script I used.

    Code:
    @echo off
    if defined PROCESSOR_ARCHITEW6432 start %SystemRoot%\Sysnative\cmd.exe /c "%~dpnx0" %* & exit
    cls
    >NUL 2>&1 net.exe session ||(
      echo.Run as Admin !!!
        >nul pause
    exit
    )
    cd /d "%~dp0"
    set "arch=x64"
    if /i %PROCESSOR_ARCHITECTURE%==x86 if not defined PROCESSOR_ARCHITEW6432 set "arch=x86"
    if %arch%==x64 (
      copy NSudoG.exe %SystemRoot%\system32\NSudoG.exe /y
      copy NSudoG.exe %SystemRoot%\SysWOW64\NSudoG.exe /y
    ) else (
      copy NSudoG.exe %SystemRoot%\system32\NSudoG.exe /y
    )
    Reg.exe add "HKCR\*\shell\runastrustedinstaller" /v "" /t REG_SZ /d "Run as TrustedInstaller" /f
    Reg.exe add "HKCR\*\shell\runastrustedinstaller" /v "Description" /t REG_SZ /d "Run as TrustedInstaller" /f
    Reg.exe add "HKCR\*\shell\runastrustedinstaller" /v "Icon" /t REG_SZ /d "imageres.dll,73" /f
    Reg.exe add "HKCR\*\shell\runastrustedinstaller" /v "MUIVerb" /t REG_SZ /d "Run as TrustedInstaller" /f
    Reg.exe add "HKCR\*\shell\runastrustedinstaller\command" /v "" /t REG_SZ /d "NSudoG.exe -U:T -P:E \"%%1\"" /f
    echo.Install completed.
    >nul pause
    
    

    I tried these other parameters too...

    Code:
    NSudoG.exe -U:T -P:E -M:S
    
    NSudoG.exe -U:T -ShowWindowMode:Hide
    
    NSudoG.exe -U:T -P:E -ShowWindowMode:Hide
    
    NSudoG.exe -U:T -P:E -M:S -ShowWindowMode:Hide
    
    
    Using NSudo, NSudoC and NSudoG

    Which caused some programs to hang, error installing my .BAT script and .REG files not able to merge.

    After testing some more, I tried this

    Code:
    NSudoG.exe -U:T
    
    
    This time it worked. The programs no longer hang. :)


    EDIT:

    The problem now is... one of my .BAT script that merges all my .REG files still has an error and .REG files still don't merge





     
  6. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    899
    1,146
    30
    There is no problem with NSudo.exe GUI. Only with this script.
     
  7. Thomas Dubreuil

    Thomas Dubreuil MDL Senior Member

    Aug 29, 2017
    358
    601
    10
    #7 Thomas Dubreuil, Dec 4, 2019
    Last edited: Dec 4, 2019
    Use NSudo.ContextMenu.Launcher maybe ?

    Not sure such effort is needed for NSudo, since you can easyinstall NSudo Context menu with NSudo Installer, which link is also on official NSudo Download page.
    One of the advantages of the installer is
    -You can have NSudo in any location (+ it adds NSudo path to environment variables path),
    -The context menu options between:
    All files (HKEY_CLASSES_ROOT*\shell\NSudo)
    exe files and batch scripts: .exe .bat .cmd .inf .ps1 .py .reg .vbs
    exe files only
    -Few different options like start menu shortcut, tile icons, custom json (more programs), uninstall support via programs and features etc.
    -It is pure batch

    Having a look at the script, you can see how I implement NSudo context menu, for example
    Code:
    reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSudo.RunAs.TrustedInstaller.EnableAllPrivileges\command" /ve /t REG_SZ /d "\"%NSudoFolder%\NSudo.exe\" -U:T -P:E -ShowWindowMode=Hide cmd /c start \"NSudo.ContextMenu.Launcher\" \"%%1\"" /f
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    899
    1,146
    30
    #8 freddie-o, Dec 5, 2019
    Last edited: Dec 5, 2019
    (OP)
    Works. Except for this one batch script of mine that merges all my reg files...

    When I Run As TrustedInstaller. Run As System and Run As System (Enable All Privileges), this shows...
    NSudo.jpg


    When I Run As TrustedInstaller (Enable All Privileges), nothing happens?

    But the batch script runs OK on my Run as TrustedInstaller script.

    EDIT:

    Also all I really need is to Run as TrustedInstaller.
     
  9. JeepWillys58

    JeepWillys58 MDL Senior Member

    Nov 6, 2010
    397
    177
    10
    #9 JeepWillys58, Nov 23, 2021
    Last edited: Nov 23, 2021
    Hi dear friend @freddie-o ,

    I would like to add a little addendum to your PowerRun install and uninstall scripts to make it easier to use...

    PowerRun Install by @freddie-o

    Code:
    @echo off
    
    REM change wording if needed..
    TITLE PowerRun Install by @freddie-o
    echo Checking for admin rights...
    Echo.
    Echo.
    Echo  ....Please click on "Yes"....
    
    reg.exe query HKU\S-1-5-19 1>nul 2>nul && goto :gotAdmin
    if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
    
    :gotAdmin
        pushd "%~dp0"
    cls
    if defined PROCESSOR_ARCHITEW6432 start %SystemRoot%\Sysnative\cmd.exe /c "%~dpnx0" %* & exit
    cls
    >NUL 2>&1 REG QUERY "HKU\S-1-5-19" ||(
      echo.Run as Admin !
       >nul pause
    exit
    )
    cd /d "%~dp0"
    set "arch=x64"
    if /i %PROCESSOR_ARCHITECTURE%==x86 if not defined PROCESSOR_ARCHITEW6432 set "arch=x86"
    if %arch%==x64 (
      copy PowerRun_x64.exe %SystemRoot%\system32\PowerRun.exe /y
      copy PowerRun.exe %SystemRoot%\SysWOW64\PowerRun.exe /y
    ) else (
      copy PowerRun.exe %SystemRoot%\system32\PowerRun.exe /y
    )
    Reg add "HKCR\*\shell\Run as TrustedInstaller"
    Reg add "HKCR\*\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "imageres.dll,1" /f
    Reg add "HKCR\*\shell\Run as TrustedInstaller\command" /v "" /t REG_SZ /d "PowerRun.exe \"%%1\"" /f
    echo.Install completed.
    timeout /t 3 >nul
    exit
    
    PowerRun Uninstall by @freddie-o
    Code:
    @echo off
    
    REM change wording if needed..
    TITLE PowerRun Uninstall by @freddie-o
    echo Checking for admin rights...
    Echo.
    Echo.
    Echo  ....Please click on "Yes".....
    
    reg.exe query HKU\S-1-5-19 1>nul 2>nul && goto :gotAdmin
    if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
    
    :gotAdmin
        pushd "%~dp0"
    cls
    if defined PROCESSOR_ARCHITEW6432 start %SystemRoot%\Sysnative\cmd.exe /c "%~dpnx0" %* & exit
    cls
    >NUL 2>&1 REG QUERY "HKU\S-1-5-19" ||(
      echo.Run as Admin !!!
      >nul pause
      exit
    )
    cd /d "%~dp0"
    set "arch=x64"
    if /i %PROCESSOR_ARCHITECTURE%==x86 if not defined PROCESSOR_ARCHITEW6432 set "arch=x86"
    if %arch%==x64 (
      del /q %SystemRoot%\system32\PowerRun.exe
      del /q %SystemRoot%\SysWOW64\PowerRun.exe
    ) else (
      del /q %SystemRoot%\system32\PowerRun.exe
    )
    Reg delete "HKCR\*\shell\Run as TrustedInstaller" /f
    echo.Uninstall completed.
    timeout /t 3 >nul
    exit
    
    Happy computing!

    Regards.
    @JeepWillys58
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. JeepWillys58

    JeepWillys58 MDL Senior Member

    Nov 6, 2010
    397
    177
    10
    Hi dear friend @Mouri_Naruto

    I had a problem when I use it, but let's do like "Hannibal" and let's go by parts...lol...

    I install the Nsudo using the install script "NSudo_Launcher_Installer_AIO.bat"

    After setting up a WIM to do some customizations, I open a Command Prompt by selecting "Run as TrustedInstaller (Enable all privileges)" and type a command to copy a modified file, hosts and sethc.exe, the host file it copies with no problem, but in the sethc.exe file the prompt returns the message "You don't have admin rights to copy" or something like that.

    Has anyone had the same problem?

    Regards.
    @JeepWillys58
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...