Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disable a vhd disk using WMI

45 views
Skip to first unread message

Anthony Jones

unread,
Jan 17, 2008, 5:17:21 AM1/17/08
to
People,

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


Owen Gilmore

unread,
Jan 17, 2008, 1:47:49 PM1/17/08
to

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

Message has been deleted

Pegasus (MVP)

unread,
Jan 18, 2008, 7:41:06 AM1/18/08
to

"Anthony Jones" <A...@yadayadayada.com> wrote in message
news:OFBsEwcW...@TK2MSFTNGP04.phx.gbl...
> "Owen Gilmore" <aogi...@gmail.com> wrote in message
> news:0173515b-d6f9-46bc...@l1g2000hsa.googlegroups.com...
> Thanks that allowed me to create a simple batch file to disable the
> existing
> drive then unplug it. Unfortunately it turns out that the Instance ID for
> the drive changes each time I use vhdmount to plug it in again. Hence the
> batch file only works once.
>
> I'm going to need some creative script to find that ID and dynamically
> generate the batch file then execute it.
>
> This is getting ugly :(

>
>
>
> --
> Anthony Jones - MVP ASP/ASP.NET

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.


Anthony Jones

unread,
Jan 18, 2008, 9:09:38 AM1/18/08
to
"Pegasus (MVP)" <I....@fly.com.oz> wrote in message
news:OANRm9cW...@TK2MSFTNGP04.phx.gbl...

>
> "Anthony Jones" <A...@yadayadayada.com> wrote in message
> news:OFBsEwcW...@TK2MSFTNGP04.phx.gbl...
> > "Owen Gilmore" <aogi...@gmail.com> wrote in message
> > news:0173515b-d6f9-46bc...@l1g2000hsa.googlegroups.com...
> > On Jan 17, 2:17 am, "Anthony Jones" <A...@yadayadayada.com> wrote:
> >>
> >>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-9ce67
f
> > 3e0240/devcon.exe
> >>
> >
> > Thanks that allowed me to create a simple batch file to disable the
> > existing
> > drive then unplug it. Unfortunately it turns out that the Instance ID
for
> > the drive changes each time I use vhdmount to plug it in again. Hence
the
> > batch file only works once.
> >
> > I'm going to need some creative script to find that ID and dynamically
> > generate the batch file then execute it.
> >
> > This is getting ugly :(
> >
> >
> >
>
> 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,

Pegasus (MVP)

unread,
Jan 18, 2008, 9:43:55 AM1/18/08
to

"Anthony Jones" <A...@yadayadayada.com> wrote in message
news:u50WEvdW...@TK2MSFTNGP04.phx.gbl...

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.


Anthony Jones

unread,
Jan 18, 2008, 11:24:13 AM1/18/08
to
"Pegasus (MVP)" <I....@fly.com.oz> wrote in message
news:%23CSmRCe...@TK2MSFTNGP02.phx.gbl...

Thanks, that's got it.

0 new messages