How to permanently map OneDrive to a drive letter using a batch file

How to permanently map OneDrive to a drive letter using a batch file

Using a little-known feature of Windows 10 and 11, we can automatically designate a specific drive letter to Microsoft OneDrive at startup every time we boot up our PC.

Blue computer key - connect to the cloud

Image: MyImages – Micha/Shutterstock

Previously, we outlined a method for mapping a drive letter to Microsoft OneDrive using the old “subst” DOS command. This trick was needed because neither Windows 10 nor Windows 11 will allow users to map OneDrive through conventional methods. While the use of a DOS command is effective, it is not permanent. Each restart or reboot of your PC will remove the mapping, so we must take the next step to make it constant.

More about Windows

In the days of DOS we could make our mapped drive permanent through an autoexec.bat file that runs during the boot process, but that will not work with Windows 10 or Windows 11. However, we can still use a batch file to run our subst command at startup, but only if we mix the old with the new and link the file to the right folder.

SEE: OneDrive Cloud Usage Policy (TechRepublic Premium)

Permanently map OneDrive to a drive letter with a batch file

For those of you not as ancient as me, a batch file is a simple text file that Windows interprets as a series of commands. These are the kinds of commands you would issue from the standard command prompt. Probably the best way to describe it is that batch files are a form of scripting

For our purposes, we will create a simple text file with the “.bat” extension with only one line in it. It does not matter where this batch file is located, but I would suggest somewhere on the operating system drive (typically C:). For our example, we will use C:\Apps.

Use Windows File Explorer to navigate to the Apps folder, as shown in Figure A, and right-click on an open area in the righthand window. Select New | Text Document from the context menu.

Figure A

a-permanently-map-onedrive-batch-file.jpg

Give your new text file a name but be sure to use the .bat extension. For our example, we used Startup.bat.

Right-click your batch file and select Edit from the context menu. Windows will open Notepad, and you will see an empty text file. Add the subst command that maps your desired drive letter to Microsoft One Drive. In my case it is:

subst z: “c:/Users/mark/OneDrive – Mark W Kaelin”

Figure B shows you what it looks like in Notepad.

Figure B

b-permanently-map-onedrive-batch-file.jpg

Save the batch file and close out Notepad. If you double-click your new batch file, it will run (probably faster than you can notice) and OneDrive will be mapped to a drive letter. However, to get this batch file to run on startup, we will have to place a link to it in the special Windows 10 and Windows 11 Startup folder.

Many users are unaware of the Windows Startup folder, but it can be useful for running any application during the boot process that does not have that feature already built in. To reach it, use the keyboard combination shortcut Windows Key + R to open the run command dialog box and type “shell:startup”, as shown in Figure C.

Figure C

c-permanently-map-onedrive-batch-file.jpg

Click OK to open a session of File Explorer pointing to the Windows Startup folder, as shown in Figure D. Right-click an open area in the righthand window and select New | Shortcut. You will be presented with a dialog box where you can browse to your batch file.

Figure D

d-permanently-map-onedrive-batch-file.jpg

Browse to where you stored your batch file (Figure E). When you find the file, click on it, and then click the OK button. Click Next and then Finish. Close out File Explorer when you are done.

Figure E

e-permanently-map-onedrive-batch-file.jpg

Now, when you look at the Windows Startup folder, you will see a link to your batch file. As long as that shortcut is in the Windows Startup folder, Microsoft OneDrive will be mapped to a specific drive letter according to your preferences when you boot your PC.

If you decide you no longer want Microsoft OneDrive mapped to a drive letter every time you boot your PC, simply remove the shortcut link from the Windows Startup folder.

Also see

Source of Article