Skip to content

Instantly share code, notes, and snippets.

@CartBlanche
Last active August 18, 2023 09:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CartBlanche/cc135d46944818864d9d468916c982cd to your computer and use it in GitHub Desktop.
Save CartBlanche/cc135d46944818864d9d468916c982cd to your computer and use it in GitHub Desktop.
A batch file that automates self elevation (to UAC), enables side loading, uninstalls the previous version and then installs a new version of your Windows 10 UWP/UAP app.
@echo off
REM Version 1.3
REM
REM Put this batch file in the same directory as your published Windows app directory and change the variable value below [YOUR_APP_PACKAGE_ID]
REM
REM Once you are ready to publish this publically, zip up the *.cer, *.msixappbudle or *.appxbundle and this batch file and
REM put it on your server or upload it to your itch.io account.
REM Tell your users/customers to unzip and launch the install.bat file and follow the prompts.
REM
REM NOTE: Some users/customers may not have the appropriate rights to enable Developer Mode and Side Loading.
REM Usually people trying to install something on their work machines, which are locked down.
REM
REM This batch file is provided as is and I cannot be held responsible for any damage it may cause. It works for my scenario, apps and game and worked during testing.
REM By downloading and using this file, you accept the above disclaimer.
REM Is this batch file the perfect side-loading installer. NO! Don't @ me :)
REM If you find this batch file useful, let me know and give credit where credit it due.
REM If you have suggestions to improve it for the betterment of the whole community, then @ me as CartBlanche on github, or SoftSavage on Instagram and Twitter.
REM Any improvement will be added to this gist file and your name will be added to the credits below.
REM
REM Updates
REM -------
REM v1.1 Made Desktop Shortcut creation optional with a prompt.
REM v1.2 Made certificate installation more specific to "this" app.
REM v1.3 Add human readable variable, which is friendlier to the customer. See appName variable.
REM
REM Credits
REM -------
REM Bringing together of several Stack Overflow searches
REM Dominique Louis - Original publisher of this file.
REM [Your_Name_Here] - Contributer
CLS
net session >nul 2>&1
if %errorlevel% equ 0 (
goto installApp
) else (
goto restartBatchfile
)
:installApp
REM Change this variable's value to YOUR UWP/UAP app's package name, found on the Packaging tab of Package.appxmanifest. No spaces!!
set installedApp=[YOUR_APP_PACKAGE_ID]
REM Change this variable's value to YOUR UWP/UAP Display Name. This can contain spaces as long as everything is on one line.
set appName=[HUMAN_READABLE_NAME]
echo Enabling Developer Mode for Sideloading
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
FOR /F "delims=" %%i IN ('DISM /Online /Get-CapabilityInfo /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0') DO (
if "%%i"=="State : Not Present" (
DISM /Online /Add-Capability /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
)
)
echo Installing Certificates for "%appName%"
for %%i in (%~sdp0\*%installedApp%*.cer) do certutil.exe -addstore TrustedPeople %%i
echo Uninstalling previous versions of "%appName%"
PowerShell -command "Get-AppxPackage | ?{ $_.Name.Contains('%installedApp%') } | Remove-AppxPackage"
echo Launching "%appName%" Installers
for %%j in (%~sdp0\*%installedApp%*.msixbundle) do (
echo "Installing %%j"
Powershell -command "Add-AppxPackage -Path %%j"
)
for %%j in (%~sdp0\*%installedApp%*.appxbundle) do (
echo "Installing %%j"
Powershell -command "Add-AppxPackage -Path %%j"
)
:desktopShortcutPrompt
set desktopShortcut=
set /p desktopShortcut=Would you like to create a Desktop Shortcut for "%appName%" now (Y/N)?
if '%desktopShortcut%'=='Y' goto createDesktopShortcut
if '%desktopShortcut%'=='y' goto createDesktopShortcut
if '%desktopShortcut%'=='N' goto launchprompt
if '%desktopShortcut%'=='n' goto launchprompt
echo "%desktopShortcut%" is invalid. Please try again
echo.
goto desktopShortcutPrompt
:createDesktopShortcut
echo Creating a Desktop Shortcut for "%appName%"
Powershell -command "$app = Get-StartApps | ?{ $_.AppID.Contains('%installedApp%') }; $appName = $app.Name.Replace(':', '-'); $linkFile = ($appName + '.lnk'); $linkPath = Join-Path ([Environment]::GetFolderPath('Desktop')) $linkFile; $link = (New-Object -ComObject WScript.Shell).CreateShortcut($linkPath); $link.TargetPath = ('shell:appsFolder\' + $app.AppID); $link.Save();"
:launchprompt
set choice=
set /p choice=Would you like to Launch "%appName%" now (Y/N)?
if '%choice%'=='Y' goto launchapp
if '%choice%'=='y' goto launchapp
if '%choice%'=='N' goto installcomplete
if '%choice%'=='n' goto installcomplete
echo "%choice%" is invalid. Please try again
echo.
goto launchprompt
:launchapp
echo Launching "%appName%"
Powershell -command "$app = Get-StartApps | ?{ $_.AppID.Contains('%installedApp%') }; $appID = $app.AppID; $shellPath = ('shell:appsFolder\' + $app.AppID); (explorer.exe $shellPath);"
:installcomplete
echo Installation of "%appName%" Complete.
pause
exit
:restartBatchFile
REM Relaunch itself with elevated privileges
Powershell Start install.bat -verb runas
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment