"Run as TrustedInstaller" from Context menu

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

  1. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,571
    2,615
    60
    No, my script opens a command window as TrustedInstaller in whatever folder or drive you shift+right click
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. retest

    retest MDL Member

    Nov 2, 2010
    116
    63
    10
    With "C:\Portable Programs\Notepad2" this is what I get using your script and mine :

    ti.jpg

    I only used your script for folders. This:

    Code:
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "imageres.dll,263" /f
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here\command" /ve /t REG_SZ /d "\"C:\Windows\System32\PowerRun.exe\" \"cmd.exe\" /k" /f
    
    pause
     
  3. @retest can you please test doggie-ones iirc 1 page back, the way it invokes TI is a bit different. the sudo files are expected to be in system32, the other wont harm.

    Code:
    reg add "HKCR\*\shell\Run as TrustedInstaller" /ve /t REG_SZ /d "Run as TrustedInstaller" /f
    reg add "HKCR\*\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "imageres.dll,208" /f
    reg add "HKCR\*\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun_x64.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1
     
  4. retest

    retest MDL Member

    Nov 2, 2010
    116
    63
    10
    works for exes. but did not create a reg key for folders.

    i tried this for folders
    Code:
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe  /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f
    
    got a flash of a cmd window.
    -----
    tried (used /k with cmd)
    Code:
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe /K for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f
    
    got this cmd window and a additional explorer window. PRun expects a executable I suppose. the cmd window is not TI.
    Capture_2024-08-01_112207.jpg

    -----

    But the /WD is a good idea.
     
  5. Then it (mine) needs explicitely the reg addresses from the other solution ... so directory and some more ... not \*\ --- now i get it :D'oh³:

    If you can test...will tinker later and report.
     
  6. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,571
    2,615
    60
    #126 freddie-o, Aug 1, 2024
    Last edited: Aug 7, 2024
    (OP)
    Open command window as TrustedInstaller here

    Open command window as TrustedInstaller here.png


    Install "Run as TrustedInstaller from context menu" script first

    Opens with Shift + Right click


    Code:
    @Echo Off
    @reg query HKU\S-1-5-19>nul 2>nul||(set 0="%~f0" %*&powershell -nop -c start cmd -args '/x/d/q/rcall',$env:0 -v runas&exit)
    
    reg add "HKCR\Directory\background\shell\Open command window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg add "HKCR\Directory\background\shell\Open command window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "imageres.dll,263" /f
    reg add "HKCR\Directory\background\shell\Open command window as TrustedInstaller here\command" /ve /t REG_SZ /d "\"C:\Windows\System32\PowerRun.exe\" cmd.exe /s /k pushd \"%%V\" & Title cmd.exe as TrustedInstaller" /f
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "imageres.dll,263" /f
    reg add "HKCR\Directory\shell\Open command window as TrustedInstaller here\command" /ve /t REG_SZ /d "\"C:\Windows\System32\PowerRun.exe\" cmd.exe /s /k pushd \"%%V\" & Title cmd.exe as TrustedInstaller" /f
    reg add "HKCR\Drive\shell\Open command window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg add "HKCR\Drive\shell\Open command window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "imageres.dll,263" /f
    reg add "HKCR\Drive\shell\Open command window as TrustedInstaller here\command" /ve /t REG_SZ /d "\"C:\Windows\System32\PowerRun.exe\" cmd.exe /s /k pushd \"%%V\" & Title cmd.exe as TrustedInstaller" /f
    
    pause
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. inTerActionVRI

    inTerActionVRI MDL Expert

    Sep 23, 2009
    1,748
    3,575
    60
    #127 inTerActionVRI, Aug 10, 2024
    Last edited: Aug 10, 2024
    @freddie-o,

    Do you know the workaround I did to fix the problem of WorkingDir ending up in System32?

    I applied the same redundancy to this for Open Here feature.

    Since some people said it wasn't working on their machines, it works fine on our machines, and we have different results, since we already have some things fixed on our machines.

    And I also added the Open here from PoweShell.

    upload_2024-8-9_21-21-29.png

    upload_2024-8-9_21-22-42.png

    Code:
    @Echo Off
    @reg.exe query HKU\S-1-5-19>nul 2>nul||(set 0="%~f0" %*&powershell -nop -c start cmd -args '/x/d/q/rcall',$env:0 -v runas&exit)
    
    reg.exe delete "HKCR\Directory\background\shell\Open command window as TrustedInstaller here" /f >nul 2>&1
    reg.exe delete "HKCR\Directory\shell\Open command window as TrustedInstaller here" /f >nul 2>&1
    reg.exe delete "HKCR\Drive\shell\Open command window as TrustedInstaller here" /f >nul 2>&1
    
    reg.exe delete "HKCR\Directory\background\shell\Open CMD window as TrustedInstaller here" /f >nul 2>&1
    reg.exe delete "HKCR\Directory\shell\Open CMD window as TrustedInstaller here" /f >nul 2>&1
    reg.exe delete "HKCR\Drive\shell\Open CMD window as TrustedInstaller here" /f >nul 2>&1
    
    reg.exe add "HKCR\Directory\background\shell\Open CMD window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg.exe add "HKCR\Directory\background\shell\Open CMD window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "imageres.dll,263" /f
    reg.exe add "HKCR\Directory\background\shell\Open CMD window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe /C for %%%%# in (\"%%V\") do cls & PowerRun.exe \"/WD:%%%%~dp#\" cmd.exe /K title \"cmd.exe as TrustedInstaller\"" /f
    reg.exe add "HKCR\Directory\shell\Open CMD window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg.exe add "HKCR\Directory\shell\Open CMD window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "imageres.dll,263" /f
    reg.exe add "HKCR\Directory\shell\Open CMD window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe /C for %%%%# in (\"%%V\") do cls & PowerRun.exe \"/WD:%%%%~dp#\" cmd.exe /K title \"cmd.exe as TrustedInstaller\"" /f
    reg.exe add "HKCR\Drive\shell\Open CMD window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg.exe add "HKCR\Drive\shell\Open CMD window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "imageres.dll,263" /f
    reg.exe add "HKCR\Drive\shell\Open CMD window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe /C for %%%%# in (\"%%V\") do cls & PowerRun.exe \"/WD:%%%%~dp#\" cmd.exe /K title \"cmd.exe as TrustedInstaller\"" /f
    
    
    reg.exe delete "HKCR\Directory\background\shell\Open PowerShell window as TrustedInstaller here" /f >nul 2>&1
    reg.exe delete "HKCR\Directory\shell\Open PowerShell window as TrustedInstaller here" /f >nul 2>&1
    reg.exe delete "HKCR\Drive\shell\Open PowerShell window as TrustedInstaller here" /f >nul 2>&1
    
    reg.exe add "HKCR\Directory\background\shell\Open PowerShell window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg.exe add "HKCR\Directory\background\shell\Open PowerShell window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "PowerShell.exe" /f
    reg.exe add "HKCR\Directory\background\shell\Open PowerShell window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe /C for %%%%# in (\"%%V\") do cls & PowerRun.exe \"/WD:%%%%~dp#\" PowerShell.exe -NoExit -NoProfile -Command \"$host.UI.RawUI.WindowTitle = 'PowerShell.exe as TrustedInstaller'\"" /f
    reg.exe add "HKCR\Directory\shell\Open PowerShell window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg.exe add "HKCR\Directory\shell\Open PowerShell window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "PowerShell.exe" /f
    reg.exe add "HKCR\Directory\shell\Open PowerShell window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe /C for %%%%# in (\"%%V\") do cls & PowerRun.exe \"/WD:%%%%~dp#\" PowerShell.exe -NoExit -NoProfile -Command \"$host.UI.RawUI.WindowTitle = 'PowerShell.exe as TrustedInstaller'\"" /f
    reg.exe add "HKCR\Drive\shell\Open PowerShell window as TrustedInstaller here" /v "Extended" /t REG_SZ /d "" /f
    reg.exe add "HKCR\Drive\shell\Open PowerShell window as TrustedInstaller here" /v "Icon" /t REG_SZ /d "PowerShell.exe" /f
    reg.exe add "HKCR\Drive\shell\Open PowerShell window as TrustedInstaller here\command" /ve /t REG_EXPAND_SZ /d "cmd.exe /C for %%%%# in (\"%%V\") do cls & PowerRun.exe \"/WD:%%%%~dp#\" PowerShell.exe -NoExit -NoProfile -Command \"$host.UI.RawUI.WindowTitle = 'PowerShell.exe as TrustedInstaller'\"" /f
    
    pause
    
     
  8. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,571
    2,615
    60
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. inTerActionVRI

    inTerActionVRI MDL Expert

    Sep 23, 2009
    1,748
    3,575
    60
    This error has nothing to do with the "Open Here" changes.
    I'm also getting this error, now. But it is related to download URL. This has been changed or protected. If you manually put the PowerRun.zip in next to script, it is installed.

    edit: New link adds the version to the filename:
    Code:
    REM set "DownloadURI=https://www.sordum.org/files/download/power-run/PowerRun.zip"
    set "DownloadURI=https://www.sordum.org/files/download/power-run/PowerRun_v1.7.zip"
    
     
  10. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,571
    2,615
    60

    You da man! Updated the OP
    Also added a link to your "Open command and powershell window as TrustedInstaller here"
    https://forums.mydigitallife.net/th...r-from-context-menu.80713/page-7#post-1847401
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. retest

    retest MDL Member

    Nov 2, 2010
    116
    63
    10
    Just a suggestion.

    I tried this in Powershell ISE and it worked :
    Code:
    (New-Object System.Net.WebClient).DownloadFile('https://www.sordum.org/files/downloads.php?power-run', 'C:\TEMP\pr.zip')
    
    If you use that URL even if the file name/version changes it will still work.

    @freddie-o @inTerActionVRI
     
  12. inTerActionVRI

    inTerActionVRI MDL Expert

    Sep 23, 2009
    1,748
    3,575
    60
    #132 inTerActionVRI, Aug 11, 2024
    Last edited: Aug 11, 2024
    Yes. I also have doing something like this with PowerShell, but you brought it here first, thanks!
    I am just like to get the file and bring the timestamp from server to save the file. But it not yet finished.
    This helps the script determine whether the server file is up to date or not. Only then does the script decide whether to download it again.


    EDIT:
    @freddie-o,
    replace from static url:
    Code:
    set "DownloadURI=https://www.sordum.org/files/download/power-run/PowerRun_v1.7.zip"
    
    to dynamic url, like @retest show above:
    Code:
    set "DownloadURI=https://www.sordum.org/files/downloads.php?power-run"
    
     
  13. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,571
    2,615
    60
    Thanks guys. Updated the OP script
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Sum_Ting_Wong

    Sum_Ting_Wong MDL Member

    Jan 30, 2024
    157
    229
    10
    #134 Sum_Ting_Wong, Dec 23, 2024
    Last edited: Dec 27, 2024
    I didn't feel like creating a new thread but wanted to share. Seemed relevant.

    A batch to enable and disable context menu entries for setting the always run as admin flag for exe files.
    Code:
    @echo off
    
    :: The point of this is some .exe files don't let you set compatibility flags, like devenv.exe in VS 2022.
    
    :: Request admin rights if not already running as admin
    >nul 2>&1 reg query "HKU\S-1-5-19\Environment"
    if '%errorlevel%' NEQ '0' (
        (echo.Set UAC = CreateObject^("Shell.Application"^)&echo.UAC.ShellExecute "%~s0", "", "", "runas", 1)>"%tmp%\getadmin.vbs"
        "%tmp%\getadmin.vbs"
        exit /B
    ) else ( >nul 2>&1 del "%tmp%\getadmin.vbs" )
    
    color 0E
    title Make any .exe "run as admin"
    SETLOCAL ENABLEDELAYEDEXPANSION
    
    :: Start
    :main
    call :banner
    echo    Admin Compat Context Menu Option
    echo.
    echo     ^|  1. Enable Menu Option    ^|
    echo     ^|  2. Disable Menu Option   ^|
    echo     ^|  3. Exit           ^|
    echo.
    set /p choice="    Pick one = "
    
    if "%choice%"=="1" goto :enable_menu
    if "%choice%"=="2" goto :disable_menu
    if "%choice%"=="3" goto :exit
    pause
    goto :main
    
    :: Enable
    :enable_menu
    call :banner
    call :add_menu
    if %errorlevel% neq 0 goto :error_enable
    echo.
    echo Menu enabled successfully.
    pause
    goto :main
    
    :: Disable
    :disable_menu
    call :banner
    call :remove_menu
    if %errorlevel% neq 0 goto :error_disable
    echo.
    echo Menu disabled successfully.
    pause
    goto :main
    
    :: Error Handling
    :error_enable
    call :banner
    echo Error enabling menu. Rolling back changes...
    call :remove_menu
    echo.
    pause
    goto :main
    
    :: Error Handling
    :error_disable
    call :banner
    echo Error disabling menu. Failed to remove the following entry:
    reg query "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_EnableAdminCompat"
    reg query "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_DisableAdminCompat"
    echo.
    pause
    goto :main
    
    :add_menu
    reg add "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_EnableAdminCompat" /ve /d "Enable Admin Compatibility" /f
    reg add "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_EnableAdminCompat\command" /ve /d "cmd /c reg add \"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\" /v \"%%1\" /d \"RUNASADMIN\" /f" /f
    reg add "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_DisableAdminCompat" /ve /d "Disable Admin Compatibility" /f
    reg add "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_DisableAdminCompat\command" /ve /d "cmd /c reg delete \"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\" /v \"%%1\" /f" /f
    exit /b %errorlevel%
    
    :remove_menu
    reg delete "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_EnableAdminCompat" /f
    reg delete "HKEY_CURRENT_USER\Software\Classes\exefile\shell\_DisableAdminCompat" /f
    exit /b %errorlevel%
    
    
    :exit
    endlocal
    exit
    
    
    
    :banner
    cls
    echo.
    echo     ___   __   __   ____
    echo       /___ /   \___/   __
    echo   ___/\    Admin   \___/
    echo       /    Context   \ __
    echo    __/\____ Menu _____\
    echo      \  \_  ____/  \_  \
    echo. && echo.
    goto :eof
    
    
    ::githubgist