Jump to content

WMI to Excel


Recommended Posts

Hello, 

I'm trying to get some data from WMI and output a particular Object Value to an Excel Cell. I have used the scriptomatic to check out the WMI code but I'm a bit stuck on the Exporting a portion of the data to an Excel Cell. For Example. I am querying Win32_ComputerSystemProduct. I want to get the IdentifyingNumber and export the Value to "B2" in excel. Im new to Autoit and have searched the forums but cannot find help. Can someone at least give me assistance on what I need to do to export the value to excel. 

 

Thank you in advance, 

John

Link to comment
Share on other sites

  • Moderators

Hi, @beaswax19. Here is a quick and dirty to give you an idea of how you could go about it. If you're planning on doing more with the resultant spreadsheet, I would declare all the variables ahead of time.

#include <Excel.au3>

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
Local $ID

$oWMI = ObjGet("winmgmts:\\.\root\CIMV2")
$oItems = $oWMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($oItems) then
       For $item In $oItems
          $ID = $item.IdentifyingNumber
       Next
    Else
        MsgBox($MB_OK, "My Test", "Unable to query WMI")
    EndIf

    If $ID <> "" Then
        $oExcel = _Excel_Open()
        $oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\my.xls")
        _Excel_RangeWrite($oWorkbook, Default, $ID, "B2")
    Else
        MsgBox($MB_OK, "My Test", "Identifying Number not found")
    EndIf

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

×
×
  • Create New...