I am running Win7 pro and the Microsoft Virtual XP.
The virtual machine uses a separate VHD for it's user generated data, a small 1 Gig fixed size virtual harddisk.

I attach this VHD in read-only mode to the host while the Virtual XP is running for backup purposes. This is done via Computer management > Storage > Disk management.

Suddenly, it won't let me do this anymore with the virtual machine running. Error: the process cannot access the file because it is being used by another process.

The error makes sense, but what baffles me is that it used to work fine for weeks. I am not aware of any changes in my setup. I did use google, but it returns results about interfering virtual DVD drives (I have none) or too big VHDs (mine is just a gig in size).

So, I wonder if mounting a VHD in use by the virtual machine is actually supported, and why the h*ll it used to let me do this?

Thanks,

Dani AI

Generated

Short answer: the host is being prevented from opening the same VHD because some process (virtually always the Virtual PC process) holds the file in a way that disallows the host from getting the access it needs. That explains the "file is being used" message and why you see handles in vpc.exe. It used to work when the VM process allowed shared/read-only access; if that changed (update, VM options, or how the disk is being used) the host will no longer be able to attach the file while the VM runs.

Practical checks (non-destructive)

  • Use Sysinternals Process Explorer (Run as admin -> Find -> "Find Handle or DLL") to confirm which process has the VHD open. If vpc.exe is the owner and it has an exclusive lock, host attach will fail. For a quick host attempt you can also try DiskPart from an elevated prompt:
    diskpart
    select vdisk file="C:\path\to\your.vhd"
    attach vdisk readonly

    If DiskPart fails with the same error, the file is locked by the VM/service.

Safe workarounds

  • The safest and simplest approach is to shut down the VM, attach or copy the VHD on the host, then restart the VM.
  • If you must copy while the guest is running, do the backup from inside the guest (copy to a network share on the host or enable Virtual PC shared folders) so the guest can quiesce files. Host-side mounting of a running VM's disk can produce inconsistent data even if attached read-only.
  • Avoid forcibly closing handles in Process Explorer; that can crash the VM and corrupt the VHD.

If you want to dig deeper, check for recent Windows/Virtual PC updates, antivirus or backup software that might have changed file-sharing behavior, and whether the VM is using undo/differencing disks (those change how the VHD is accessed). As and suggested, simple reboots can help in transient cases, but since you already tried that, the Process Explorer/DiskPart checks above will confirm whether the lock is coming from Virtual PC or something else.

Recommended Answers

All 3 Replies

simple things first, reboot the pc
(dumps all running processes hence releases them for use...)

First reboot your PC and then check again.

Thanks Temmu and avadhraj, but naturally I have rebooted both the VM and the host machine; even twice. Same result, just won't let me attach anymore.

The problem is, I cannot attach the VHD with the Virtual PC running, the vdh file is opened with two handles by vpc.exe, which makes sense of course.

But the surprising thing is, this USED TO WORK for several weeks!
Still not sure if this is by design, or an error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.