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 (Highlighted in yellow) 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 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 the 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 VHD with 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 the 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 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.
Also do not forget to share this post:
Share via
Facebook _
Twitter _
Pinterest _
GooglePlus _
Email _
Blogger _
WhatsApp
Related Articles:
Post writing is also a fun, if you be acquainted with afterward you can write if not it is complicated to write.
ReplyDeleteAs soon as I noticed this website I went on reddit
ReplyDeleteto share some of the love with them.
Thank you so much
DeleteThis means a lot to me