Posted on September 2, 2015 · Posted in Windows 8

Auto-Mount VHD at Startup

In Windows 7 and Windows Server 2008 R2 it became possible to create and mount virtual hard disk files (VHD) directly from Disk Management console. These virtual disks look like separate physical disks in the system and can be used to store any data. An essential disadvantage of these disks is the necessity to mount VHD files manually each time you reboot the system. Only computer administrators have the right to mount VHD files, users do not have these privileges.

In this article we’ll show how to automatically mount a VHD file at the system startup so that virtual hard disks are available for users (with no administrator privileges).

Windows doesn’t have a built-in ability to automatic mounting of VHD files when you reboot your system. Let’s try to implement auto-mount drives using the diskpart and Windows Task Scheduler.

So, create a new text file (C:\Scripts\attach_vhd.txt) containing the following text:

select vdisk file="F:\imagedisk.vhdx"
attach vdisk
assign letter=K

script for mounting vhd disk

F:\imagedisk.vhdx is the full path to the VHD or VHDX disk image
K is a drive letter to be assigned to your VHD disk.

Note. For security purpose, it’s better to change NTFS rights for file attach_vhd.txt, so that users could not change it.

Run Windows Task Scheduler (Taskschd.msc) and create a new Scheduler task (Actions -> Create Task). Configure it as follows: 

automount task

General tab

  • Specify the name of the task (Name)
  • Check Run whether user is logged on or not
  • Check Run with highest privileges

Triggers tab

  • Add a new startup trigger (At Startup) with the default settings

Actions tab

  • Create a new action (New)
  • The action is Start a program
  • Program/script: diskpart
  • As a program argument, specify : /s “C:\Scripts\attach_vhd.txt”

diskpart with arguments

In the Conditions tab, uncheck Start the task only if the computer is on AC power

Save the changes. The system will prompt you to enter the name and the password of the account, from which the task will be run. (The account must have administrator privileges.)

administrator credential

To run the task as SYSTEM, open its properties again and in the General tab click Change User or Group button. In Select User or Group Window, specify system and save the changes.

run task from system account

At the next startup, this VHD disk will be automatically mounted.

vhd disk in managment console

Note. As a rule, the disk appears in the list of available disks in about 30-60 seconds after the startup.

Related Articles