r3h1996

Filter WMI DiskDrive

7 posts in this topic

#1 ·  Posted (edited)

Good evening forum,

Looking for a bit of help with WMI DiskDrive.

I need to be able to filter my results based on the SCSIBus. I am able to do this in VBScript but cannot for the life of me figure out how to do it in AutoIt.

This is what I do in VBScript...

I added

Where SCSIBus=0

after the execquery.

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("ROBERT-PC")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive Where SCSIBus=0", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo "Model: " & objItem.Model
      WScript.Echo "SCSIBus: " & objItem.SCSIBus
      WScript.Echo
   Next
Next


Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm: 
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

This only returns the results of SCSIBus 0 (SATA port 0 which my C: drive is connected to.)

I need to be able to do the exact same in AutoIt.

Can someone point me in the right direction ?

Thanks :D

Edited by r3h1996

Share this post


Link to post
Share on other sites



ObjCreate Funtion.

 

Saludos


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

r3h1996,

The WQL will look like this...

$colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive where SCSIbus = 0")

Post what you've tried for more help.

kylomas

Edit: You might have a look at the AutoIt version of scriptomatic in the "Examples" forum.

Edited by kylomas
additional info

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

...and no need to select * if you are only using model.  I dont know why your script also echoes SCSIbus seeing as how you know its value from your where clause.

$colItems = $objWMIService.ExecQuery("Select Model from Win32_DiskDrive Where SCSIbus = 0" , "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

ObjCreate Funtion.

 

Saludos

Could you explain a bit more clearly Danyfirex ?

r3h1996,

The WQL will look like this...

$colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive where SCSIbus = 0")

Post what you've tried for more help.

kylomas

Edit: You might have a look at the AutoIt version of scriptomatic in the "Examples" forum.

I haven't tried anything note worthy. I tried a couple of basic bits but nothing has worked.

...and no need to select * if you are only using model.  I dont know why your script also echoes SCSIbus seeing as how you know its value from your where clause.

$colItems = $objWMIService.ExecQuery("Select Model from Win32_DiskDrive Where SCSIbus = 0" , "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

 

Hi boththose, I wont only be using model, I just shortened the script until I figure out how to get it to work the way I want. Having the SCSIBus echo as well as an extra check. This will later lead to a ConsoleRead which will need the SCSIBus also as a second check.

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
      $Output = $Output & "BytesPerSector: " & $objItem.BytesPerSector & @CRLF
      $strCapabilities = $objItem.Capabilities(0)
      $Output = $Output & "Capabilities: " & $strCapabilities & @CRLF
      $strCapabilityDescriptions = $objItem.CapabilityDescriptions(0)
      $Output = $Output & "CapabilityDescriptions: " & $strCapabilityDescriptions & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "CompressionMethod: " & $objItem.CompressionMethod & @CRLF
      $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
      $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
      $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output = $Output & "DefaultBlockSize: " & $objItem.DefaultBlockSize & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
      $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
      $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
      $Output = $Output & "ErrorMethodology: " & $objItem.ErrorMethodology & @CRLF
      $Output = $Output & "FirmwareRevision: " & $objItem.FirmwareRevision & @CRLF
      $Output = $Output & "Index: " & $objItem.Index & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "InterfaceType: " & $objItem.InterfaceType & @CRLF
      $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
      $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF
      $Output = $Output & "MaxBlockSize: " & $objItem.MaxBlockSize & @CRLF
      $Output = $Output & "MaxMediaSize: " & $objItem.MaxMediaSize & @CRLF
      $Output = $Output & "MediaLoaded: " & $objItem.MediaLoaded & @CRLF
      $Output = $Output & "MediaType: " & $objItem.MediaType & @CRLF
      $Output = $Output & "MinBlockSize: " & $objItem.MinBlockSize & @CRLF
      $Output = $Output & "Model: " & $objItem.Model & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "NeedsCleaning: " & $objItem.NeedsCleaning & @CRLF
      $Output = $Output & "NumberOfMediaSupported: " & $objItem.NumberOfMediaSupported & @CRLF
      $Output = $Output & "Partitions: " & $objItem.Partitions & @CRLF
      $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
      $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
      $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
      $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
      $Output = $Output & "SCSIBus: " & $objItem.SCSIBus & @CRLF
      $Output = $Output & "SCSILogicalUnit: " & $objItem.SCSILogicalUnit & @CRLF
      $Output = $Output & "SCSIPort: " & $objItem.SCSIPort & @CRLF
      $Output = $Output & "SCSITargetId: " & $objItem.SCSITargetId & @CRLF
      $Output = $Output & "SectorsPerTrack: " & $objItem.SectorsPerTrack & @CRLF
      $Output = $Output & "SerialNumber: " & $objItem.SerialNumber & @CRLF
      $Output = $Output & "Signature: " & $objItem.Signature & @CRLF
      $Output = $Output & "Size: " & $objItem.Size & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
      $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
      $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
      $Output = $Output & "TotalCylinders: " & $objItem.TotalCylinders & @CRLF
      $Output = $Output & "TotalHeads: " & $objItem.TotalHeads & @CRLF
      $Output = $Output & "TotalSectors: " & $objItem.TotalSectors & @CRLF
      $Output = $Output & "TotalTracks: " & $objItem.TotalTracks & @CRLF
      $Output = $Output & "TracksPerCylinder: " & $objItem.TracksPerCylinder & @CRLF
   Next
   ConsoleWrite($Output)
   FileWrite(@TempDir & "\Win32_DiskDrive.TXT", $Output )
   Run(@Comspec & " /c start " & @TempDir & "\Win32_DiskDrive.TXT" )
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DiskDrive" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Here is the code from AutoIt Scriptomatic but as you probably know you cant just put "where" into the code like VBScript so I need an AutoIt equivalent of "Where"

Share this post


Link to post
Share on other sites

Its not autoit, its WQL.   and it is the same.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Local $rtn = Example(@ComputerName)
MsgBox(0, '', $rtn)
Exit

Func Example($sComputer)
    Local $objWMI = ObjGet('winmgmts:\\' & $sComputer & '\root\CIMV2')
    Local $objItems = $objWMI.InstancesOf('Win32_DiskDrive Where SCSIBus="0"')

    If Not IsObj($objItems) Then Return -1; invalid object
    If Not $objItems.Count Then Return -2; nothing found

    For $objItem In $objItems
       Return $objItem.Model
    Next
EndFunc

 


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now