Page 1 of 1 1
Topic Options
#195536 - 2009-08-24 12:38 PM Get fixed disks and corresponding data using WMIQuery
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
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.

 Code:
$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 Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
There are two problems:
  1. The UDF works in asynchronous mode, so you don't get an error back when you specify an invalid query.
  2. Your query is invalid - you want to retrieve "DriveType"

Top
#195538 - 2009-08-24 01:59 PM Re: Get fixed disks and corresponding data using WMIQuery [Re: Richard H.]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
Yeah just noticed that after putting it away for an hour.
Will do some updates and post back.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195539 - 2009-08-24 01:59 PM Re: Get fixed disks and corresponding data using WMIQuery [Re: Mart]
Glenn Barnas Administrator Online   content
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
This code works fine.. the "what" argument of "Type" doesn't seem valid on any sytem I've checked.
Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#195540 - 2009-08-24 02:00 PM Re: Get fixed disks and corresponding data using WMIQuery [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
BTW, if you want to see errors, change the query line in the UDF like so:
 Code:
	$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_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1866
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:
 Code:
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
#195542 - 2009-08-24 02:23 PM Re: Get fixed disks and corresponding data using WMIQuery [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
 Originally Posted By: apronk

.....
Although this is only for local systems.


Used this approach before and it works great. Now I need the data from remote systems so in this case this is not the best option.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195543 - 2009-08-24 02:32 PM Re: Get fixed disks and corresponding data using WMIQuery [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1866
Loc: Hilversum, The Netherlands
Or run this script using my RemoteRunAs UDF ;-)
Top
#195544 - 2009-08-24 02:37 PM Re: Get fixed disks and corresponding data using WMIQuery [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
Got several options now. I must be able to pull out some working code. Will post back when I'm done.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195545 - 2009-08-24 03:06 PM Re: Get fixed disks and corresponding data using WMIQuery [Re: Mart]
Glenn Barnas Administrator Online   content
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
I gave up entirely on remote query via WMI. My latest version of SIT (System Interrogation Tool) uses TCP socket connections to make requests and return data that's gathered, processed, and formatted locally. MUCH faster! SIT used to take almost a minute to initially gather 50-60 pieces of information, mostly via WMI calls. Using a combination of local registry, WMI, and FSO, the initial query now completes in about 10 seconds.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 59 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.033 seconds in which 0.011 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org