Don't get mad, man! The point here was not even this bunch of redundancies that I put. You can see that in the template I sent, related to the script that freddie-o sent, I didn't even put the "getrights" full of redundancies. One detail: I said I described it "with tips by AveYo". :::: 1. Run as Admin with PowerShell, any path, params, loop guard, minimal i/o, tips by AveYo :::: 2. Run as Admin with native shell, any path, params, loop guard, minimal i/o, tips by AveYo As I changed some details, I thought it was necessary to leave something related to the source, which are the hints and clues left by your code. You said that when it is changed, it is no longer what you did, but it is still based on what you shared. People get credit for starting things. I like to do identation. I don't really like adding "&" characters to keep everything on the same line. Regarding what you said, about the order, I read it there in the other topic. I tried to do it, but as I said here, if you leave the method by PowerShell positioned at the end, it doesn't work. I couldn't. But the way I put it, you can negate that it moves on to the next one. Indicating that if there is an error, it will try the next one, and so on. Regarding the note on running as admin, it is in the menu. Option for the user. Continue by clicking on A or run the script directly as admin.
I think putting the full path should fix it. But it should work as it was before. from Code: reg.exe add "HKCR\*\shell\Run as TrustedInstaller\command" /v "" /t REG_SZ /d "PowerRun.exe \"%%1\"" /f >NUL to Code: reg.exe add "HKCR\*\shell\Run as TrustedInstaller\command" /v "" /t REG_SZ /d "%SystemROOT%\System32\PowerRun.exe \"%%1\"" /f >NUL But here it is working without the full path and with the full path. Script with registry entries have been applied correctly. I tested it now.
Still throws the same errors This is getting tricky I tried working from "C:\Program Files\PowerRun" instead and it works The thing is it only happens with this one script of mine that imports reg files Same error happened with NSudo
Can you attach the script removing sensitive data from it? I once had a lot of problems with script execution, and it was related to a registry tweak.
A very simple script Code: @echo off REG IMPORT AddAppsAndScriptsToContextMenu.reg REG IMPORT AddRibbonToContextMenu.reg REG IMPORT CleanUpContextMenu.reg REG IMPORT ProcessExplorer.reg REG IMPORT ThisAndThat.reg pause
for now, just add cd /d "%~dp0" Code: @echo off cd /d "%~dp0" REG IMPORT "shell ContextMenu.reg" REG IMPORT AddRibbonToContextMenu.reg REG IMPORT "Vertical_Volume_Control.reg" REG IMPORT ProcessExplorer.reg REG IMPORT ThisAndThat.reg pause Code: A operação foi concluída com êxito. ERRO: Erro ao abrir o arquivo. Pode haver um erro de disco ou de sistema de arquivos. A operação foi concluída com êxito. ERRO: Erro ao abrir o arquivo. Pode haver um erro de disco ou de sistema de arquivos. ERRO: Erro ao abrir o arquivo. Pode haver um erro de disco ou de sistema de arquivos. Pressione qualquer tecla para continuar. . . The errors refer to missing files.
It works. Funny I didn't think of that I made slight modifications and correction to your script and will add it to the OP
You can make Reg file's, compress them to .Zip file. Add them as attachment to main post. what more easy than that ?
@freddie-o, A solution to that problem of the import *.reg file script. Selecting the install option, the script automatically downloads, extracts and installs. Atached below! EDIT: "import file import script" to "import *.reg file script"
this is a very good replacement I do 2 things I never want one. only one approach, I try to build everything myself # I understand your code add your to my fav sorry mein enlish is bad france to big, have a nice time
Just replace from: Code: @start "Downloading !DownloadFileName! file..." /wait /B PowerShell.exe -Command Start-BitsTransfer -Source "!DownloadURI!" -Destination "%ROOT%\!DownloadFileName!" to: Code: @start "Downloading !DownloadFileName! file..." /wait /B PowerShell.exe -Command "(New-Object System.Net.WebClient).DownloadFile('!DownloadURI!', '%ROOT%\!DownloadFileName!')"
What about this? 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 if not %arch%==x86 if not %arch%==arm del /q %SystemRoot%\SysWOW64\PowerRun.exe >NUL reg delete "HKCR\*\shell\Run as TrustedInstaller" /f >NUL echo. echo.Successfully uninstalled PowerRun and removed "Run as TrustedInstaller" from the Context menu. ) else ( 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\*\shell\Run as TrustedInstaller" >NUL reg add "HKCR\*\shell\Run as TrustedInstaller" /v "Icon" /t REG_SZ /d "imageres.dll,1" /f >NUL reg add "HKCR\*\shell\Run as TrustedInstaller\command" /v "" /t REG_SZ /d "PowerRun.exe \"%%1\"" /f >NUL echo. echo.Successfully installed PowerRun and added "Run as TrustedInstaller" to the Context menu. ) rmdir /q /s "PowerRun" >nul del /q /s "!DownloadFileName!" >nul ) else ( echo. echo.PowerRun is already installed. ) ) echo. echo Press any key to make another choice... pause >nul cls goto menu
del /f /q I hadn't even noticed it, but you don't even need this line. The other commands will already create this key. I put a condition for use with bits if it is present because it preserves "Date Time File Stamp". Code: sc.exe query "BITS" | findstr /I "RUNNING" >nul && ( :: Preserves Remote Time File Stamp start "Downloading !DownloadFileName! file..." /wait /B PowerShell.exe -Command Start-BitsTransfer -Source "!DownloadURI!" -Destination "%ROOT%\!DownloadFileName!" ) || ( start "Downloading !DownloadFileName! file..." /wait /B PowerShell.exe -Command "(New-Object System.Net.WebClient).DownloadFile('!DownloadURI!', '%ROOT%\!DownloadFileName!')" )
sc.exe query "BITS" | findstr /I "RUNNING" --- Not a good check. in my case. -> STATE : 1 STOPPED but it not disabled. I can use it Any time. Code: C:\Users\Admin>sc.exe query "BITS" SERVICE_NAME: BITS TYPE : 20 WIN32_SHARE_PROCESS STATE : 1 STOPPED WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 this will be a better check. Code: >nul 2>nul reg query HKLM\SYSTEM\CurrentControlSet\Services\BITS || echo Bits not found 2>nul reg query HKLM\SYSTEM\CurrentControlSet\Services\BITS | find /i "Start" | >nul find /i "0x4" && echo Bits not found
Yes, it is a good check. Because it is the Default. I have no way of knowing about the modifications that users make. If it's "automatic", I don't know if it will work, I think it should work. But when in doubt, if it is not "running" the download will be made by the other command. We have the "else" in case it is not in standard "RUNNING" mode. ") || ("
I know for sure, it will work. it will fail only if you disable it. [Start = 0x4] Code: Automatic 0X2 Manual 0x3 Disabled 0x4