News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Drive in use

Started by sinsi, May 06, 2012, 05:43:18 AM

Previous topic - Next topic

sinsi

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.
Light travels faster than sound, that's why some people seem bright until you hear them.

donkey

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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

MichaelW

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.
eschew obfuscation

farrier

http://www.masm32.com/board/index.php?topic=4624.0

???

hth


I remember being impressed when this first came out!

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

dedndave

unfortunately - the info is lost....
Quote[attachment deleted by admin]

a lot of good learning material has disappeared   :(

ragdog

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,

dedndave

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

ragdog

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

dedndave


sinsi

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.
Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

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