Deploying Teams to Start Minimized at First Launch

Spread the word

Business Case

So now that Skype for Business is being killed off for Microsoft Teams, I’m sure a lot of organizations are currently looking into the migration process. If your org is like my org, we try to make our deployments as silent as possible for our users.

In our case, we wanted Teams to be extra silent due to heavy adoption of Zoom and Slack across the company. We did not want to overload our users with a myriad of different collaboration tools; however, we still want Teams to be installed as an option.

The Problem with the Teams Installation

Microsoft Teams is a super easy program to install silently via the .exe or the .msi. The problem is that after login, Teams will launch front and center on the desktop…which is something we didn’t want in our environment.

There are ways to make Teams open hidden to the task tray after login, but from my experience Teams had to be started at least once for the app preference files to be created on a per-user basis in AppData.

The two methods I know of to start Teams minimized AFTER installation are:

  1. In the app settings, check the “open application in background” checkbox

  2. Edit the desktop-config.json file to edit the openAsHidden option to true (you can script this or find pre-written scripts available online to run as a CI/baseline in ConfigMgr or even as a startup script)

What if I Want to Deploy Teams with the Hidden Option Already True?

This is where the fun begins and we potentially go into an unsupported scenario. Fun right?

Microsoft Teams is an Electron developed app, which means that most of the source files are available in an archive file called app.asar. This archive has a .js file inside it called desktopConfigurationManager.js which has the defaults for openAsHidden along with other defaults like openAtLogin, runningOnClose, etc.

What we’re going to do is install and launch Teams on a test PC to look for app.asar. From there we’re going to use Node.JS to extract the files (similar to a .zip file) and modify the desktopConfigurationManager.js file. After we do that, we’ll repackage the archive to create a brand-new app.asar file. This new file will then be deployed whenever we deploy Teams…overwriting the default one that’s a part of the Teams.exe install.

Now we’re going to use Node.JS to extract the Teams App.asar file

  • In an elevated cmd, run the following command: asar extract “%LOCALAPPDATA%\Microsoft\Teams\current\resources\app.asar” C:\Temp\asar

  • Using your code editor of choice, open C:\Temp\asar\lib\desktopConfigurationManager.js
  • Search for openAsHidden and set the values to true (there should be 2 instances)
    • You may also set other defaults here like openAtLogin as mentioned above

  • To package up our changes, run asar pack “C:\TEMP\asar” “C:\TEMP\app.asar” –unpack *.node
  • Grab the new app.asar file we just made and add it to your Endpoint Manager installation package
    • In my case I’m deploying Teams with ConfigMgr using a PowerShell script under the user context
# Install Microsoft Teams
Write-output "Installing Teams. Please Wait..."

try{
    Start-Process "$PSScriptRoot\Teams_windows_x64.exe" -ArgumentList "-s" -Wait
}catch{
    Write-output "An error occurred during installation:"
    Write-output $_
}
# Copy Customized app.asar
Write-output "Copying customized app.asar"

try{
   Copy-Item "$PSScriptRoot\app.asar" "$env:LOCALAPPDATA\Microsoft\Teams\current\resources\app.asar" -Force
}catch{
   Write-Output "An Error occurred during copying the app.asar"
   Write-Output $_
}

After Teams installs, I use the following code to launch Teams using the “system initiated” argument. This is important because if you simply launch the teams.exe process (or if a user starts Teams from the start menu or desktop icon) Teams will launch fullscreen and not honor our openAsHidden setting. Only when you launch the process with “system initiated” will our changes work. This is also how Teams gets launched when any user logs in by default.

#Define Teams Update.exe paths      
$userTeams = [System.IO.Path]::Combine("$env:LOCALAPPDATA", "Microsoft", "Teams", "current", "Teams.exe")
        
#Define arguments
$args = @("-process-start-args","""--system-initiated""")

#Launch Teams
Write-output "Launching Teams - System Initiated"
if (Test-Path -Path $userTeams) {
    Start-Process -FilePath $userTeams -ArgumentList $args
}

Huge shoutout to www.joseespitia.com for originally blogging about modifying Teams using Node.JS