In this post, we’ll see how we can add a application shortcut in Startup folder so that it starts automatically with Windows.

We can use 3 methods:

  1. Copy pre-existing shortcut to Startup folder using PowerShell script
  2. Embed shortcut in PowerShell script. The same script will create the shortcut and put it in Startup folder
  3. Create a Win32 application which will copy the shortcut to Startup folder.

Existing setup done:

  1. Two Local users created
  2. Azure AD Connect configured
  3. Seamless Single Sign-On (IE) configured
  4. Seamless Single Sign-On (Firefox) configured
  5. Hybrid Azure AD Join configured
  6. Intune enrollment – Domain Joined Windows 10 devices
  7. Azure AD Join
  8. Office 365 Pro Plus Application
  9. Sample SharePoint Team Site
  10. OneDrive Known Folder Migration and SharePoint library sync
  11. Copy necessary files (Win32 App)
  12. Set Desktop Background, Lock Screen and Screensaver

Existing setup:

  1. SkyDC: Machine with ADDS, DNS, DHCP role
  2. SkyCON: Machine where we will install Azure AD Connect
  3. SkyCM: Machine with Configuration Manager Current Branch
  4. SkyTEN1: Domain Joined Windows 10 machine
  5. SkyTEN2: Domain Joined Windows 10 machine
  6. SkyTEN3i: Domain Joined Windows 10 machine (Intune Managed)
  7. SkyTEN4i: Domain Joined Windows 10 machine (Intune Managed)
  8. SkyTEN5i: Azure AD Joined Windows 10 (Intune Managed)
  9. SkyTEN6i: Azure AD Joined Windows 10 (Intune Managed)
  10. SkyTEN7i: Azure AD Joined Windows 10 (Cloud User, Intune Managed)
  11. SkyTEN8i: Azure AD Joined Windows 10 (Cloud User, Intune Managed)

Have 3 groups where we will deploy the 3 methods:

Microsoft Edge in Startup (Method 1)

This method assumes that the shortcut exists in Windows folder.

#Script to put Microsoft Edge in Startup Folder

#Check for Edge shortcut already copied

$EdgeShortcut = “${Env:SystemRoot}\Microsoft Edge.lnk”

$EdgeShortcutDestinationPath = “${Env:programdata}\Microsoft\Windows\Start Menu\Programs\Startup”

if(Test-Path $EdgeShortcut)

{

#Shortcut exists. simply copy it to Startup Folder

Copy-Item -Path $EdgeShortcut -Destination $EdgeShortcutDestinationPath

}

Create a PowerShell Script with above Text.

Follow above method to add the PowerShell Script in Intune.

Navigate to Intune -> Device configuration -> PowerShell scripts. Click on +Add.

In Name, provide name of the script. I have given below. Click Next.

Name: Copy Edge to StartUp

Description: This script will copy the Microsoft Edge shortcut which is already present in Windows folder (copied using CopyFIles application) into StartUp folder.

Click on Folder icon and select the script. Click Next.

In Assignments, select the appropriate option. As I want to deploy it to a group, click on +Select groups to include and select the appropriate group.

After group is selected, click Next.

Click Add.

In Client machine:

Sync the device

Restart the Microsoft Intune Management Extension service.

The shortcut appears in StartUp folder.

After restart, you can see that Microsoft Edge automatically starts.

In Intune check the script status.

Microsoft Edge in Startup (Method 2)

Script to convert a file to Base64 encoding. Here Microsoft Edge shortcut is used.

#Script to convert Microsoft Edge shortcut into Base64 format

$EdgeShortcut = “Microsoft Edge.lnk”

if(Test-Path $EdgeShortcut)
{
#Shortcut exists. Convert into Base64.
$Content = Get-Content -Path $EdgeShortcut -Encoding Byte
$Base64 = [convert]::ToBase64String($Content)
Write-Host $Base64
Set-Content -Path “Microsoft Edge Base64.txt” -Value $Base64
}

Create a script with above text.

Put the Edge shortcut in the same folder

Execute the script. You can see the Base64 equivalent of the shortcut file.

The text file got created.

Create a PowerShell script. Embed the Base64 string into the script. The script when executed will create the shortcut into desired folder:

PowerShell script to create Microsoft Edge shortcut in global Startup folder

Copy the content from “Microsoft Edge Base64.txt” file in $Base64 variable.

#Script to put Microsoft Edge in Startup Folder

#Create Edge Shortcut

$EdgeShortcut = “$Env:programdata\Microsoft\Windows\Start Menu\Programs\Startup\Microsoft Edge.lnk”

if(Test-Path $EdgeShortcut)

{

#Shortcut exists. Do not do anything.

}

else

{

#Shortcut does not exists. Create Shortcut

$Base64 = “TAAAAAEUAgAAAAAAwAAAAAAAAEaBAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAADcFFAAfgJvUNEJFAvNNt4A4k5Q0VuEhBQAAGwVBUFBTCQUIAAMAAAAAAAAAFQI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AxADUAMAAuAHAAbgBnAAAAEQAAAAQAAAAAEwAAAAB41/9dAAAAEwAAAAAfAAAAJgAAAEEAcwBzAGUAdABzAFwATQBpAGMAcgBvAHMAbwBmAHQARQBkAGcAZQBTAHEAdQBhAHIAZQAzADEAMAB4ADMAMQAwAC4AcABuAGcAAAARAAAABQAAAAATAAAA/////xEAAAAOAAAAABMAAAChBAAAMQAAAAsAAAAAHwAAAA8AAABNAGkAYwByAG8AcwBvAGYAdAAgAEUAZABnAGUAAAAAAFkAAAAUAAAAAB8AAAAkAAAAQQBzAHMAZQB0AHMAXABNAGkAYwByAG8AcwBvAGYAdABFAGQAZwBlAFMAcQB1AGEAcgBlADcAMQB4ADcAMQAuAHAAbgBnAAAAAAAAADEAAAAxU1BTsRZtRK2NcEinSEAupD14jBUAAABkAAAAABUAAAA8AAAAAAAAAAAAAABNAAAAMVNQUzDxJbfvRxoQpfECYIye66wxAAAACgAAAAAfAAAADwAAAE0AaQBjAHIAbwBzAG8AZgB0ACAARQBkAGcAZQAAAAAAAAAAAC0AAAAxU1BTs3ftDRTGbEWuWyhbONewGxEAAAAHAAAAABMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==”

$Content = [Convert]::FromBase64String($Base64)

Set-Content -Path “$Env:programdata\Microsoft\Windows\Start Menu\Programs\Startup\Microsoft Edge.lnk” -Value $Content -Encoding Byte

}

Note: While creating the script, make sure that entire Base64 text is in one line.

Deploy the script to 2nd group using Microsoft Intune. You can use the above method.

The script is created and deployed.

In Client machine

The shortcut appears in StartUp folder

After restart, you can see that Microsoft Edge automatically starts.

Check the status of the script.

Microsoft Edge in Startup (Method 3)

Copy Files – Win32 App

Make a list of all necessary files that you want to copy to targeted devices.

Create a folder and put all files in that folder

copyEdgeToStartup.cmd

Microsoft Edge.lnk

Create a CMD file which will copy the shortcut file to StartUp folder:

copy /Y .\”Microsoft Edge.lnk” “%ProgramData%\Microsoft\Windows\Start Menu\Programs\StartUp\”

The Win32 Content Prep Tool

Open Command Prompt. Navigate to the folder where Win32 Content Prep Tool is extracted and execute IntuneWinAppUtil.exe

Enter relevant details and press Enter. I have used the below:

Please specify the source folder: D:\Tenants\Sky366\Apps\CopyEdgeToStartup

Please specify the setup file: copyEdgeToStartup.cmd

Please specify the output folder: D:\Tenants\Sky366\Apps\Win32Apps

The intunewin file created

Create an Win32 App in Intune

Login to Azure portal.

Navigate to Intune -> Client apps -> Apps. Click on +Add.

In App type, select Windows app (Win32).

Click on App package file – Select file.

Click on the folder icon and select the .Intunewin file

Click OK.

Click on App information – Configure.

Enter the details and click OK. I have used below

Name: Copy Edge shortcut to StartUp folder

Description: This App will copy the Microsoft Edge shortcut to StartUp folder.

Publisher: Your Organization

Click on Program – Configure.

In Install command, enter the CMD file which will copy the files.

In Uninstall command, enter the CMD file which will copy the files. Note: As I am not going to use Uninstall command, I have used the same CMD file. You can create another CMD file in the same folder which will delete the files from the Windows folder and mention it here.

In Install behavior, select System.

Click OK.

Click on Requirements – Configure.

In Operating system architecture, select both the architecture.

In Minimum operating system, select the appropriate option.

I have selected the Windows 10 1607.

Click OK.

Click Detection rules – Configure.

In Rules format, select Manually configure detection rules. Click Add.

Note: if the shortcut file in the app exists in the StartUp folder, then app is already run. So, we’ll check for its existence.

In Rule type, select File.

In Path, enter %ProgramData%\Microsoft\Windows\Start Menu\Programs\StartUp\

In File or folder, enter one of the filename with extension. I entered Microsoft Edge.lnk.

In Detection method, select File or folder exists.

In Associated with a 32-bit app on 64-bit clients, select No.

Click OK.

Click OK.

Click Add.

After some time, you’ll see that the file is uploaded successfully.

Open the App again.

Navigate to Assignments.

Click on Add group.

In Assignment type, select Required.

Click on Include Groups.

Choose appropriate option.

I am making the app required for the devices in 3rd group I created earlier in this post.

Click OK two times.

Click Save.

In Client machine:

Sync the device

Restart the Microsoft Intune Management Extension service

The shortcut appears in StartUp folder

After restart, you can see that Microsoft Edge automatically starts.

Check the status of the application.

Leave a comment

Your email address will not be published. Required fields are marked *