Forum Discussion

rmoat's avatar
rmoat
Brass Contributor
Feb 18, 2020
Solved

Start OneDrive when windows starts - All domain computers

Hello,

I'm trying to figure out if there is a way we can push out a script that will enable the OneDrive startup key. Just a small background on this, prior to my time at my company, OneDrive was disabled on all computers, including the use of the DisableFileSyncNGSC key. Removing these keys doesn't allow OneDrive to start up automatically. So far, the only way I've found out how to get it to start up, is to go into the settings of OneDrive and click the "Start OneDrive automatically when I sign in to Windows". This creates the following OneDrive registry key:

 
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
C:\Users\<username>\AppData\Local\Microsoft\OneDrive\OneDrive.exe" /background
 
However, we have 1,300+ machines and it would be nice if there was a way to somehow push this out to everyone so they didn't need to go in and enable it themselves (since most won't even read the instructions to do it).
 
The problem is, creating a registry key for each unique user per machine doesn't quite work so well. I tried creating one like this:
%userprofile%\AppData\Local\Microsoft\OneDrive\OneDrive.exe /background, but using the %userprofile% environment variable doesn't work. Is there anything I can do to force every machine to start OneDrive automatically? We want to use Known Folder Move for all of our users, but OneDrive has to start each time to ensure that syncing happens.
  • rmoat 

     

    try placing the key here instead:

     

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

     

    that should force it to run for all users on the device and you wont have to try and figure out how to inject into HKCU

7 Replies

  • Lou_Mickley's avatar
    Lou_Mickley
    Brass Contributor

    rmoat also check to make sure 

    [HKLM\SOFTWARE\Policies\Microsoft\OneDrive]"PreventNetworkTrafficPreUserSignIn" is NOT set to 1.  Setting it to 1 will prevent OneDrive from starting with Windows until the user logs in the first time.  Then it should start with Windows going forward.  you can also read more here: https://docs.microsoft.com/en-us/onedrive/use-group-policy#PreventNetworkTraffic 

    • rmoat's avatar
      rmoat
      Brass Contributor

      Lou_Mickley Thank you also! I missed this notification. This is helpful, as we're going to start using Intune to do some of these OneDrive tasks now, and this was a question we had come up just yesterday.

  • dustintadam's avatar
    dustintadam
    Iron Contributor

    rmoat 

     

    try placing the key here instead:

     

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

     

    that should force it to run for all users on the device and you wont have to try and figure out how to inject into HKCU

    • rmoat's avatar
      rmoat
      Brass Contributor

      dustintadam Thank you, that makes sense and will definitely work. Also, it just occurred to me, OneDrive can be installed for All Users by running OneDriveSetup.exe /allusers /silent.

       

      Basically we could push that out to all computers as well, and the OneDrive client is then moved/installed to C:\Program Files (x86)\Microsoft OneDrive, which also makes updating run entries easier just to point at that location instead of the user folder.

      Both seem like they'll work great. Thanks for your help!

      • dustintadam's avatar
        dustintadam
        Iron Contributor

        rmoat 

         

        Yup, you can, in fact, if you want, here's the script we use when imaging computers (we use InTune and AutoPilot, but this will work with anything as it's just PowerShell)

         

        It'll download whatever the current production release of the Sync client is and install it for all users:

         

        $ODClient = "https://go.microsoft.com/fwlink/?linkid=844652"
        $output = "$ENV:temp"  + '\OneDriveSetup.exe'
        $apppath = "C:\Program Files (x86)\Microsoft OneDrive\OneDrive.exe"
        $action = New-ScheduledTaskAction -Execute $apppath
        $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date)
         
        Invoke-WebRequest -Uri $ODClient -OutFile $output
        Start-Process -FilePath $output -ArgumentList '/allusers', '/silent'
        Start-Sleep -Seconds 60

        Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Launch OneDrive" | Out-Null
        Start-ScheduledTask -TaskName "Launch OneDrive"
        Start-Sleep -Seconds 5
        Unregister-ScheduledTask -TaskName "Launch OneDrive" -Confirm:$false
        }

         

Resources