Skip to content

Automatically Starting OneDrive for RemoteApp Sessions

This guide explains how to configure OneDrive to start automatically when users launch RemoteApp applications on Remote Desktop Session Host (RDSH) servers.

Problem Description

When using RemoteApp (individual published applications) instead of full desktop sessions, OneDrive does not start automatically for signed-in users. This occurs because:

  • RemoteApp sessions only launch the specific published application
  • Startup items and logon scripts designed for full desktop sessions don't execute
  • OneDrive expects to be launched during a full desktop logon process

Users must manually launch OneDrive each time they use a RemoteApp, or OneDrive doesn't sync at all.

Solution Overview

Configure the RailRunOnce registry key to automatically start OneDrive when users launch their first RemoteApp application. This registry key is specifically designed for startup applications in RemoteApp scenarios.

Prerequisites

  • Remote Desktop Session Host (RDSH) server with RemoteApp configured
  • OneDrive installed on the RDSH server
  • Administrative access to the RDSH server
  • PowerShell with administrator privileges

Registry Configuration

Registry Details

Setting Value
Path HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\RailRunOnce
Value Name OneDrive (can be any descriptive name)
Type String (REG_SZ)
Data "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background

Verify OneDrive Path

The OneDrive installation path may vary depending on your environment. Common paths:

  • C:\Program Files\Microsoft OneDrive\OneDrive.exe (per-machine install)
  • C:\Program Files (x86)\Microsoft OneDrive\OneDrive.exe (older installs)

Verify the correct path before applying the registry change.

PowerShell Script

Run this script with administrator privileges on each RDSH server:

#Requires -RunAsAdministrator

$ParentPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server"
$NewKeyName = "RailRunOnce"
$FullKeyPath = Join-Path -Path $ParentPath -ChildPath $NewKeyName

$ValueName = "OneDrive"
$ValueData = '"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background'
$ValueType = "String"

Write-Output "Attempting to configure registry key: $($FullKeyPath)"
Write-Output "Setting value: $($ValueName) = '$($ValueData)' (Type: $($ValueType))"

if ($null -eq (Get-Item -Path $FullKeyPath -ErrorAction SilentlyContinue)) {
    Write-Output "Registry key does not exist. Creating key: $($FullKeyPath)"
    try {
        New-Item -Path $FullKeyPath -Force -ErrorAction Stop | Out-Null
        Write-Output "Successfully created registry key $($NewKeyName)."
    }
    catch {
        Write-Error "Failed to create registry key: $($FullKeyPath). Error: $($_.Exception.Message)"
        exit 1
    }
}
else {
    Write-Output "Registry key $($NewKeyName) already exists."
}

try {
    Set-ItemProperty -Path $FullKeyPath -Name $ValueName -Value $ValueData -Type $ValueType -Force -ErrorAction Stop
    Write-Output "Successfully set registry value '$($ValueName)' to '$($ValueData)'."
}
catch {
    Write-Error "Failed to set registry value '$($ValueName)'. Error: $($_.Exception.Message)"
    exit 1
}

Write-Output "Registry configuration complete."

Manual Registry Configuration

If you prefer to configure the registry manually:

  1. Open Registry Editor (regedit.exe) as administrator
  2. Navigate to:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server
    
  3. Create a new key named RailRunOnce (if it doesn't exist)
  4. Inside RailRunOnce, create a new String Value named OneDrive
  5. Set the value data to:
    "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background
    
  6. Close Registry Editor
  7. No reboot required (takes effect on next user RemoteApp session)

Verification

Test the Configuration

  1. Connect to a RemoteApp application as a test user
  2. Check if OneDrive starts automatically:
  3. Look for the OneDrive icon in the system tray
  4. Open Task Manager and verify OneDrive.exe is running
  5. Verify OneDrive is syncing files

Verify Registry Value

# Check if the registry value is configured correctly
Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\RailRunOnce" -Name "OneDrive"

Expected output:

OneDrive : "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background

Deploying via Group Policy

For centralized deployment across multiple RDSH servers:

Step 1: Create GPO

  1. Open Group Policy Management Console
  2. Create a new GPO targeting RDSH servers with RemoteApp
  3. Name it appropriately (e.g., "RDSH - RemoteApp OneDrive Autostart")

Step 2: Configure Registry Preference

  1. Navigate to: Computer Configuration → Preferences → Windows Settings → Registry
  2. Right-click → New → Registry Item
  3. Configure the registry item:
  4. Action: Update
  5. Hive: HKEY_LOCAL_MACHINE
  6. Key Path: SYSTEM\CurrentControlSet\Control\Terminal Server\RailRunOnce
  7. Value name: OneDrive
  8. Value type: REG_SZ
  9. Value data: "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background
  10. Click OK
  1. Link the GPO to the OU containing your RDSH servers
  2. Run gpupdate /force on RDSH servers or wait for policy refresh
  3. Verify with: gpresult /h report.html

Understanding the /background Parameter

The /background parameter launches OneDrive silently without showing the setup wizard:

  • Starts OneDrive in the background
  • No user interaction required
  • Begins syncing immediately if already configured
  • Minimizes to system tray

Troubleshooting

OneDrive Not Starting

Solutions: - Verify the OneDrive executable path is correct - Check that OneDrive is installed on the RDSH server - Ensure the registry value is set correctly - Check Task Manager to see if OneDrive process is running - Review Event Viewer for OneDrive startup errors

OneDrive Starts Multiple Times

Problem: OneDrive launches multiple instances.

Solutions: - Ensure OneDrive is not also configured in user startup items - Check that only one RailRunOnce entry exists for OneDrive - Verify RemoteApp applications aren't individually launching OneDrive - Review RDSH startup scripts for duplicate OneDrive launches

Registry Value Not Applied via GPO

Solutions: - Verify GPO is linked to correct OU - Check GPO scope and filtering - Run gpresult /h report.html to verify GPO application - Ensure computer account is not filtered out - Check for WMI filter restrictions

OneDrive Prompts for Sign-In Every Session

Problem: Users must sign into OneDrive each RemoteApp session.

Solutions: - Configure FSLogix Profile Containers to persist OneDrive settings - Use folder redirection for AppData - Configure OneDrive Silent Account Configuration - Review user profile management strategy - Consider implementing roaming profiles or user profile disks

Path Contains Spaces Causing Issues

Problem: Registry value with spaces not working.

Solutions: - Ensure the entire path is wrapped in double quotes - Verify quotes are straight quotes (") not smart quotes (" or ") - Test the command manually in PowerShell first

Alternative: FSLogix Profile Containers

For enterprise environments, consider using FSLogix Profile Containers:

  • Persists OneDrive configuration across sessions
  • Maintains user settings and sync state
  • Eliminates need for OneDrive to re-sync each session
  • Recommended for Azure Virtual Desktop and RDS environments

See FSLogix documentation for implementation details.

Additional Startup Applications

You can add other applications to RailRunOnce using the same method:

# Example: Add multiple startup applications
$Apps = @{
    "OneDrive" = '"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background'
    "Teams"    = '"C:\Program Files\Microsoft\Teams\current\Teams.exe" --processStart "Teams.exe" --process-start-args "--system-initiated"'
}

$RailRunOncePath = "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\RailRunOnce"

foreach ($App in $Apps.GetEnumerator()) {
    Set-ItemProperty -Path $RailRunOncePath -Name $App.Key -Value $App.Value -Type String -Force
    Write-Output "Configured: $($App.Key)"
}

This guide applies to Windows Server Remote Desktop Services (RDS) with RemoteApp configurations.