Here's what I've come up with. After Installing... the script opens PowerRun and notifies you to "Allow Command Line" so the "PowerRun.ini" gets saved there in the System folders
The sec code is unique for each system and each windows installation in a system. PRun saves all sec codes generated. So it is, kind of, portable.
nSudo have problems with latest insider & 24h2 version. so i moved to God-Mode tool. project page. https://github.com/RubisetCie/god-mode
You might need a "if %arch%==x64 ..." for the start PRun commands. Any particular reason you skipped the /wait in the second start? ----- One more suggestion, Since PRun will be available on the users system, add a option for folders to "Open command prompt here as TI". What I use: Code: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Command Prompt here as TI\shell\35Command Prompt here as TI\command] @="\"C:\\Portable Programs\\RunAsTI\\PowerRun64.exe\" cmd.exe /s /k pushd \"%V\" & Title CMD as TI" If the above can be improved : anyone, please comment.
No way for me to test on x86 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) :menu cd /d "%~dp0" if /i "%PROCESSOR_ARCHITECTURE%" equ "amd64" (set "arch=x64") else (set "arch=%PROCESSOR_ARCHITECTURE%") if "%PROCESSOR_ARCHITEW6432%" neq "" if /i "%arch%" neq "x86" if /i "%arch%" neq "x64" start %SystemRoot%\Sysnative\cmd.exe /C "%~dpnx0" %* & exit set "ROOT=%~dp0" set "DownloadFileName=PowerRun.zip" set "DownloadURI=https://www.sordum.org/files/download/power-run/PowerRun.zip" SetLocal EnableExtensions EnableDelayedExpansion echo. echo ____________________________________________________________ echo. echo "Run as TrustedInstaller" from the Context Menu echo ____________________________________________________________ echo. echo. echo [1] Add "Run as TrustedInstaller" to the Context menu echo. echo [2] Remove "Run as TrustedInstaller" from the Context menu echo. echo. echo. [Q] Quit echo. echo. echo ____________________________________________________________ echo. echo. choice /C:12Q /N /M "Enter your choice :" if %errorlevel% equ 3 exit if %errorlevel% equ 2 ( if exist "%SystemROOT%\System32\PowerRun.exe" ( del /q %SystemRoot%\system32\PowerRun.exe >NUL del /q %SystemRoot%\system32\PowerRun.ini >NUL if not %arch%==x86 if not %arch%==arm del /q %SystemRoot%\SysWOW64\PowerRun.exe >NUL del /q %SystemRoot%\SysWOW64\PowerRun.ini >NUL reg delete "HKCR\batfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\cmdfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\cplfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\exefile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\Microsoft.PowerShellScript.1\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\mscfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\regfile\shell\Run as TrustedInstaller" /f >nul 2>&1 cls echo. echo.Successfully uninstalled PowerRun and removed "Run as TrustedInstaller" from the Context menu. ) else ( cls echo. echo.PowerRun has already been removed. ) ) if %errorlevel% equ 1 ( if not exist "%SystemROOT%\System32\PowerRun.exe" ( @start "Downloading !DownloadFileName! file..." /wait /B powershell -c "(New-Object System.Net.WebClient).DownloadFile('!DownloadURI!', '%ROOT%\!DownloadFileName!')" if exist "%ROOT%\!DownloadFileName!" @start "Expanding !DownloadFileName! file..." /wait /B powershell -c "Expand-Archive -Force '%ROOT%\!DownloadFileName!' '%ROOT%'" if exist "PowerRun\PowerRun.exe" ( if %arch%==x64 ( copy PowerRun\PowerRun_x64.exe %SystemRoot%\system32\PowerRun.exe /y >NUL copy PowerRun\PowerRun.exe %SystemRoot%\SysWOW64\PowerRun.exe /y >NUL ) else ( copy PowerRun\PowerRun.exe %SystemRoot%\system32\PowerRun.exe /y >NUL ) reg add "HKCR\batfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\batfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\cmdfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\cmdfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\cplfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\cplfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\exefile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\exefile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\Microsoft.PowerShellScript.1\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\Microsoft.PowerShellScript.1\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\mscfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\mscfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\regfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\regfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 msg Console "PowerRun windows(s) will now open. Click on the 'File' menu and 'Allow Command Line' to disable the Cmd parameter restriction." if %arch%==x64 ( start "" /wait %SystemRoot%\system32\PowerRun.exe start "" /wait %SystemRoot%\SysWOW64\PowerRun.exe ) else ( start "" /wait %SystemRoot%\system32\PowerRun.exe ) cls echo. echo.Successfully installed PowerRun and added "Run as TrustedInstaller" to the Context menu. ) rmdir /q /s "PowerRun" >nul del /q /f "!DownloadFileName!" >nul ) else ( echo. echo.PowerRun is already installed. ) ) echo. echo Press any key to go to the Main menu... pause >nul cls goto menu
It will patch only the PowerRun that was opened. This is why the bellow method is effective. It will place the patched .ini in both Sustem32 and SysWOW64 folders. There are no need to execute for specified PowerRun arch. Just open the x86 before copy .exe and .ini to system32. The same ini will be used for any arch. Then you can start PowerRun after it is extracted to the ROOT folder. Then the .ini patched by PowerRun will be placed correctly. So the suggested adjustments to the code should be: 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) :menu cd /d "%~dp0" if /i "%PROCESSOR_ARCHITECTURE%" equ "amd64" (set "arch=x64") else (set "arch=%PROCESSOR_ARCHITECTURE%") if "%PROCESSOR_ARCHITEW6432%" neq "" if /i "%arch%" neq "x86" if /i "%arch%" neq "x64" start %SystemRoot%\Sysnative\cmd.exe /C "%~dpnx0" %* & exit set "ROOT=%~dp0" set "DownloadFileName=PowerRun.zip" set "DownloadURI=https://www.sordum.org/files/download/power-run/PowerRun.zip" SetLocal EnableExtensions EnableDelayedExpansion echo. echo ____________________________________________________________ echo. echo "Run as TrustedInstaller" from the Context Menu echo ____________________________________________________________ echo. echo. echo [1] Add "Run as TrustedInstaller" to the Context menu echo. echo [2] Remove "Run as TrustedInstaller" from the Context menu echo. echo. echo. [Q] Quit echo. echo. echo ____________________________________________________________ echo. echo. choice /C:12Q /N /M "Enter your choice :" if %errorlevel% equ 3 exit if %errorlevel% equ 2 ( if exist "%SystemROOT%\System32\PowerRun.exe" ( del /q %SystemRoot%\System32\PowerRun.exe >NUL del /q %SystemRoot%\System32\PowerRun.ini >NUL if not %arch%==x86 if not %arch%==arm ( del /q %SystemRoot%\SysWOW64\PowerRun.exe >NUL del /q %SystemRoot%\SysWOW64\PowerRun.ini >NUL ) reg delete "HKCR\batfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\cmdfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\cplfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\exefile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\Microsoft.PowerShellScript.1\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\mscfile\shell\Run as TrustedInstaller" /f >nul 2>&1 reg delete "HKCR\regfile\shell\Run as TrustedInstaller" /f >nul 2>&1 cls echo. echo.Successfully uninstalled PowerRun and removed "Run as TrustedInstaller" from the Context menu. ) else ( cls echo. echo.PowerRun has already been removed. ) ) if %errorlevel% equ 1 ( if not exist "%SystemROOT%\System32\PowerRun.exe" ( @start "Downloading !DownloadFileName! file..." /wait /B powershell -c "(New-Object System.Net.WebClient).DownloadFile('!DownloadURI!', '%ROOT%\!DownloadFileName!')" if exist "%ROOT%\!DownloadFileName!" @start "Expanding !DownloadFileName! file..." /wait /B powershell -c "Expand-Archive -Force '%ROOT%\!DownloadFileName!' '%ROOT%'" if exist "PowerRun\PowerRun.exe" ( msg Console "PowerRun windows(s) will now open. Click on the 'File' menu and 'Allow Command Line' to disable the Cmd parameter restriction." start "" /wait /i "%ROOT%\PowerRun\PowerRun.exe" if not %arch%==x64 if not %arch%==arm64 ( copy PowerRun\PowerRun.exe "%SystemRoot%\System32\PowerRun.exe" /y >NUL ) if not %arch%==x86 if not %arch%==arm ( copy PowerRun\PowerRun.exe "%SystemRoot%\SysWOW64\PowerRun.exe" /y >NUL copy PowerRun\PowerRun_x64.exe "%SystemRoot%\System32\PowerRun.exe" /y >NUL copy PowerRun\PowerRun.ini "%SystemRoot%\SysWOW64\PowerRun.ini" /y >NUL ) copy PowerRun\PowerRun.ini "%SystemRoot%\System32\PowerRun.ini" /y >NUL reg add "HKCR\batfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\batfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\cmdfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\cmdfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\cplfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\cplfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\exefile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\exefile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\Microsoft.PowerShellScript.1\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\Microsoft.PowerShellScript.1\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\mscfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\mscfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 reg add "HKCR\regfile\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe" /f >NUL reg add "HKCR\regfile\shell\Run as TrustedInstaller\command" /v "" /t REG_EXPAND_SZ /d "cmd.exe /X /D /U /R for %%%%# in (\"%%1\") do PowerRun.exe \"/WD:%%%%~dp#\" \"%%1\"" /f >nul 2>&1 cls echo. echo.Successfully installed PowerRun and added "Run as TrustedInstaller" to the Context menu. ) rmdir /q /s "PowerRun" >NUL del /q /f "!DownloadFileName!" >NUL ) else ( echo. echo.PowerRun is already installed. ) ) echo. echo Press any key to go to the Main menu... pause >nul cls goto menu
Has already died with the advent of Win11. Server-side, it's dead for years and already smelling bad. x86 has a historical problem, though. Tons and tons of software, either totally or partially 32bit. Many installers are, too. And who knows what else and where else 32bit code is still used in Windows. At least WoW64 will be with us for the foreseeable future. We managed to finally get rid of 16bit code, though.
Thanks for cleaning up the script My script opens PowerRun in both System32 and SysWOW64 folders so the INI is saved there. Same results But I agree that patching the INI before copying the PowerRun files in System32 and SysWOW64 folders is cleaner and less to do. I'll add the script to the OP
If you look at the download scheme I made in my script, it is only to check if the zip file present (already downloaded) is the same as the one on the server. If the dates are different, we know that there is a new version of PowerRun, so it downloads the new version. Is it possible to improve this system to remove the old version, in case a new download occurs due to the presence of a new version of PowerRun on the server. So, user don't need to uninstall and then reinstall in the case of new version. What do you think about this? EDIT: You told me that you dont have enabled BITS. So, nevermind.
Does this work for you? Would be great to have a working script And add it to Code: HKCR\Directory\shell HKCR\Directory\background\shell HKCR\Drive\shell So the command prompt is accessible everywhere
Yes, it works. You will have to convert the reg code to bat code. Should be easy. I use AutoIt so I cannot post the code. This is the entire reg key, you will have to modify it a bit. Same code for Drive & Background. Code: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Command Prompt here as TI\shell\35Command Prompt here as TI] @="use PowerRun" "MUIVerb"="use PowerRun" "Icon"="\"C:\\Portable Programs\\RunAsTI\\PowerRun64.exe\", 0" [HKEY_CLASSES_ROOT\Directory\shell\Command Prompt here as TI\shell\35Command Prompt here as TI\command] @="\"C:\\Portable Programs\\RunAsTI\\PowerRun64.exe\" cmd.exe /s /k pushd \"%V\" & Title CMD as TI" using RegConverter https://www.sordum.org/8478/reg-converter-v1-2/ : Code: Title Reg Converter v1.2 & Color 1A Reg.exe add "HKCR\Directory\shell\Command Prompt here as TI\shell\35Command Prompt here as TI" /ve /t REG_SZ /d "use PowerRun" /f Reg.exe add "HKCR\Directory\shell\Command Prompt here as TI\shell\35Command Prompt here as TI" /v "MUIVerb" /t REG_SZ /d "use PowerRun" /f Reg.exe add "HKCR\Directory\shell\Command Prompt here as TI\shell\35Command Prompt here as TI" /v "Icon" /t REG_SZ /d "\"C:\Portable Programs\RunAsTI\PowerRun64.exe\", 0" /f Reg.exe add "HKCR\Directory\shell\Command Prompt here as TI\shell\35Command Prompt here as TI\command" /ve /t REG_SZ /d "\"C:\Portable Programs\RunAsTI\PowerRun64.exe\" cmd.exe /s /k pushd \"%%V\" & Title CMD as TI" /f Exit EDIT : I got it from here : https://github.com/mspaintmsi/superUser/issues/12
Open command window as TrustedInstaller here FIXED https://forums.mydigitallife.net/th...r-from-context-menu.80713/page-8#post-1846386
BTW: Instead of explicit Reg-Keys i use: 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 The \*\shell will install to all keys with \shell REG_EXPAND_SZ is found, can't remember where ...
I have a nifty tool from @wtarkan that converts REG >> CMD. I use it for picky Reg strings -- export it as REG directly -- convert and check CMD, it will show, how it should look. #NIFTY
@freddie-o There is a difference between my code and yours. With my code if I right-click folder 'C:\Portable Programs\Notepad2' and click 'open command prompt here as ti", the command window is opened and CDed to 'C:\Portable Programs\Notepad2'. So I can run notepad2.exe from the command window without having to manually CD to 'C:\Portable Programs\Notepad2'. That's why the menu item has a "here". With your code the command window will open at system32, I think.