Getting HD info with no floppy access

134 views
Skip to first unread message

Jim Taylor

unread,
Jul 14, 2002, 12:45:49 AM7/14/02
to
When I execute the following command on my W2k system, the floppy is
accessed, which is something I don't want. How can this be stopped?

wbemdump /Q root\cimv2 WQL "SELECT * FROM Win32_LogicalDiskToPartition"

I downloaded the SDK just last night but it appears that this class is the
only one that can be used to find out what logical drives are on each hard
drive _and_ in what order. Is there a better way? Having to sort things
out by looking at the starting address for each logical disk could get a
little messy.

--
Thanks,
Jim

Aaron Bertrand [MVP]

unread,
Jul 14, 2002, 11:33:32 PM7/14/02
to
adding...

WHERE DriveType=3

...works for many Disk-related queries. This will restrict it to physical
hard disks (though with at least one of the queries, there's still access
noise, but not quite as annoying as the floppy access).

--
www.aspfaq.com / www.perfhound.com

"Jim Taylor" <james.taylor@att..net> wrote in message
news:re02jukipga374h5j...@4ax.com...

Jim Taylor

unread,
Jul 15, 2002, 1:41:10 AM7/15/02
to
On Sun, 14 Jul 2002 23:33:32 -0400, "Aaron Bertrand [MVP]"
<aaronATaspfaq.com> wrote:

> adding...
>
> WHERE DriveType=3
>
> ...works for many Disk-related queries. This will restrict it to physical
> hard disks (though with at least one of the queries, there's still access
> noise, but not quite as annoying as the floppy access).

Thanks, but that won't work for Win32_LogicalDiskToPartition and I haven't
found anything else that I can use to get the very basic HD information I
need. All I want is to find out how each physical hard drive is
partitioned and how the drive letters are assigned (what you can see at a
glance with Disk Management), all without floppy access. I guess that's
asking a little too much of WMI. :(

--
Jim

[MS] Scott McNairy

unread,
Jul 15, 2002, 1:38:56 PM7/15/02
to
Here is a possible workaround:

select * from win32_logicaldisk where drivetype = 3

store the obj.path_.relpath to a variable

select * from win32_diskpartition store the object path to a variable like
above, this query does not cause floppy drive access.

// if this next call succeeds you will have a object that you are looking
for without floppy access.
objPath = concatonate the two variables escaping the " and the \ with either
\" or \\ so that you have a valid object path for the
Win32_LogicalDiskToPartition.

set obj = svc.Get(yourConcatonatedPath)

--
[MS] Scott McNairy
WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Jim Taylor" <james.taylor@att..net> wrote in message

news:tun4ju8s9b7s6lnhd...@4ax.com...

[MS] Scott McNairy

unread,
Jul 18, 2002, 3:29:18 PM7/18/02
to
Here is the script that works around the floppy access for you.


'// helper function to fix the path up so that it can be used in a future
getObject operation
Function FixPath(byref sPathDisk, byref sPathPart)
sTemp = "Win32_LogicalDiskToPartition.Antecedent=" & chr(34) &
replace(sPathPart,chr(34), "\" & chr(34)) & chr(34) & "," & "Dependent=" &
chr(34) & replace(sPathDisk,chr(34), "\" & chr(34)) & chr(34)
Fixpath = sTemp
end function

'// get the service
set svc = getObject("winmgmts:\\scotmc3\root\cimv2")


'// Get the LogicalDisk's Path
set objEnumLogicalDisk = svc.execQuery("select * from win32_LogicalDisk
where drivetype = 3", "WQL", 0)

'// get the DiskPartition's path
set objEnumDiskPartition = svc.execQuery("select * from
win32_diskpartition", "WQL", 0)


'// associate the two sets
for each objLogicalDisk in objEnumLogicalDisk

for each objDiskPartition in objEnumDiskPartition


' this is expected to fail once in a while since we are concatonating a
possible path to avoid hitting the floppy
on error resume next
set objLogicalDiskToPartition =
svc.get(Fixpath(objLogicalDisk.Path_.relpath,
objDiskPartition.path_.relpath), 0)
if err.number = 0 then
wscript.echo "We got the Win32_LogicalDiskToPartition object and it looks
like this without touching the floppy"

wscript.echo objLogicalDiskToPartition.path_.relpath
on error goto 0:
wscript.echo objLogicalDiskToPartition.getObjectText_(1)

else
err.clear
end if


next
next

--
[MS] Scott McNairy
WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"[MS] Scott McNairy" <sco...@online.microsoft.com> wrote in message
news:3d3308b0$1...@news.microsoft.com...

Jim Taylor

unread,
Jul 19, 2002, 1:55:24 PM7/19/02
to
On Thu, 18 Jul 2002 12:29:18 -0700, "[MS] Scott McNairy"
<sco...@online.microsoft.com> wrote:

> Here is the script that works around the floppy access for you.

Thanks a lot Scott, you obviously know your stuff. There's no way I could
have written that on my own any time soon. I need to run down some better
docs, I didn't know that a couple of the WMI commands you used even
existed.

To be honest, now that I see it, I think it's debatable which way is
better, hitting the floppy or doing it like in the script. My system has 3
partitions and 5 logical drives which causes the script to hit the HD 15
times and take almost 2 seconds. Good thing I don't have say 6 partitions
and 8 logical drives. But on an average system I guess the no floppy way
would be better.

I got a jscript version working but getting FixPath() right did give me a
hard time. mainly because I started off trying to do it like you did with
vbscript when a much simpler way works for jscript.

Still some work to do to extract drive letter assignments from it.
This seems to be a lot harder than it should be.

--
Jim

function FixPath(sPathDisk, sPathPart) {
var sTemp = "Win32_LogicalDiskToPartition.Antecedent=\'"
+ sPathPart + "\',Dependent=\'"
+ sPathDisk + "\'";
// WScript.echo("sTemp = ", sTemp);
return (sTemp);
}

var svc = GetObject("winmgmts:{impersonationLevel=impersonate}"
+ "\\\\.\\root\\cimv2");
var objEnumLogicalDisk = svc.execQuery
("select * from win32_LogicalDisk where drivetype = 3", "WQL", 0);
var objEnumDiskPartition = svc.execQuery
("select * from win32_diskpartition", "WQL", 0);
var d, p, Disk, Partition;
d = new Enumerator(objEnumLogicalDisk);
for(;!d.atEnd();d.moveNext()){
Disk = d.item();
p = new Enumerator(objEnumDiskPartition);
for(;!p.atEnd();p.moveNext()){
Partition = p.item();
try{
var objLogicalDiskToPartition = svc.get
(FixPath(Disk.path_.relpath, Partition.path_.relpath), 0);
WScript.echo("We got the Win32_LogicalDiskToPartition object and"
+ " it looks like this without touching the floppy");
WScript.echo(objLogicalDiskToPartition.path_.relpath);
WScript.echo(objLogicalDiskToPartition.getObjectText_(1));
}
catch(e) {
}
}
}

Reply all
Reply to author
Forward
0 new messages