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
    529
    537
    30
    #1 freddie-o, Dec 3, 2019
    Last edited: Dec 8, 2019
    These scripts add "Run as TrustedInstaller" to the context menu so you can run any Process as TrustedInstaller by right clicking them.




    Needs PowerRun




    Batch script (to install)

    NOTE: Run this batch script together in the same folder as "PowerRun.exe" and "PowerRun_x64.exe"
    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 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.exe add "HKCR\*\shell\runastrustedinstaller" /v "Icon" /t REG_SZ /d "imageres.dll,1" /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 "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 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 (
      del /q %SystemRoot%\system32\PowerRun.exe
      del /q %SystemRoot%\SysWOW64\PowerRun.exe
    ) else (
      del /q %SystemRoot%\system32\PowerRun.exe
    )
    Reg.exe delete "HKCR\*\shell\runastrustedinstaller" /f
    echo.UnInstall completed.
    >nul pause
    
    




    Reg file (no install)

    NOTE: Change the path (in the command string) to where your "PowerRun" folder is located.

    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]
    @="E:\\MY APPS\\PowerRun\\PowerRun_x64.exe \"%1\""
    
    



     
  2. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    529
    537
    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 Senior Member

    Jul 10, 2014
    328
    1,121
    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
    566
    290
    30
    I have not experienced this. All my programs (the ones I have tried) run fine with Nsudo.
     
  5. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    529
    537
    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
    529
    537
    30
    There is no problem with NSudo.exe GUI. Only with this script.
     
  7. Thomas Dubreuil

    Thomas Dubreuil MDL Senior Member

    Aug 29, 2017
    314
    523
    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
    529
    537
    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.