Run as TrustedInstaller [from Context menu]

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

  1. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    643
    725
    30
    #1 freddie-o, Dec 3, 2019
    Last edited: Sep 12, 2020
    Add “Run as TrustedInstaller” to the Context menu. Then you can right click any Windows Process and run them as TrustedInstaller / NT Authority\System.




    Run as TrustedInstaller.png




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

    PowerRun v1.4 (Run with highest privileges)
    [Credits to @wtarkan]





    Batch script

    To install


    Put this script in the same folder as PowerRun.

    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
    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
    
    



    + + +​




    REG file

    No install

    Edit 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:\\My PowerRun Folder\\PowerRun_x64.exe \"%1\""
    
    

     
  2. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    643
    725
    30
    Had to replace NSudo with PowerRun because half the programs and scripts would not run or would hang using NSudo. But somehow PowerRun runs all of them (so far)
     
  3. Mouri_Naruto

    Mouri_Naruto MDL Developer

    Jul 10, 2014
    392
    1,303
    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 Addicted

    Sep 16, 2018
    819
    464
    30
    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
    643
    725
    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
    643
    725
    30
    There is no problem with NSudo.exe GUI. Only with this script.
     
  7. Thomas Dubreuil

    Thomas Dubreuil MDL Senior Member

    Aug 29, 2017
    356
    587
    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
    643
    725
    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.