Creating a Script to Deploy Pre-Layered Applications at Boot
This section covers the process of creating a script to deploy applications that are pre-layered on the endpoint and register file extensions and context windows with Windows Explorer. In order to do that, you need to bundle the following script into an IntuneWin package. In the next chapter, you will create an IntuneWin package of this script.
Note: This script name will be used in the next chapter in the App information section, where you are asked to enter the app name. For this example, we will give this script the name _StartupIntuneFA1s.cmd. If you change this name, you will need to change it in the script below, too.
Copy
@echo off
set FA1StartupPath=%ProgramData%\FlexAppOne\Startup
set options=--system --index 999
:: Edit Above
::----------
cls
if not A%1A==AA set FA1StartupPath=%1
if not A%2A==AA set options=%2
::Uninstall Section - if true, runs and skips to end
if /i A%1A==AuninstallA rd /s/q "%ProgramData%\FlexAppOne\Startup\Logs" & schtasks /delete /tn "(FA1)\(FA1) StartupIntuneFA1s" /f & goto end
::Install Section - Intune process to copy _StartupIntuneFA1a.cmd from IME Cache folder to ProgramData
::Skips if _StartupIntuneFA1s.cmd exists in ProgramData
if not exist "%programdata%\FlexAppOne\_StartupIntuneFA1s.cmd" md "%programdata%\FlexAppOne" & copy _StartupIntuneFA1s.cmd "%programdata%\FlexAppOne">nul 2>&1
::Runs After Install Section by Intune System context at install time and by Task Scheduler after each reboot
schtasks /delete /tn "(FA1)\(FA1) StartupIntuneFA1s" /f & schtasks /create /tn "(FA1)\(FA1) StartupIntuneFA1s" /tr "%ProgramData%\FlexAppOne\_StartupIntuneFA1s.cmd" /sc onlogon /ru system>nul 2>&1
::Runs after Intune Installs app as System and then Task Scheduler runs each time the system reboots
cd /d "%FA1StartupPath%" & for /f "tokens=* delims=" %%i in ('dir "%FA1StartupPath%\*.exe" /b') do start "Startup" "%FA1StartupPath%\%%i" %options% & md "%FA1StartupPath%\Logs">nul 2>&1 & echo Started %FA1StartupPath%\%%i %options% > "%FA1StartupPath%\Logs\%%i.txt"
:end
