Skip to content

Instantly share code, notes, and snippets.

@AnubyteCode
Last active July 3, 2024 08:08
Show Gist options
  • Save AnubyteCode/4441a18b44be9a19c418cc7271e30ac1 to your computer and use it in GitHub Desktop.
Save AnubyteCode/4441a18b44be9a19c418cc7271e30ac1 to your computer and use it in GitHub Desktop.
YourMUM.bat
:: YourMUM.bat v0.9 - Installer for .mum files, for online or offline images.
:: Handles folders with and without update.mum, giving choice to only use or ignore update.mum.
:: Handles the process of mounting, saving, discarding, or leaving as-is a mounted image
@echo off
setlocal enabledelayedexpansion
:: 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" )
Title .mum installer
color 0E
:menu
:: Erase all variables set using blank /set commands, except %mounted%
set choice=
set errorlevel=
set installTarget=
set targetChoice=
set offlineLocation=
set offlineDir=
set wimFile=
set mountLocation=
set mumDir=
set upmumpath=
set updateChoice=
set handling=
:: Starting...
call :banner
echo Please select an option:
echo 1. Install .mum files from a directory
echo 2. Install registry entries for .mum files
echo 3. Uninstall registry entries for .mum files
echo 4. Exit
echo.
set /p choice="Enter your choice: "
if "%choice%"=="1" goto :chooseInstallationTarget
if "%choice%"=="2" goto :installRegistryEntries
if "%choice%"=="3" goto :uninstallRegistryEntries
if "%choice%"=="4" goto :exit
echo Invalid choice. Please try again.
timeout /t 3 /nobreak >nul
goto :menu
:installRegistryEntries
call :banner
reg add "HKEY_CLASSES_ROOT\SystemFileAssociations\.mum\shell\RunAs" /ve /d "Install with DISM" /f
reg add "HKEY_CLASSES_ROOT\SystemFileAssociations\.mum\shell\RunAs" /v "HasLUAShield" /t REG_SZ /d "" /f
reg add "HKEY_CLASSES_ROOT\SystemFileAssociations\.mum\shell\RunAs\command" /ve /d "cmd /k dism /online /add-package /packagepath:\"%%1\"" /f
echo Registry entries for .mum files installed.
timeout /t 3 /nobreak >nul
goto :menu
:uninstallRegistryEntries
call :banner
reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.mum\shell\RunAs" /f
echo Registry entries for .mum files uninstalled.
timeout /t 3 /nobreak >nul
goto :menu
:chooseInstallationTarget
call :banner
echo Please select an installation target:
echo 1. Current installation
echo 2. Offline image or installation
echo.
set /p targetChoice="Enter your choice: "
if "%targetChoice%"=="1" (
set installTarget=current
goto :chooseDirectory
)
if "%targetChoice%"=="2" (
goto :chooseOfflineLocation
)
echo Invalid choice. Please try again.
timeout /t 3 /nobreak >nul
goto :chooseInstallationTarget
:chooseOfflineLocation
call :banner
echo Specify the location of the offline files,
echo or type "none" if there are currently none:
set /p offlineLocation="Location: "
if "%offlineLocation%"=="none" (
set mounted=yes
goto :chooseWimFile
) else (
set mounted=
set offlineDir=%offlineLocation%
goto :chooseDirectory
)
:chooseWimFile
call :banner
echo Please specify the location of the .wim file:
set /p wimFile="Location: "
if not exist "%wimFile%" (
echo The specified .wim file does not exist.
timeout /t 3 /nobreak >nul
goto :chooseWimFile
)
:chooseMountLocation
call :banner
echo Please specify the mount location:
set /p mountLocation="Location: "
if not exist "%mountLocation%" (
echo The specified mount directory does not exist. Creating it...
mkdir "%mountLocation%"
if not exist "%mountLocation%" (
echo Failed to create the mount directory.
timeout /t 3 /nobreak >nul
goto :chooseMountLocation
)
)
echo Mounting image...
dism /mount-image /imagefile:"%wimFile%" /mountdir:"%mountLocation%"
if errorlevel 1 (
echo Failed to mount the image.
timeout /t 3 /nobreak >nul
goto :chooseWimFile
)
set offlineDir=%mountLocation%
goto :chooseDirectory
:chooseDirectory
call :banner
:: Resets upmumpath variable to ensure it doesn't carry over from a previous run
set upmumpath=
echo Please specify the directory containing the .mum files:
set /p mumDir="Location: "
if not exist "%mumDir%" (
echo The specified directory does not exist.
timeout /t 3 /nobreak >nul
goto :chooseDirectory
)
goto :checkUpdateMum
:checkUpdateMum
if exist "%mumDir%\update.mum" (
set upmumpath=%mumDir%\update.mum
goto :handleUpdateMum
) else (
goto :installMumFiles
)
:handleUpdateMum
call :banner
echo An update.mum file was found. Please choose an option:
echo 1. Use update.mum, ignoring other .mums
echo 2. Use other mums, ignoring update.mum
echo.
set /p updateChoice="Enter your choice: "
if "%updateChoice%"=="1" (
goto :installUpdateMum
) else if "%updateChoice%"=="2" (
goto :installMumFiles
) else (
echo Invalid choice. Please try again.
timeout /t 3 /nobreak >nul
goto :handleUpdateMum
)
:installUpdateMum
call :banner
echo Installing update.mum...
if "%installTarget%"=="current" (
dism /online /add-package /packagepath:"%upmumpath%"
) else (
dism /image:"%offlineDir%" /add-package /packagepath:"%upmumpath%"
)
if errorlevel 1 (
echo Failed to install update.mum
echo Failed to install update.mum >> installation_errors.log
) else (
echo Successfully installed update.mum
echo Successfully installed update.mum >> installation_success.log
)
echo.
echo.
echo Installation complete...
echo Check installation_success.log and installation_errors.log for details.
timeout /t 5 /nobreak >nul
goto :handle
:installMumFiles
call :banner
echo Installing .mum files...
for %%f in ("%mumDir%\*.mum") do (
if "%%f" neq "%upmumpath%" (
if "%installTarget%"=="current" (
dism /online /add-package /packagepath:"%%f"
) else (
dism /image:"%offlineDir%" /add-package /packagepath:"%%f"
)
if errorlevel 1 (
echo Failed to install %%f
echo Failed to install %%f >> installation_errors.log
) else (
echo Successfully installed %%f
echo Successfully installed %%f >> installation_success.log
)
)
)
echo.
echo.
echo Installation complete...
echo Check installation_success.log and installation_errors.log for details.
timeout /t 5 /nobreak >nul
goto :handle
:handle
:: Checks if mounted or using a disk image. Wont work if an image was mounted before running the script.
if "%mounted%"=="yes" (
goto handlemount
) else (
goto handleoffline
)
:handlemount
:: Decides what happens to the mounted path
call :banner
echo Now about the image? (if unsure, check generated .txt files)
echo 1. Save
echo 2. Discard
echo 3. Add more
echo 4. Ignore
echo.
set /p handling="Enter your choice: "
if "%handling%"=="1" (
echo Saving changes...
dism /unmount-image /mountdir:"%offlineDir%" /commit
if errorlevel 1 (
echo Failed to save changes.
echo Failed to save changes >> installation_errors.log
) else (
set mounted=
echo Changes saved successfully.
echo Changes saved successfully >> installation_success.log
)
) else if "%handling%"=="2" (
echo Discarding changes...
dism /unmount-image /mountdir:"%offlineDir%" /discard
if errorlevel 1 (
echo Failed to discard changes.
echo Failed to discard changes >> installation_errors.log
) else (
set mounted=
echo Changes discarded successfully.
echo Changes discarded successfully >> installation_success.log
)
) else if "%handling%"=="3" (
echo Continuing without unmounting...
call :chooseDirectory
) else if "%handling%"=="4" (
echo Resetting variables, returning to start...
goto :menu
) else (
echo Invalid choice. Please try again.
timeout /t 3 /nobreak >nul
goto :handleoffline
)
:handleoffline
call :banner
:: Decides what happens to the offline path
set handling=
echo Now about the image? (if unsure, check generated .txt files)
echo 1. Save {disabled}
echo 2. Discard {disabled}
echo 3. Add more
echo 4. Ignore
echo.
set /p handling="Enter your choice: "
if "%handling%"=="3" (
echo Continuing without unmounting...
call :chooseDirectory
) else if "%handling%"=="4" (
echo Resetting variables, returning to start...
goto :menu
) else (
echo Invalid choice. Please try again.
timeout /t 3 /nobreak >nul
goto :handlemount
)
::-------special-functions-----------
:exit
:: Creates a countdown for aesthetics
set "lines=echo. && echo."
set "cnt=echo COUNTDOWN"
> %tmp%\Rest1.vbs echo Wscript.sleep 1000 && SET R1=Start /w %tmp%\Rest1.vbs
cls
%lines% && echo ">---> Closing in ...3" && %cnt% 3 >> %tmp%\count.txt && %R1% && cls
%lines% && echo ">---> Closing in ....2" && %cnt% 2 >> %tmp%\count.txt && %R1% && color 06 && cls
%lines% && echo ">---> Closing in .....1" && %cnt% 1 >> %tmp%\count.txt && %R1% && cls
del %tmp%\Rest1.vbs > nul && DEL %tmp%\count.txt > nul && exit
:banner
:: Header, also clears clutter
cls
echo.
echo ___________________________________________________
echo.
echo /\_/\ ___ _ _ _ __ /\/\ /\ /\ /\/\
echo \_ _/ / _ \ ^| ^| ^| ^|^| '__^| / \ / / \ \ / \
echo / \ ^| (_) ^|^| ^|_^| ^|^| ^| / /\/\ \\ \_/ // /\/\ \
echo \_/ \___/ \__,_^|^|_^| \/ \/ \___/ \/ \/
echo.
echo ___________________________________________________
echo.
echo.
goto :eof
::githubgist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment