Automatically Mount Virtual Hard Disk at Startup in Windows

In previous posts I told you about creating virtual hard disk in Windows 8, 8.1 & 10 , creating virtual hard disk in Windows 7 , mounting and unmounting virtual hard disks in Windows 8, 8.1 &10 and mounting and unmounting virtual hard disks in Windows 7. Now I am going to tell you how you can make a virtual hard disk automatically mount at startup in Windows 7 and above. Some versions of Windows 10 will not unmount the virtual hard disk until you restart the computer. So you can mount a virtual hard disk and then turn off your computer and then turn it on to see what happens and then restart your computer to see what happens. If you feel the need that you should make the hard disk automatically mount at startup, follow this tutorial. It is divided in two parts:

Part ONE (Creating a batch file):

In this part we will create a batch file which will contain commands to attach the virtual hard disk.

If there is one virtual hard disk to attach:

1. Press WindowsKey+ R to open run. Type notepad and press enter or Ok.

2. The notepad window will open. (You can use any method to open notepad)

3. The tricky section is now beginning. Take a look at the code below:

@echo off
set UmerSoftwares="%TEMP%%RANDOM%.TXT"
echo select vdisk file="Path to VHD" >>%UmerSoftwares%
echo attach vdisk >>%UmerSoftwares%
diskpart /s %UmerSoftwares%
del %UmerSoftwares%

You have to copy the code above and paste it in the notepad (You can also write it manually). Make sure to replace the Path to VHD in the above code with the path to your Virtual Hard disk file (Not the mounted virtual hard disk itself).

4. After writing the code, click the File menu.

5. Select Save As.

6. Navigate to the folder where you want to save the batch file. In the box that I have shown with a green box in the screenshot below, type a name for the batch file followed by .bat extension. For example vhd attach.bat
Then press the Ok button.

7. A batch file will appear in the directory you specified in the previous step. You will need this in Part 2 of this tutorial.

If there are more than one virtual hard disks to attach:

1. You will have to open notepad as told in the steps 1 and 2 in the previous portion.
2. For more than one virtual hard disks to be attached, you will have to make minor changes to the code. The code in the previous portion was:

@echo off
set UmerSoftwares="%TEMP%%RANDOM%.TXT"
echo select vdisk file="Path to VHD" >>%UmerSoftwares%
echo attach vdisk >>%UmerSoftwares%
diskpart /s %UmerSoftwares%
del %UmerSoftwares%

Now you will have to copy the third and fourth lines from the above code and paste it at immediately next line as many times as the number of required hard disks. Do not forget to replace the Path to VHDwith the path to the virtual hard disk each time you paste the code. For example, the code for two hard disks is

@echo off
set UmerSoftwares="%TEMP%%RANDOM%.TXT"
echo select vdisk file="Path to first VHD" >>%UmerSoftwares%
echo attach vdisk >>%UmerSoftwares%
echo select vdisk file="Path to second VHD" >>%UmerSoftwares%
echo attach vdisk >>%UmerSoftwares%
diskpart /s %UmerSoftwares%
del %UmerSoftwares%

You will have to modify the code for any number of hard disks you want to attach. In the screenshot below, I have written the code to attach three virtual hard disks.

3. Now you will have to create the batch file from this notepad as told in steps 5, 6 and 7 in the previous portion of this article.

Part TWO (Adding the batch file to startup):

In this part of the tutorial, we will be adding the virtual hard disk to startup. I have a complete tutorial on How to make programs automatically launch at startup. Consider checking that if you want to see all methods of adding the batch file you made in the part one to startup. Here I am going to write only one method.

1. Right-click the batch file you created in part one and select copy.

2. Press WindowsKey+ R to open run. Type shell:startup and press Ok.

3. The startup folder will open. You will have to click the white area and select Paste shortcut.

4. The batch file will be added to startup.

5. You can restart your computer to check if the virtual hard disk is attached automatically at startup. It may ask you the permission to have administrator privileges when you log in to Windows. If so click Yes to grant the permission. This method may not work with an account on your computer which is not an administrator.

If you follow the above procedure correctly, you should be able to make the vhd automatically mount at Windows startup. If you are still having any problem, feel free to ask in the comments.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *