Urik_Kane

open_with_avidemux_registry_win64_add

Dec 2nd, 2019 (edited)
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.78 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. title Add/Update Avidemux in registry
  4.  
  5. :check_elevation
  6. net session >nul 2>&1
  7. if not %errorlevel%==0 echo   & echo Error: Must run as administrator. & pause>nul & goto :eof
  8.  
  9. set executables=avidemux.exe,avidemux_portable.exe
  10. set foundcount=0
  11.  
  12. :: search in C:\Program Files
  13. cd /d %programfiles%
  14. for /d %%F in (*avidemux*) do ( for %%X in (%executables%) do ( if exist "%%~F\%%~X" ( CALL :LogFoundFolder "%programfiles%\%%~F\%%~X")))
  15.  
  16. :: search in the same folder the script is located in
  17. cd /d "%~dp0"
  18. for %%X in (%executables%) do ( if exist "%~dp0%%~X" ( cd..\.. & CALL :LogFoundFolder "%~dp0%%~X"))
  19.  
  20.  
  21. if !foundcount!==0 echo Could not auto-find any installations. & goto :hintcustomfolder
  22. if !foundcount!==1 goto :ConfirmFolder
  23. FOR /L %%F IN (1,1,%foundcount%) DO ( if ""!folderidlist!=="" ( set folderidlist=%%F) else ( set folderidlist=!folderidlist!,%%F))
  24.  
  25.  
  26. :SelectFoundFolder
  27. echo.
  28. echo please choose folder ^( !folderidlist! or custom^)
  29. FOR /L %%F IN (1,1,%foundcount%) DO ( echo  %%F     !foundpath%%F!)
  30. echo.
  31. set folderid=
  32. set /p folderid="enter number !folderidlist! or word ^"custom^"   = "
  33. if not "!folderid!"=="" (
  34.     set "folderid=!folderid: =!"
  35.     for %%A in (!folderid!) do ( if /i "%%~A"=="custom" goto :hintcustomfolder)
  36.     for /f "delims=1234567890" %%A in ('echo !folderid!') do echo ERROR: !folderid! - only numbers are allowed^^! & goto :SelectFoundFolder
  37.     for %%A in (%folderidlist%) do if "!folderid!"=="%%A" (
  38.         set "installpath=!foundpath%%A!"
  39.         echo. & echo Selected folder: !installpath!
  40.         goto :SetKeys
  41.     )
  42.     echo ERROR: !folderid! is NOT a valid option^^!
  43. )
  44. goto :SelectFoundFolder
  45.  
  46. :hintcustomfolder
  47. echo.
  48. echo Please enter Avidemux folder
  49. echo.
  50. :AskCustomFolder
  51. set installpath=
  52. set /p installpath="Enter Avidemux folder "
  53. for %%P in (%installpath%) do goto :next
  54. goto :AskCustomFolder
  55. :next
  56. set installpath=%installpath:"=%
  57. if "%installpath:~-1%"=="\" set "installpath=%installpath:~0,-1%"
  58. if "%installpath:~-1%"=="/" set "installpath=%installpath:~0,-1%"
  59. for %%P in (%installpath%) do (
  60.     if exist "%installpath%" (
  61.         if not "%%~xP"=="" ( for %%X in (%executables%) do ( if /i "%%~nxP"=="%%~X" CALL :SetCustomFolder "%installpath%" & goto :ConfirmFolder))
  62.         for %%X in (%executables%) do ( if exist "%installpath%\%%~X" ( CALL :SetCustomFolder "%installpath%\%%~X" & goto :ConfirmFolder))
  63.     )
  64. )
  65. echo  & echo Error^: Could not find installation in provided folder. & echo. & goto :AskCustomFolder
  66.  
  67. :SetKeys
  68. reg query "HKCR\Applications\avidemux.exe\shell\open\command">nul 2>&1 || ( echo Could not find registry key. Create one? & pause)
  69. reg add "HKCR\Applications\avidemux.exe\shell\open\command" /f /v "" /t REG_SZ /d "\"%installpath%\" \"%%1\""
  70.  
  71. :: results
  72. echo.
  73. echo -------------------------------------------------------
  74. if !errorlevel!==0 ( echo  Succesfully changed value & CALL :OpenKey) else ( echo  Failed to change value)
  75. echo -------------------------------------------------------
  76. echo.
  77. pause & goto :eof
  78.  
  79. :OpenKey
  80. REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey" /d "HKCR\Applications\avidemux.exe\shell\open\command" /f>nul 2>&1
  81. start /b regedit
  82. goto :eof
  83.  
  84. :LogFoundFolder
  85. set /a foundcount=!foundcount!+1
  86. echo.
  87. echo Avidemux installation found: "%~1"
  88. set "foundpath!foundcount!=%~1"
  89. goto :eof
  90.  
  91. :SetCustomFolder
  92. echo.
  93. echo Avidemux custom installation: "%~1" & echo.
  94. set "foundpath1=%~1"
  95. goto :eof
  96.  
  97. :ConfirmFolder
  98. set proceed=
  99. set /p "proceed=Use this installation (Y/N)?"
  100. if not "!proceed!"=="" (
  101.     set "proceed=!proceed: =!"
  102.     for /f "delims=yYnN" %%A in ('echo !proceed!') do goto :ConfirmFolder
  103. )
  104. if /i !proceed!==y ( set "installpath=%foundpath1%" & goto :SetKeys)
  105. if /i !proceed!==n ( echo. & goto :hintcustomfolder)
  106. goto :ConfirmFolder
Add Comment
Please, Sign In to add comment