Jump to content

Function WMI


vince76000
 Share

Recommended Posts

Sorry for my english, I'm french

I don't know if this function already exits but i created one :

Func WMI($strComputer,$Query)

    Dim $objLocator =  ObjCreate("WbemScripting.SWbemLocator")
    dim $objService = $objLocator.ConnectServer($strComputer, "root\cimv2")
    Dim $Jobs = $objService.ExecQuery($Query)
    return $Jobs
EndFunc

An example for use it :

This script send you all services names in a remote computer :

Dim $Service
Dim $string = ""
Dim  $table = WMI("127.0.0.1","SELECT * FROM Win32_Service")



For $Service in $table
     $string = $string & " " & $Service.Name
Next
 
MsgBox(0, "Name: ", $string)
 
 
 
 
Func WMI($strComputer,$Query)
    

    Dim $objLocator =  ObjCreate("WbemScripting.SWbemLocator")
    dim $objService = $objLocator.ConnectServer($strComputer, "root\cimv2")
    Dim $table = $objService.ExecQuery($Query)
    
    return $table
    
EndFunc

regards

Vincent Lassauce

Edited by vince76000
Link to comment
Share on other sites

You pass $strComputer into your function, but then immediately set it to ".", which I believe is the current computer. So your function, given any remote computer name, would only return data from the current computer.

Did you actually try getting data from a remote computer with this function, as written here?

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

  • 1 year later...

I worked a little around this code and made this finally :

#Include <date.au3>
#include <file.au3>

$log = FileOpen("softwarelist.txt", 2)
FileWrite($log, "================================================" & @CRLF)
FileWrite($log, "Software List " & @YEAR & "/" & @MON & "/" & @MDAY & " - at " & @HOUR & ":" & @MIN  & ":" & @SEC & @CRLF)
FileWrite($log, "================================================" & @CRLF & @CRLF)
FileWrite($log, "------------------------------------------------------------------------------")

Dim $Product
Dim $string = ""
Dim $table = WMI("127.0.0.1","SELECT * FROM Win32_Product")

For $Product in $table
    $string = $string & @CRLF & "Description. " & $Product.Description & @CRLF & "Ver. " & $Product.Version & @CRLF & "Vendor. "  & $Product.Vendor & @CRLF & "------------------------------------------------------------------------------"
Next
FileWrite($log, $string)

FileWrite($log, @CRLF & @CRLF & "================================================" & @CRLF & "End of all treatments." & @CRLF & "================================================")
FileClose($log)

Func WMI($strComputer,$Query)
    Dim $objLocator =  ObjCreate("WbemScripting.SWbemLocator")
    dim $objService = $objLocator.ConnectServer($strComputer, "root\cimv2")
    Dim $table = $objService.ExecQuery($Query)
    return $table
EndFunc

The includes were to add some requests to ini files in a first time. As date include.

Anyway, the primary code was great. I just added some work around.

Link to comment
Share on other sites

Don't open old topics for no reason! AutoIt Scriptomatic generates WMI scripts for you.

Not to mention that it would be better if the function was

Func WMI($Query, $strComputer = "localhost" )

There is also a link to the compiled version of ScriptoMatic in my sig.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Don't open old topics for no reason! AutoIt Scriptomatic generates WMI scripts for you.

Just 'cause he created a script that does something that has been coded before (and it's not as robust) doen't mean he's opening an old topic; it's just his version of a UDF to perform WMI queries. I have done the same thing in my time and will post the code here when/if I find it.

edit:

By far - inferior to the scripto tool, but I like hands on.

http://www.autoitscript.com/forum/index.ph...st&p=389577

Edited by spudw2k
Link to comment
Share on other sites

Just 'cause he created a script that does something that has been coded before (and it's not as robust) doen't mean he's opening an old topic; it's just his version of a UDF to perform WMI queries. I have done the same thing in my time and will post the code here when/if I find it.

A quick search for Win32_Product reveals this has been covered many times.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...