The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: sinsi on May 06, 2012, 05:43:18 AM

Title: Drive in use
Post by: sinsi on May 06, 2012, 05:43:18 AM
Is there any way of telling if a drive is in use? I have been playing around with VHDs and it seems that my code will detach one while it is in use (in this one case, by chkdsk).
Like when you try and 'safely remove' a USB drive and Windows tells you it's in use and try again.

Some sort of IOCTL? Searching MSDN is torture.
Title: Re: Drive in use
Post by: donkey on May 06, 2012, 06:42:50 AM
Hi Sinsi,

No IOCTRL in that one, you use the Pdhxxx performance data query api, as I remember the ones your concerned with are 'PhysicalDisk' (234) and '% Disk Time' (200) though I could be having a memory problem with that. I wrote one once but deleted it as mostly useless, the concept is simple though.

first verify that the names I gave above are right using PdhLookupPerfNameByIndex and the index numbers (in brackets)
Next create a counter path using PdhMakeCounterPath
Open a query and add a counter using PdhOpenQuery/PdhAddCounter
then poll the query using PdhCollectQueryData/PdhGetFormattedCounterValue

You'll probably want to set up a timer to poll the query using SetTimer or some such. I can probably throw something together if I get time before I leave for BC.

Edgar
Title: Re: Drive in use
Post by: MichaelW on May 06, 2012, 07:28:31 AM
I have some doubts that the PhysicalDisk performance object would report anything for a virtual drive, but if works like a HDD monitor, it should be fairly easy to code.
Title: Re: Drive in use
Post by: farrier on May 06, 2012, 07:48:46 PM
http://www.masm32.com/board/index.php?topic=4624.0

???

hth


I remember being impressed when this first came out!

farrier
Title: Re: Drive in use
Post by: dedndave on May 07, 2012, 03:59:38 AM
unfortunately - the info is lost....
Quote[attachment deleted by admin]

a lot of good learning material has disappeared   :(
Title: Re: Drive in use
Post by: ragdog on May 07, 2012, 04:58:08 AM
Yes Dave i have me wonder Yesterday

I look often on this attachment :'(

I have ask Hutch

Quotedatabase size and disk storage on the entire site was so big

Ok Hutch would make a Achive like
http://www.masm32au.com/files/index.php

Or Masm32Board.zip

and we can download it :wink

Ok The HDDMon project have i saved on my drive and i upload the complete project from this site
http://www.masm32.com/board/index.php?topic=4624.0

HDDMon_Project
http://www.sendspace.com/file/bpwgil

Greets,
Title: Re: Drive in use
Post by: dedndave on May 07, 2012, 05:03:51 AM
that isn't great, either, because we won't know which files go with which threads
they should have made a note like this
Quote[test21.zip attachment deleted by admin]
or - probably better
Quote[archive10025.zip attachment deleted by admin]

now - it's fucked
unless Hutch wants to go through the old forum back-ups

that really diminishes the value of the forum
i - and i am sure many others - used to use it as a reference
without the attachments - those threads are mostly useless
Title: Re: Drive in use
Post by: ragdog on May 07, 2012, 05:09:38 AM
Quotethat really diminishes the value of the forum
i - and i am sure many others - used to use it as a reference
without the attachments - those threads are mostly useless

I agree with you
I used often as  reference :'(


A complete zip archive is better

Dave for the HddMon project look on my old post
http://www.masm32.com/board/index.php?topic=18816.msg159383#msg159383
Title: Re: Drive in use
Post by: dedndave on May 07, 2012, 05:15:14 AM
thanks   :U
Title: Re: Drive in use
Post by: sinsi on May 07, 2012, 11:05:16 AM
Thanks ragdog, that looks interesting, but I don't want to go off on a tangent  :bg
The problem is that a file can be open on the volume but no activity. I've looked at sysinternals 'handle' but it seems to use a driver, way more than I need.

I think I will just ask the user whether to go ahead with a detach.
Interesting thing, to attach you need admin privileges, for detach no elevation required.
Title: Re: Drive in use
Post by: dedndave on May 07, 2012, 01:34:46 PM
QuoteInteresting thing, to attach you need admin privileges, for detach no elevation required.

that makes sense in a way   :P
but - having an admin password doesn't mean you know the drive is safe - lol
just because you can afford to buy a Mercedes, doesn't mean you can drive one