I've got a vhd file which I mount using vhdmount /p on Windows XP running on
my laptop. The problem is that this is incompatible with hibernation which
I use a lot when travelling.
Unfortunately whilst the disk device is added as a plug in it doesn't appear
in the Safely Remove Hardware dialog which I can easily access from the icon
in the system tray.
I need to find my way to the device manager first to disable the disk then I
can use vhdmount to 'unplug' the device. Only then can I hibernate.
I'd like to script this process since I will do it quite frequently.
So far my investigations into using WMI has drawn a blank, it seems that
Win32_DiskDrive doesn't support a .Disable() method.
Any one know how I can do this with WMI or _any_ other approach such as
WinAPI, .NET or a different COM library, I don't realy mind how its done.
Cheers,
--
Anthony Jones - MVP ASP/ASP.NET
See if devcon.exe works for you. This was mentioned in a thread
recently about disabling usb devices. Here is the download location,
http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe
Shouldn't be too hard. Let's have a look at the relevant section
of c:\device.txt, generated with this command:
devcon hwids "*" > c:\device.txt
both before and after you run vhdmount.
I'm hoping I know what the 'relevant section' is. With only my single HD
I've only got this present (there is also the DVD on IDE\...).
IDE\DISKSAMSUNG_HM040GI_________________________AA100-12\5&2015AABE&0&0.0.0
Name: SAMSUNG HM040GI
Hardware ID's:
IDE\DiskSAMSUNG_HM040GI_________________________AA100-12
IDE\SAMSUNG_HM040GI_________________________AA100-12
IDE\DiskSAMSUNG_HM040GI_________________________
SAMSUNG_HM040GI_________________________AA100-12
GenDisk
Compatible ID's:
GenDisk
also this may be relevant
STORAGE\VOLUME\1&30A96598&0&SIGNATURE41AB2316OFFSET7E00LENGTH950A58200
Name: Generic volume
Hardware ID's:
STORAGE\Volume
and this:-
ROOT\SYSTEM\0003
Name: Microsoft Virtual Server Storage Bus
Hardware ID's:
root\vhdbus
There is nothing else seems related to Disks such SCSI etc which is
understandable.
After vhdmount /p /f "c:\vhds\mydisk.vhd" this appears in the output:-
SCSI\DISK&VEN_MS&PROD_VIRTUAL_SERVER&REV_1.0\2&35135AAD&0&000000
Name: MS Virtual Server SCSI Disk Device
Hardware ID's:
SCSI\Disk______MS__Virtual_Server1.0_
SCSI\Disk______MS__Virtual_Server
SCSI\Disk______MS
SCSI\______MS__Virtual_Server1
______MS__Virtual_Server1
GenDisk
Compatible ID's:
SCSI\Disk
SCSI\RAW
also this appears (I guess this relates to the partition on the disk):-
STORAGE\VOLUME\1&30A96598&0&SIGNATURE5838EA08OFFSET7E00LENGTH3E430000
Name: Generic volume
Hardware ID's:
STORAGE\Volume
after:-
devcon disable
SCSI\DISK&VEN_MS&PROD_VIRTUAL_SERVER&REV_1.0\2&35135AAD&0&000000
(I get all sort of nonsense from CMD re the & in the name but devcon does
disable the device).
Now device.txt doesn't list the STORAGE\VOLUME above but the SCSI\DISK is
still present.
Follow that with:-
vhdmount.exe -u "c:\vhds\mydisk.vhd"
and the SCSI\DISK disappears
Now redo the vhdmount -p -f "c:\vhds\mydisk.vhd"
and the SCSI\DISK reappears as:-
SCSI\DISK&VEN_MS&PROD_VIRTUAL_SERVER&REV_1.0\2&5629699&0&000000
Name: MS Virtual Server SCSI Disk Device
Hardware ID's:
SCSI\Disk______MS__Virtual_Server1.0_
SCSI\Disk______MS__Virtual_Server
SCSI\Disk______MS
SCSI\______MS__Virtual_Server1
______MS__Virtual_Server1
GenDisk
Compatible ID's:
SCSI\Disk
SCSI\RAW
You'll note that the instance ID has changed (the 35135AAD in the original
has become 5629699).
The STORAGE\VOLUME also reappears but its ID remains unchanged (which I
guess this is how the OS knows it can give it the S: drive letter I had
previously assigned it).
The volume is NTFS formatted if thats relevant.
It's gonna take me a while to build some script to handle this, as you can
probably tell I'm way outside my comfort zone with all this device admin
level stuff. ;)
BTW, Does anyone know of a way to hook the 'Preparing to hibernate' state
the system goes through, it would good to place anything I come up with (if
can come up with anything) here. That way if I forget to unload the disk
before press 'off' it will happen automatically.
Cheers,
I suggest you try these commands::
devcon disable "SCSI\Disk______MS__Virtual_Server1.0_"
devcon enable "SCSI\Disk______MS__Virtual_Server1.0_"
By the way, what you call "all sorts of nonsense" is not nonsense at
all - it relates to the command you issued. The device ID you used
had embedded ampersands ("&") which the Command Processor
interpreted as command concatenators. In other words, you tried
to disable all sorts of devices, which could have quite unexpected
consequences. Make sure to enclose your device names with
double quotes to avoid ambiguities.
Thanks, that's got it.