VHD - Auto-mount at Startup in Windows 8

How to Auto-mount a VHD at Startup in Windows 8

information   Information
This tutorial will help show you how to have a VHD auto-mount as a drive at startup in Windows 8.

You must be signed in as an administrator to complete these steps.

Tip   Tip
If you like, you could also use Bitlocker to encrypt the VHD drive.




Here's how...


1. To start with, create a VHD file, using the drive letter you want to use for this VHD.
NOTE: For example, I've created a VHD file called 'MySecureStuff.vhd' in the 'C:\MyVHDs' folder, and I want it to be mounted as drive H.

2. Open Notepad, and copy the text below into it. (Note I have struck out the third line as I believe it was incorrect and shouldn't be entered.)

Code:
select vdisk file="[COLOR=#ff0000][B]C:\MyVHDs\MySecureStuff.vhd[/B][/COLOR]"
attach vdisk
[DEL]assign letter=[COLOR=#ff0000][B]H[/B][/COLOR][/DEL]
[DEL]
[/DEL]
A) Change the 'file=' part of the first line to contain the full path to the VHD you created earlier in step 1.​
B) Change the 'assign letter' to be the drive letter you wish to use.​
SetupScript_1a_x.png


3. In Notepad, save it as a .txt file, and close Notepad.
NOTE: For example, I've called mine 'AttachVHD_H.txt' and saved it in a folder called 'C:\MyVHDs\VHDLoadScripts'.
SetupScript_2a_x.png

4. Open the WIN+X Power User Tasks menu, and click/tap on Computer Management. (see screenshot below)
SetupScript_3.png


5. In Computer Management, select Task Scheduler on the left (point 1 on screenshot), then select Create Task (point 2 on screenshot).
SetupScript_4a.png


6. In the General tab, enter a name and description for your task. Change the radio buttons to 'Run whether user is logged on or not', and change 'Configure for:' to say Windows 8.
Task_1a.png


7. Select the Triggers tab, then click New to add a new Trigger. Change 'Begin the task' to say 'At Startup'. Optionally, you can also tick the 'Delay task for' checkbox and select 1 minute (see note below). Click on OK.

Note   Note
The reason I selected a 1 minute delay is because I plan to enable BitLocker. Delaying gives the computer the chance to prompt me to enter a Bitlocker password just after I login rather than having to manually find the drive and start BitLocker. If you aren't using BitLocker, I don't think there's any advantage in selecting the delay.


Task_2a_Sub.png

8. Select the Actions tab, then click New to add a new Action.
A) In the 'Program/Script' box enter diskpart.​
B) In the 'Add arguments' box enter:​
/s
followed by a space and then the full path and name of the script file saved in step 4. So in my example it is:​
/s C:\MyVHDs\VHDLoadScripts\AttachVHD_H.txt
C) Click on OK.​
Task_3a.png

9. Select the Conditions tab. Clear the two checkboxes to Stop if the computer switches to battery power and Start the task only if the computer is on AC power, then click on OK to create the task.
Task_4a.png

10. If a Task Scheduler dialog pops up, saying 'enter user account information for running this task' then enter the password for the administrator username.
WARNING: You will also need to update this if you ever change the password on this account.
Task_6a_Auth.png


11. Close Computer Management.

12. To test this works, restart your computer. When it restarts, you should find that after a minute, the new drive is mounted as drive H: (or whatever you selected).


That's it, you're done!


 

Attachments

  • Windows_Virtual_PC.png
    Windows_Virtual_PC.png
    15.2 KB · Views: 399
Last edited by a moderator:
Great tutorial David. It's all polished up now. :)
 

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G7 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Galaxy S23 Plus phone
Nice!
Great job DavidY!
 

My Computer

System One

  • OS
    Windows 10 Pro x64
    Computer type
    Laptop
    System Manufacturer/Model
    Lenovo Y520
    CPU
    Intel Core i5 7300HQ
    Motherboard
    OEM Lenovo
    Memory
    4GB DDR4-2400
    Graphics Card(s)
    NVIDIA GeForce GTX 1050
    Sound Card
    Realtek HD
    Monitor(s) Displays
    1 (2)
    Screen Resolution
    1920x1080
    Hard Drives
    Seagate 1TB 5400 RPM
    Keyboard
    OEM Lenovo
    Mouse
    Logitech G502 Proteus Core
    Internet Speed
    100 Mbps
    Browser
    Google Chrome
    Other Info
    PC:

    AMD Athlon X4 760K
    8GB DDR3-1866
    AMD Radeon RX 460
    Seagate 500 GB 7200 RPM
Great work!
Can be very useful.
 

My Computer

System One

  • OS
    Windows 10 x64
    Computer type
    Laptop
    System Manufacturer/Model
    HP Envy DV6 7250
    CPU
    Intel i7-3630QM
    Motherboard
    HP, Intel HM77 Express Chipset
    Memory
    16GB
    Graphics Card(s)
    Intel HD4000 + Nvidia Geforce 630M
    Sound Card
    IDT HD Audio
    Monitor(s) Displays
    15.6' built-in + Samsung S22D300 + 17.3' LG Phillips
    Screen Resolution
    multiple resolutions
    Hard Drives
    Samsung SSD 250GB + Hitachi HDD 750GB
    PSU
    120W adapter
    Case
    small
    Cooling
    laptop cooling pad
    Keyboard
    Backlit built-in + big one in USB
    Mouse
    SteelSeries Sensei
    Internet Speed
    slow and steady
    Browser
    Chromium, Pale Moon, Firefox Developer Edition
    Antivirus
    Windows Defender
    Other Info
    That's basically it.
I have tried this a couple of times and although it "mounts" the VHDX, I have to double-click the VHDX file in Explorer before it is visible as my H Drive. Any solution for this?
 

My Computer

System One

  • OS
    Win 8.1
I'm not sure, to be honest.

When you initially created the VHD, did you assign it to drive H:? I found that I needed to assign the same drive letter in Disk Management as I wanted to mount it with later.

Also what happens if you run the diskpart command in an elevated command prompt?

One thing to try is to run this (with whatever filenames and paths you used).
diskpart /s C:\MyVHDs\VHDLoadScripts\AttachVHD_H.txt

Note that when I tried this, it gives me this message at the end. This doesn't seem to be an issue though.
There is no volume specified.
Please select a volume and try again.

Or you could try the commands individually , eg.
diskpart
select vdisk file="C:\MyVHDs\MySecureStuff.vhd"
attach vdisk
assign letter=H
exit
 

My Computer

System One

  • OS
    Windows 8.1, 10
Hi David - my physical HGST 4TB drive has drive letter E: assigned to it in Disk Management. Should the virtual drive have a different logical letter?

Disk 1 in DM is the physical HGST 4TB drive with the first 379MB reserved by the system, the next 2TB in an active, healthy primary partition (listed as E:), and the remaining 1.6TB unallocated.
 

My Computer

System One

  • OS
    Win 8.1
Hi bbrescia,

Have you assigned a drive letter to the virtual disk VHDX, in Disk Management?

In my example it's the Virtual drive letter I'm trying to set; what I did was create a VHDX and set it to drive H: when I first set it up in Disk Management.

The diskpart script in Task Scheduler then mounts it back to where it was before, but I think it needs to be done in Disk Management first.

There shouldn't be any changes to the physical drive letters.
 

My Computer

System One

  • OS
    Windows 8.1, 10
yes - sorry, I am saying H: but really I meant F:. The drive is assigned to F: in DM and my script says F: too. The task reports that it ran successfully.
 

My Computer

System One

  • OS
    Win 8.1
When I run my script from a DOS prompt, it reports successful completion but also says, "There is no volume specified. Please select a volume and try again."

ALso - after the script runs, I can see that in DM, the virtual drive is mounted with the letter F: It also appears in Explorer. It just doesn't get to the final step of appearing in Explorer if the script runs at startup. Here is my script:

select vdisk file="E:\HGST4TB.vhdx"
attach vdisk
assign letter=F
 

My Computer

System One

  • OS
    Win 8.1
I would have saved the script to my C: drive but for some odd reason it won't let me write to the C: drive. I've checked the properties of the C: drive - it is shared and every class of user has full control, including me, the "trusted installer". What's up with that?
 

My Computer

System One

  • OS
    Win 8.1
I would have saved the script to my C: drive but for some odd reason it won't let me write to the C: drive. I've checked the properties of the C: drive - it is shared and every class of user has full control, including me, the "trusted installer". What's up with that?
Windows doesn't like you placing files in the root directory of the C: drive. It's much happier if you create a folder and put your files there, so I'd give that a try. I don't think there's any real advantage in putting them in the C:\ root directory.

I don't see why that should extend to the E:\ drive, but it might be worth trying creating a folder E:\MyVHDs or whatever, and putting the VHDX and the startup scripts there, to see if that makes a difference.

When I run my script from a DOS prompt, it reports successful completion but also says, "There is no volume specified. Please select a volume and try again."
Yes I get that too. It doesn't seem to be a problem when I've run it though; I get that message but it appears in Explorer with no problems.

I have to go to work now but will try and investigate more tonight.
 

My Computer

System One

  • OS
    Windows 8.1, 10
ALso - after the script runs, I can see that in DM, the virtual drive is mounted with the letter F: It also appears in Explorer. It just doesn't get to the final step of appearing in Explorer if the script runs at startup. Here is my script:

select vdisk file="E:\HGST4TB.vhdx"
attach vdisk
assign letter=F
I just had another thought...

What happens if you go back into Disk Management, and assign the virtual drive to another drive letter, say M:? Then change the script to assign letter=M as well and try it.

My theory is this - I'm wondering if there might be some hardware on your computer (for example a memory card reader) that has previously been mounted as F: . If there's no memory card inserted, it doesn't show in Windows Explorer, but I suspect Explorer still knows about it and has it in mind, which is why it doesn't like to show your VHD.

If so, then you need to find a drive letter that's far enough through the alphabet that Explorer doesn't have another use for it.
 

My Computer

System One

  • OS
    Windows 8.1, 10
Hi bbrescia,

Thanks for that. I don't know what the problem is. Could you post a screenshot of your Disk Management screen please?

Perhaps something in there will give us a clue.
 

My Computer

System One

  • OS
    Windows 8.1, 10
DM Screenshot Just After Startup.jpgFile Explorer Screenshot Just After Startup.jpgDM Screenshot Just After Double-clicking the VHDX file.jpgFile Explorer Screenshot Just After Double-clicking the vhdx file.jpg

My script (file is named AttachMyVHDX.txt and is located in E:\VHDs:

select vdisk file="E:\VHDs\HGST4TB.vhdx"
attach vdisk
assign letter=F

In Task Scheduler, the "action" is: diskpart /s with parameter of E:\VHDs\AttachMyVHDX.txt

Thank you so much for sticking with this and I'm sure it will wind up to be some little fairly obvious thing that I've missed!

Bob
 

My Computer

System One

  • OS
    Win 8.1
Oh - the pix are in order:

DM Screenshot just after startup
File Explorer shot just after startup
DM Screenshot after double-clicking the vhdx file
File Explorer screenshot just after double-clicking the vhdx file
 

My Computer

System One

  • OS
    Win 8.1
select vdisk file="E:\VHDs\HGST4TB.vhdx"
Hello Bob,

I think in this part of the script, you're saying the path to the VHDX is:
E:\VHDs\HGST4TB.vhdx

But from the screenshot, it's actually in:
E:\HGST4TB.vhdx

So you would either need to unmount the VHDX , and relocate it to the subfolder (which is what I would do, because I like putting stuff in subfolders!), or change the script.

Hope this helps!
 

My Computer

System One

  • OS
    Windows 8.1, 10
David - eureka, mark this as solved! I am so sorry to have taken so much of your valuable time for such an oversight - but I do thank you very much for the solution.

Now I can add the other 2 HGST 4TB drives that arrived today in a RAID 5 configuration...
 

My Computer

System One

  • OS
    Win 8.1
Back
Top