A little-known feature in Windows 10 and 11 allows us to automatically assign a drive letter to Microsoft OneDrive every time we start up our computer.
We have previously discussed a method to map a drive from Microsoft OneDrive using an old DOS command, “subst”. This trick was required because Windows 10 or Windows 11 won’t allow OneDrive users to map it using traditional methods. Although the DOS command works, it’s not permanent. The mapping will be removed with each reboot or restart of your PC. Therefore, we need to take the next step to ensure it remains constant.
The DOS days saw us making our mapped drive permanent with an autoexec.bat script that ran during the boot process. However, this will not work for Windows 10 and Windows 11. We can still use a Batch file to run our subst command during startup. But only if the old file is mixed with the new, and the file is linked to the correct folder.
SEE: OneDrive Cloud Usage Policies (TechRepublic Premium).
Permanently map OneDrive with a batch file to a drive letter
Batch files are a simple text file that Windows interprets into a series commands. These are the commands that you would use from the standard command prompt. The best way to explain it is that batch file are a type of scripting.
We will use this file to create a text file with the extension “.bat”. It will contain only one line. Although it doesn’t matter where the batch file is, I recommend that it be located on the operating system drive (typically C.). We will use C:Apps for our example.
Windows File Explorer can be used to navigate to your Apps folder as shown in Figure ARight-click in the righthand pane. Select New | Text Document from the context menu.
Be sure to give your new text file a name, but make sure you use the.bat extension. We used Startup.bat as our example.
Right-click the batch file you wish to edit and choose Edit from the context menu. Windows will open Notepad. You will see a blank text file. Add the subcommand that maps your drive letter to Microsoft One Drive. In my example, it’s:
subst z: “c:/Users/mark/OneDrive – Mark W Kaelin”
Figure BThis is how it looks in Notepad.
Close Notepad, save the batch file, and close it. Double-click your batch file to make it run (probably faster that you can notice), and OneDrive will be mapped as a drive letter. To get the batch file to start on startup, we must link it to the Windows 10 or Windows 11 Startup folder.
Although many users don’t know about the Windows Startup folder it is useful for running any program during boot that doesn’t have this feature. You can access it by pressing the combination keyboard shortcut Windows Key + R. Type “shell:startup” into the run command dialog box. Figure C.
To open File Explorer, click OK. Point to the Windows Startup folder. Figure D. Shortcut.| Shortcut. The dialog box that opens will allow you to browse to your batch file.
Browse to the place where your batch files are stored (Figure E). Click on the file to open it. Then click the OK button. Click Next, then Finish. Once you are done, close File Explorer.
You will now see a link to your batch files when you open the Windows Startup Folder. If the shortcut is located in the Windows Startup directory, Microsoft OneDrive will map to a particular drive letter according to your preferences.
You can remove the shortcut link in the Windows Startup folder if you don’t want Microsoft OneDrive mapped as a drive letter each time you boot your computer.