#195536 - 2009-08-24 12:38 PM
Get fixed disks and corresponding data using WMIQuery
|
Mart
KiX Supporter
Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
|
Been staring at this for some time now and cant find where it goes wrong. The script below fails to get the type of the drive.
According to the comment in the WMIQuery UDF it should be possible to give it a where parameter. That is what the "Caption", $drive is supposed to do but I get empty results. Anyone got a bright idea?
Maybe it is something small and stupid and I’ve been staring at it for to long so I’m just not seeing it.
$computer = "System1"
$drives = WMIQuery("Caption","Win32_LogicalDisk", $computer)
For Each $drive in $drives
$type = WMIQuery("Type","Win32_LogicalDisk", $computer, "Caption", $drive)
If $type[0] = 2
;0 = Unknown type of drive, 1 = Removable drive, 2 = Fixed drive
;3 = Network drive, 4 = CD/DVD drive, 5 = RAM Disk
?"Fixed disk"
EndIf
Next
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#195537 - 2009-08-24 01:55 PM
Re: Get fixed disks and corresponding data using WMIQuery
[Re: Mart]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
There are two problems:
- The UDF works in asynchronous mode, so you don't get an error back when you specify an invalid query.
- Your query is invalid - you want to retrieve "DriveType"
|
Top
|
|
|
|
#195540 - 2009-08-24 02:00 PM
Re: Get fixed disks and corresponding data using WMIQuery
[Re: Richard H.]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
BTW, if you want to see errors, change the query line in the UDF like so:
$objEnum = $SystemSet.ExecQuery($sQuery,"WQL",0)
Useful for small queries, but may cause issues for very long / large queries.
|
Top
|
|
|
|
#195541 - 2009-08-24 02:09 PM
Re: Get fixed disks and corresponding data using WMIQuery
[Re: Richard H.]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Btw, if you want a faster approach then WMI, I've written a UDF for myself a long time ago using the File System Object:
Function GetDrives
Dim $fso, $DriveCol, $Drive, $drv
$fso = CreateObject("Scripting.FileSystemObject")
$DriveCol = $fso.Drives
For Each $Drive in $DriveCol
$drv = $fso.GetDrive($Drive)
? "Drive: "+$drv
If $drv.DriveType <> 4
? "Volume: "+$drv.VolumeName
? "Total: "+$drv.TotalSize
? "Free: "+$drv.FreeSpace
EndIf
? "Type: "+$drv.DriveType ;1 = Removable, 2 = HDD, 3 = Network, 4 = CD
?
Next
EndFunction
Although this is only for local systems.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 382 anonymous users online.
|
|
|