Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Prevent removing attached VHD, from safely removed attached media

16 Feb 2012   #1

W7 64 pro
Prevent removing attached VHD, from safely removed attached media

Hi all,

I was just wondering if anyone knows a way to prevent users from removing a attached VHD from "Safely remove hardware and eject media", We have had multiple users eject the VHD when they are going to unplug their USB and they are ejecting the attached VHD insted.

Any help would be much appreciated.

(Apologies if this is in the wrong section)

My System SpecsSystem Spec
03 Apr 2012   #2

W7 64 pro

Still cant find a solution to this,

I have found the DeviceOverRides in registry "HKLM\SYSTEM\CurrentControlSet\Control\DeviceOverrides"

I added the following keys for each of the Hardware ID's and Compatible ID's of the VHD listed below.


Replaced the "\" with "#". So for example I made the following keys,

Below is the following keys I entered:
Then created the dword "removable" with value "0" inside the "*" key
I did the above for each single "Hardware Ids" for the VHD.

After doing this, It removed the individual entries for each VHD for example both VHD had their own category in Safely Remove Hardware listed below:

Eject Msft Virtual Disk SCSI Disk Device
      - EXAMPLE (D:)
Eject Msft Virtual Disk SCSI Disk Device
      - EXAMPLE (E:)
Eject Msft Virtual Disk SCSI Disk Device
      - EXAMPLE (F:)
After adding the DeviceOverride keys for the hardware Ids of the VHD, It has only recategorized the VHD and it is still removeable,

Under Safely Remove hardware it displays the following:

      -Eject Msft Virtual Disk SCSI Disk Device
      -Eject Msft Virtual Disk SCSI Disk Device
      -Eject Msft Virtual Disk SCSI Disk Device
Does Anyone else know a way to prevent a VHD from being removed/disconnected.

Can't remove/hide "Safely remove hardware" because people frequently bring their own personal USB devices.

Any help would be much appreciated.

My System SpecsSystem Spec
04 Mar 2014   #3

Windows 7 Ultimate 64bit

One thing I've just noticed, not a fix but a workaround.

Currently, even if I safely remove a mounted VHD (which normally would result in a virtual disk drive exception, exclaimed in devmgmt.msc, and the volume would be unmountable until full restart is completed).

If I use VHD Attach's Detach... (ie open the vhd file that's just been removed, then hit Detach) the volume can be remounted again, safely ejected (and detached), remounted....

My System SpecsSystem Spec

12 Mar 2014   #4

Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1

I was asked to stick my nose in here. I don't know if this will help or not...
Is it possible to mount the vhd file as read only when it is being used by a virtual machine?
My System SpecsSystem Spec
14 Mar 2014   #5

Windows 7 Ultimate 64bit

Quote   Quote: Originally Posted by Gandalf View Post
I was asked to stick my nose in here. I don't know if this will help or not...
Is it possible to mount the vhd file as read only when it is being used by a virtual machine?
No, that's re VMware / Virtually hosted volumes using a host like virtualbox or hyper-pc I think.

In this thread I'm talking about native virtual hard drives, new windows 7 feature, and shared virtual volumes.

Differencing disks impose massively restrictive and convoluted pre-requisites, imho. you can't have a volume as a single file, so you can't easily copy it, the parent needs to be read-only, and (here's the deal-breaker) the updates need to be deployed on all the children. Smells like virtual obese teen spirit.

the specific issue in this thread is how attached volumes behave with windows 7. These are not read-only volumes, and they cannot be safely removed... well, they can, but you'll get an exclamation re the drive in device manager, and you won't be able to re-attach the volume... unless you detach it using VHD Attach, for example. Think that's a workaround I mentioned here earlier, if not.. now you know (hopefully).

Thanks for the interest though
My System SpecsSystem Spec
18 Mar 2014   #6

Windows 7 Ultimate 64bit

Good news I think. I parked this issue a while back but stumbled on a successful search result whilst investigating removing the removable bit from volumes... all credit goes to Helge Klein

The enumerated data is recreated on reboot, so a script (batch) is needed to write the registry entry.

I just tested by:

using regedit to navigate to the (virtual) volume's Key (use devmgmt.msc and properties on the device, populate the volume to identify and capacity and confirm you have the right volume if you have several... Think I'll modify the "friendly name" too...) captured from the device instance path, ie

identify volume

get dev.ID

Find in reg, ie
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SCSI\Disk&Ven_Msft&Prod_Virtual_Disk\2&1f4adffe&0&0 00002

Get permission! (Tip: NirSoft RegOwnership)

Change Capabilities to 2 (decimal)
NB if you get a permission error navigate away from and back to the key, to refresh.

//from inc/api/cfgmgr32.h (WINDDK)
#define CM_DEVCAP_LOCKSUPPORTED (0x00000001)
#define CM_DEVCAP_EJECTSUPPORTED (0x00000002)
#define CM_DEVCAP_REMOVABLE (0x00000004)
#define CM_DEVCAP_DOCKDEVICE (0x00000008)
#define CM_DEVCAP_UNIQUEID (0x00000010)
#define CM_DEVCAP_SILENTINSTALL (0x00000020)
#define CM_DEVCAP_RAWDEVICEOK (0x00000040)
#define CM_DEVCAP_HARDWAREDISABLED (0x00000100) (default)
#define CM_DEVCAP_NONDYNAMIC (0x00000200)

The change is noticeable straight away..

I'm gonna do some more testing with a dummy volume, to ensure normal detach (using diskmgmt, for example) is not hindered....
My System SpecsSystem Spec
18 Mar 2014   #7

Windows 7 Ultimate 64bit

Interestingly, on reboot, I'm getting the "drive in use" less-than-helpful message when trying to 'safely remove' the drive (after reboot, change not yet persistent, still testing)...

unmount worked, re-rebooting, to see what the crack is... video illustration and script particulars coming soon
My System SpecsSystem Spec
18 Mar 2014   #8

Windows 7 Ultimate 64bit

windows search indexer stops the volume being safely removed... prohibiting volume from being indexed, and modifying and disabling winblows search indexer (one word: everything)

rewriting permissions on 200g data
My System SpecsSystem Spec
18 Mar 2014   #9

Windows 7 Ultimate 64bit

Make drive unremovable : demo

The batch in it's entirety is detailed below, including a new friendly name to help identify the volume in devmgmt etc

:: 1! subinacl /subkeyreg "DEV INSTANCE IN HKEY" /setowner=user
:: 2! subinacl /subkeyreg "DEV INSTANCE IN HKEY" /grant=user
:: 3! reg add "HKEY DEV" /v Capabilities /t REG_DWORD /d 2 /f

subinacl /subkeyreg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SCSI\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\2&1F4ADFFE&0& 000002" /setowner=jonny

subinacl /subkeyreg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SCSI\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\2&1F4ADFFE&0& 000002" /grant=jonny

:: Disable eject hard disk
:: Original value: 100
reg.exe add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SCSI\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\2&1F4ADFFE&0& 000002" /v Capabilities /t REG_DWORD /d 2 /f

reg.exe add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SCSI\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\2&1F4ADFFE&0& 000002" /v FriendlyName /t REG_SZ /d LBS.VHD /f
My System SpecsSystem Spec

 Prevent removing attached VHD, from safely removed attached media

Thread Tools

Similar help and support threads
Thread Forum
Windows Live Mail removing attached photos - why?
Sending photos that I have taken as small sized jpegs the message is not sent - my "sent" copy shows the attachment icons in red with a message that the attachments are of a file type that is considered dangerous and the file has been deactivated. There is a help link but why does this happen -...
Browsers & Mail
External USB HD cannot be safely removed
Cannot safely remove ext-HD Toshiba laptop, Win7 x32, Home Premium Mains powered hub > Ext-USB powered HD. (Western Digital) I am using a third party "USB Safely Remove" app because it gives me more feedback than the Windows default "Safely Remove" USB Safely Remove advise this is a...
Hardware & Devices
Safely removing my external HDD is a chaotic mess.
Hello people, At the beginning of my topic, I would like to mention that this is (maybe) the first post for me, so, if I messed up with any of forums rules, just tell me. Well, let us get into the topic directly: * Problem Define: - Can not do a safely remove to my external hard drive,...
Hardware & Devices
Safely removing old NVIDA drivers ?
I noticed that I have nVidia drivers dating back from a long time ago still on my PC. I was hesitate to just delete the folders in Windows after reading that you can cause problems or false positives etc. With that in mind, how do I remove previous nVidia drivers, I presently have the latest...
Problem with Dell OEM, Can it be removed safely?
Hi, I am trying to put a back up program on my computer. The first clone works but then the second will not because of a problem with the Dell OEM partition. Can that partition be removed without causing any problems with the computer? I don't use anything that I know of from Dell. My computer...
Backup and Restore

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 12:00.
Twitter Facebook Google+