OneDrive won’t open if there’s a space in the user name: a quick fix

OneDrive has a really weird bug that happens quite rarely but that will prevent you from even logging into the service if your user account happens to have a space in it. The bug does not appear to affect every user with a space in its user name and it’s not really clear why some people get it and why others don’t. Nevertheless, it can be a very aggravating issue that most people won’t be able to troubleshoot on their own, leaving them with an unusable cloud storage service that reminds them it doesn’t work every time it’s run with an error message such as this:

What’s going on?

In some cases, opening Onedrive from the Start menu or at startup invokes the batch script OneDrivePersonal.cmd located under C:\Users\Username\Appdata\Local\Microsoft\OneDrive.

Files ending in .BAT or .CMD are actually text files that run in an instance of the Command Prompt. OneDrivePersonal is no exception. If you right-click it and select Edit, here’s what it will look like.

If those two lines of text look like they may be Command Prompt commands, that’s because they are.

What do those lines do?

The first line tells the Command Prompt to run the program Onedrive.exe located under the %LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe folder using the option /client=Personal. Note that this path is a shortened version of C:\Users\Username\Appdata\Local\Microsoft\OneDrive. More on that later.

The exit command simply exits the command prompt.

What’s causing the issue?

Under normal circumstances (i.e., when the username does not contain white spaces) the script runs normally. However, when there is a space in the username, the Command Prompt has no way of telling whether a white space is part of the path or is used to separate various parts of the start command. It then defaults to assuming that the actual path ends with the first white space it encounters. In our case, user Tech 4 Freelancers was trying to open OneDrive, so the first line of the script is interpreted as “Run the program named Tech.exe located under C:\Users”. Since there is no program called Tech.exe, we encounter this error.

How to fix the issue

In the Windows Explorer address bar, type %LOCALAPPDATA%/Microsoft/Onedrive and press Enter. You’ll be shown the folder in the second screenshot in this page:

Right-click OneDrivePersonal.cmd and select Edit. The file will be opened in Notepad. Replace its content with the following code, then save and exit Notepad:

cd "%LOCALAPPDATA%\Microsoft\OneDrive\"
start onedrive.exe /client=Personal

You can test if the edits solved the issue by double-clicking OneDrivePersonal.cmd. If the window for logging into OneDrive appears, it worked.

Extending the fix to other users (optional)

If your computer has more than one account with white spaces in it, you will need to edit the content of each OneDrivePersonal.cmd file manually, or automate the process by running

for /f "tokens=*" %i in ('dir /b c:\users') do copy "c:\users\%USERNAME%\Appdata\local\microsoft\onedrive\onedrivepersonal.cmd" "c:\users\%i\appdata\local\microsoft\onedrive\onedrivepersonal.cmd"

in a Command Prompt window with elevated privileges. Despite the command taking up multiple lines in the web page, it actually is a single, long line. It goes without saying that only administrators can run command prompts with elevated privileges.

About Andrea Luciano Damico 137 Articles
Andrea Luciano Damico is a freelance translator from Italy. Among his interests are linguistics, technology, video games, and generally being a chill guy. He runs Let's and