"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,740
    3,068
    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,740
    3,068
    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,770
    3,601
    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
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,740
    3,068
    60
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. inTerActionVRI

    inTerActionVRI MDL Expert

    Sep 23, 2009
    1,770
    3,601
    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"
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,740
    3,068
    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,770
    3,601
    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"
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,740
    3,068
    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
    165
    239
    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
     
  15. betakernel

    betakernel MDL Novice

    Nov 29, 2017
    38
    11
    0
    #135 betakernel, Dec 3, 2025
    Last edited: Dec 3, 2025
    I used the project https://github.com/mspaintmsi/superUser to create a batch script to handle the following:
    1. Right-click and use TrustedInstaller permissions to open CMD in this directory
    2. Right-click and use TrustedInstaller permissions to open Powershell in this directory
    3. Select a folder, then right-click and choose TrustedInstaller permissions to open this folder

    I am a CN (Chinese) user, so the script uses Chinese comments and a Chinese menu.

    Place the batch script and the executable from the superUser project in the same directory, then just run the batch script.


    Code:
    @ECHO OFF
    PUSHD %~dp0
    TITLE Hello World
    >nul reg add hkcu\software\classes\.Admin\shell\runas\command /f /ve /d "cmd /x /d /r set \"f0=%%2\" &call \"%%2\" %%3" & set "_= %*"
    >nul fltmc || if "%f0%" neq "%~f0" ( cd.>"%tmp%\runas.Admin" & start "%~n0" /high "%tmp%\runas.Admin" "%~f0" "%_:"=""%" &exit /b )
    cd /d "%~dp0"
    if "%PROCESSOR_ARCHITECTURE%"=="x86" set bits=32
    if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set bits=64
    REM Check command line arguments
    if "%~1"=="install" (
        goto install
    )
    if "%~1"=="uninstall" (
        goto uninstall
    )
    Rem Set program path
    SET "_file_name=%~dp0superUser%bits%.exe"
    SET "_file_path=%~dp0"
    Rem Set names - Open CMD or PS as TrustedInstaller here
    SET "_Open_CMD=Open CMD Here as TrustedInstaller (AsSuperUser)"
    SET "_Open_PowerShell=Open PowerShell Here as TrustedInstaller (AsSuperUser)"
    Rem Set names - Run as TrustedInstaller
    SET "_Run_SuperUser=Run as TrustedInstaller (AsSuperUser)"
    Rem Set names - Import as TrustedInstaller
    SET "_Import_SuperUser=Import as TrustedInstaller (AsSuperUser)"
    Rem Set names - Open directory as TrustedInstaller
    SET "_Open_SuperUser=Open Directory as TrustedInstaller (AsSuperUser)"
    Rem Set command lines
    SET "_cmd_cmd=CMD.exe /S /K pushd \"%%V\"&Title CMD TrustedInstaller"
    SET "_cmd_powershell=powershell.exe -noexit -command Set-Location -lit '%%V';$Host.UI.RawUI.WindowTitle = 'TrustedInstaller: Windows Powershell'"
    ::Not escaped: SET _open_Directory=/m CMD.exe /S /K "pushd "%V" &reg delete "HKCR\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}" /v "RunAs" /f &explorer "%V" &reg add "HKCR\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}" /v "RunAs" /t REG_SZ /d "Interactive User" /f &exit"
    ::SET "_open_Directory=CMD.exe /S /K pushd \"%%V\" ^&reg delete \"HKCR\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}\" /v \"RunAs\" /f ^&explorer \"%%V\" ^&reg add \"HKCR\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}\" /v \"RunAs\" /t REG_SZ /d \"Interactive User\" /f ^&exit"
    SET "_open_Directory=/m CMD.exe /S /K pushd \"%%V\" &reg delete \"HKCR\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}\" /v \"RunAs\" /f &explorer \"%%V\" &reg add \"HKCR\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}\" /v \"RunAs\" /t REG_SZ /d \"Interactive User\" /f &exit"
    Rem Set icons
    SET "_iconcmd=cmd.exe"
    SET "_iconps=powershell.exe"
    Rem Set registry keys - Open CMD/PS as TrustedInstaller here
    SET "_regkey1=HKCR\Folder\shell\OpenCmdAsSuperUser"
    SET "_regkey2=HKCR\Directory\shell\OpenCmdAsSuperUser"
    SET "_regkey3=HKCR\Directory\Background\shell\OpenCmdAsSuperUser"
    SET "_regkey4=HKCR\Drive\shell\OpenCmdAsSuperUser"
    SET "_regkey5=HKCR\Drive\Background\shell\OpenCmdAsSuperUser"
    SET "_regkey6=HKCR\LibraryFolder\Background\shell\OpenCmdAsSuperUser"
    SET "_regkey7=HKCR\Folder\shell\OpenPowerShellAsSuperUser"
    SET "_regkey8=HKCR\Directory\shell\OpenPowerShellAsSuperUser"
    SET "_regkey9=HKCR\Directory\Background\shell\OpenPowerShellAsSuperUser"
    SET "_regkey10=HKCR\Drive\shell\OpenPowerShellAsSuperUser"
    SET "_regkey11=HKCR\Drive\Background\shell\OpenPowerShellAsSuperUser"
    SET "_regkey12=HKCR\LibraryFolder\Background\shell\OpenPowerShellAsSuperUser"
    Rem Set registry keys - Run/Import as TrustedInstaller
    SET "_regkey21=HKCR\exefile\shell\runasSuperUser"
    SET "_regkey22=HKCR\cmdfile\shell\runasSuperUser"
    SET "_regkey23=HKCR\batfile\shell\runasSuperUser"
    SET "_regkey24=HKCR\mscfile\shell\runasSuperUser"
    SET "_regkey25=HKCR\Microsoft.PowerShellScript.1\shell\runasSuperUser"
    SET "_regkey26=HKCR\regfile\shell\runasSuperUser"
    Rem Set registry keys - Open directory as TrustedInstaller
    SET "_regkey31=HKCR\Directory\shell\OpenAsTIAsSuperUser"
    SET "_regkey32=HKCR\Drive\shell\OpenAsTIAsSuperUser"
    :Menu
    SET Options=
    ECHO.&ECHO. 1. Install SuperUser right-click menu
    ECHO.&ECHO. 2. Uninstall SuperUser right-click menu
    ECHO.&ECHO. 3. Exit
    ECHO.
    SET /P Options=[92mPlease enter your choice and press Enter: [0m
    IF /I "%Options%"=="1" GOTO install
    IF /I "%Options%"=="2" GOTO uninstall
    IF /I "%Options%"=="3" GOTO OUT
    ECHO.&ECHO. Invalid choice, please try again!
    PING -n 2 127.1>NUL
    CLS
    GOTO Menu
    :install
    REM Remove leftover registry entries
    for %%i in (%_regkey1% %_regkey2% %_regkey3% %_regkey4% %_regkey5% %_regkey6% %_regkey7% %_regkey8% %_regkey9% %_regkey10% %_regkey11% %_regkey12% %_regkey21% %_regkey22% %_regkey23% %_regkey24% %_regkey25% %_regkey26% %_regkey31% %_regkey32%) do reg delete %%i /f
    Rem Open CMD Here as TrustedInstaller (SuperUser)
    for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%" "%_regkey5%" "%_regkey6%") do (
        Reg.exe add %%k /ve /t REG_SZ /d "%_Open_CMD%" /f
        Reg.exe add %%k /v "HasLUAShield" /t REG_SZ /d "" /f
        Reg.exe add %%k /v "Position" /t REG_SZ /d "Bottom" /f
        Reg.exe add %%k /v "Icon" /t REG_SZ /d "%_iconcmd%" /f
        Reg.exe add "%%k\Command" /ve /t REG_SZ /d "\"%_file_name%\" %_cmd_cmd%" /f
    )
    Rem Open PowerShell Here as TrustedInstaller (SuperUser)
    for %%k in ("%_regkey8%" "%_regkey9%" "%_regkey10%" "%_regkey11%" "%_regkey12%") do (
        Reg.exe add %%k /ve /t REG_SZ /d "%_Open_PowerShell%" /f
        Reg.exe add %%k /v "HasLUAShield" /t REG_SZ /d "" /f
        Reg.exe add %%k /v "Position" /t REG_SZ /d "Bottom" /f
        Reg.exe add %%k /v "Icon" /t REG_SZ /d "%_iconps%" /f
        Reg.exe add "%%k\Command" /ve /t REG_SZ /d "\"%_file_name%\" %_cmd_powershell%" /f
    )
    Rem Run as TrustedInstaller
    :: Process exefile, cmdfile, batfile, mscfile, Microsoft.PowerShellScript.1
    for %%k in ("%_regkey21%" "%_regkey22%" "%_regkey23%" "%_regkey24%") do (
        Reg.exe add %%k /ve /t REG_SZ /d "%_Run_SuperUser%" /f
        Reg.exe add %%k /v "MultiSelectModel" /t REG_SZ /d "Single" /f
        Reg.exe add %%k /v "HasLUAShield" /t REG_SZ /d "" /f
        Reg.exe add "%%k\command" /ve /t REG_SZ /d "\"%_file_name%\" \"%%1\"" /f
    )
    Rem Import registry as TrustedInstaller
    Reg.exe add "%_regkey26%" /ve /t REG_SZ /d "%_Import_SuperUser%" /f
    Reg.exe add "%_regkey26%" /v "MultiSelectModel" /t REG_SZ /d "Single" /f
    Reg.exe add "%_regkey26%" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "%_regkey26%\command" /ve /t REG_SZ /d "\"%_file_name%\" regedit /s \"%%L\"" /f
    Rem Open Directory as TrustedInstaller (SuperUser)
    for %%k in ("%_regkey31%" "%_regkey32%") do (
        Reg.exe add %%k /ve /t REG_SZ /d "%_Open_SuperUser%" /f
        Reg.exe add %%k /v "HasLUAShield" /t REG_SZ /d "" /f
        Reg.exe add %%k /v "Position" /t REG_SZ /d "Top" /f
        Reg.exe add %%k /v "Icon" /t REG_SZ /d "SHELL32.dll,077" /f
        Reg.exe add %%k /v "AppliesTo" /t REG_SZ /d "NOT System.ParsingName:=\"::{645FF040-5081-101B-9F08-00AA002F954E}\"" /f
        Reg.exe add %%k /v "SeparatorBefore" /t REG_SZ /d "" /f
        Reg.exe add %%k /v "SeparatorAfter" /t REG_SZ /d "" /f
        Reg.exe add "%%k\Command" /ve /t REG_SZ /d "\"%_file_name%\" %_open_Directory%" /f
    )
    REM Add exclusion for SuperUser folder in Controlled Folder Access
    powershell -inputformat none -outputformat none -NonInteractive -Command "Add-MpPreference -ControlledFolderAccessAllowedApplications '%~dp0superUser32.exe'"
    powershell -inputformat none -outputformat none -NonInteractive -Command "Add-MpPreference -ControlledFolderAccessAllowedApplications '%~dp0superUser64.exe'"
    exit
    :uninstall
    REM Remove leftover registry entries
    for %%i in (%_regkey1% %_regkey2% %_regkey3% %_regkey4% %_regkey5% %_regkey6% %_regkey7% %_regkey8% %_regkey9% %_regkey10% %_regkey11% %_regkey12% %_regkey21% %_regkey22% %_regkey23% %_regkey24% %_regkey25% %_regkey26% %_regkey31% %_regkey32%) do reg delete %%i /f
    REM Remove exclusion for SuperUser folder in Controlled Folder Access
    powershell -inputformat none -outputformat none -NonInteractive -Command "Remove-MpPreference -ControlledFolderAccessAllowedApplications '%~dp0superUser32.exe'"
    powershell -inputformat none -outputformat none -NonInteractive -Command "Remove-MpPreference -ControlledFolderAccessAllowedApplications '%~dp0superUser64.exe'"
    exit
    :OUT
    exit
    
     
  16. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,740
    3,068
    60

    Hi. MDL is an English Forum
    Otherwise only a very small percent of members can understand/use your script
    Also, why not create a dedicated Thread for your script so you can manage it better
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. betakernel

    betakernel MDL Novice

    Nov 29, 2017
    38
    11
    0
    TKS ,I have already translated it into English.
     
  18. alanfox2000

    alanfox2000 MDL Member

    Dec 25, 2015
    169
    401
    10
  19. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,740
    3,068
    60
    Why not start a SendToTI thread
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...