Sign in to follow this  
Followers 0
ripdad

_WMI_InstancesOf_v2.25

4 posts in this topic

#1 ·  Posted (edited)

This function (version 1), was developed solely for applications I needed it for.
It was only tested with Class names that was needed in those scripts.

And so, I didn't want to release it by itself because I knew it needed some more
work before I did that.

Recently, I delved back into it after several years and am now releasing version 2,
which was mostly rewritten over the past several weeks.

What does it do? It retrieves the properties and values pertaining to your computer,
operating system and devices. All you need is a valid Win32 Class Name.

So, here it is -- let me know if you have any issues!

Updated to v2.25, January 14, 2017

Download: _WMI_InstancesOf_v2.25.au3

 

Edited by ripdad
2 people like this

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I tested the class string:
Win32_NTLogEvent WHERE Logfile="System"
and it returns an error because file is in Logfile. Oh well.


Edit: fixed in v2.11



 



 

Edited by ripdad

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Updated to v2.11
- Fixed a problem with WHERE statement strings
- Now supports horizontal arrays

Examples:

#include 'array.au3'
#include '_WMI_InstancesOf_v2.11.au3'

; Example 1 - vertical array

Local $rtn = _WMI_InstancesOf('Win32_OperatingSystem', 1)
Local $nError = @error
If IsArray($rtn) Then
    _ArrayDisplay($rtn)
Else
    MsgBox(0, '', 'Error: ' & $nError & @CRLF & $rtn)
EndIf
Exit
#include 'array.au3'
#include '_WMI_InstancesOf_v2.11.au3'

; Example 2 - horizontal array

Local $sClass = 'Win32_NTLogEvent WHERE Logfile="System"'
$sClass &= ' And EventCode="6005"'
$sClass &= ' And TimeGenerated>"20160101000000.000000-000"'; date range start (get month, December 2016)
$sClass &= ' And TimeGenerated<"20170101000000.000000-000"'; date range end + 1
Local $NoBlanks = 0; include blank values
Local $nHorizontal = 1; return horizontal array ($NoBlanks = 0, must be used)
Local $nStatement = 1; get these properties only
Local $strProperty = 'ComputerName|EventCode|EventIdentifier|TimeGenerated'
Local $rtn = _WMI_InstancesOf($sClass, $NoBlanks, $nHorizontal, $nStatement, $strProperty)
Local $nError = @error
If IsArray($rtn) Then
    _ArraySort($rtn, 0, 1, 0, 3); <- sort by date column (user dependent)
    _ArrayDisplay($rtn)
Else
    MsgBox(0, '', 'Error: ' & $nError & @CRLF & $rtn)
EndIf
Exit
#include 'array.au3'
#include '_WMI_InstancesOf_v2.11.au3'

; Example 3 - horizontal array

Local $strProperty = 'Name|NetConnectionID|Manufacturer|NetConnectionStatus'
Local $rtn = _WMI_InstancesOf('Win32_NetworkAdapter', 0, 1, 1, $strProperty)
Local $nError = @error
If IsArray($rtn) Then
    _ArrayDisplay($rtn)
Else
    MsgBox(0, '', 'Error: ' & $nError & @CRLF & $rtn)
EndIf
Exit

 

Edited by ripdad

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

Share this post


Link to post
Share on other sites

Updated to v2.25 - see first post

This should be it, unless someone has a suggestion or problem with the script.

 

 

 


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
Sign in to follow this  
Followers 0

  • Similar Content

    • jguinch
      By jguinch
      Hello.
      I did create these few functions several months ago. I post here, if it can interest someone.
      These functions based on WMI queries allow you to manage printers : add / delete printer, driver, port, or obtain configuration, set default printer ... I let you discover it with the code.

       
      Here is the list of the available functions :
      _Printmgr_AddLocalPort
      _PrintMgr_AddPrinter
      _PrintMgr_AddPrinterDriver
      _PrintMgr_AddTCPIPPrinterPort
      _PrintMgr_AddWindowsPrinterConnection
      _PrintMgr_CancelAllJobs
      _PrintMgr_EnumPrinter
      _PrintMgr_EnumPrinterConfiguration
      _PrintMgr_EnumPrinterDriver
      _PrintMgr_EnumPrinterProperties
      _PrintMgr_EnumTCPIPPrinterPort
      _Printmgr_Pause
      _Printmgr_PrinterExists
      _Printmgr_PrintTestPage
      _PrintMgr_RemoveLocalPrinterPort
      _PrintMgr_RemovePrinter
      _PrintMgr_RemovePrinterDriver
      _PrintMgr_RemoveTCPIPPrinterPort
      _PrintMgr_RenamePrinter
      _Printmgr_Resume
      _PrintMgr_SetDefaultPrinter
       
      And some examples :
      #Include "PrintMgr.au3" ; Remove a printer called "My old Lexmark printer" : _PrintMgr_RemovePrinter("My old Lexmark printer") ; Remove the driver called "Lexmark T640" : _PrintMgr_RemovePrinterDriver("Lexmark T640") ; Remove the TCP/IP printer port called "TCP/IP" _PrintMgr_RemoveTCPIPPrinterPort("MyOLDPrinterPort") ; Add a driver, called "Samsung ML-451x 501x Series", and driver inf file is ".\Samsung5010\sse2m.inf" _PrintMgr_AddPrinterDriver("Samsung ML-451x 501x Series", "Windows NT x86", @scriptDir & "\Samsung5010", @scriptDir & "\Samsung5010\sse2m.inf") ; Add a TCP/IP printer port, called "MyTCPIPPrinterPort", with IPAddress = 192.168.1.10 and Port = 9100 _PrintMgr_AddTCPIPPrinterPort("MyTCPIPPrinterPort", "192.168.1.10", 9100) ; Add a printer, give it the name "My Printer", use the driver called "Samsung ML-451x 501x Series" and the port called "MyTCPIPPrinterPort" _PrintMgr_AddPrinter("My Printer", "Samsung ML-451x 501x Series", "MyTCPIPPrinterPort") ; Set the printer called "My Printer" as default printer _PrintMgr_SetDefaultPrinter("My Printer") ; Connect to the shared printer "\\192.168.1.1\HPDeskjetColor") _PrintMgr_AddWindowsPrinterConnection("\\192.168.1.1\HPDeskjetColor") ; List all installed printers #Include <Array.au3> $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) ; List all printers configuration #Include <Array.au3> $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration() _ArrayDisplay($aPrinterConfig) ; List all installed printer drivers #Include <Array.au3> $aDriverList = _EnumPrinterDriver() _ArrayDisplay($aDriverList) ; Retrieve the printer configuration for the printer called "Lexmark T640" #Include <Array.au3> $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration("Lexmark T640") _ArrayDisplay($aPrinterConfig) ; Add a local printer port (for a file output) _AddLocalPrinterPort("c:\temp\output.pcl") ; Remove the local port _RemoveLocalPrinterPort("c:\temp\output.pcl") Current version download link :
       
      PrintMgr.au3
    • TMelanson
      By TMelanson
      Hi folks,
      I'm hoping someone can help me out here.
      Background:
      I have the need to run a program with admin credentials (#RequireAdmin), and then get the SID of the locally logged in account. Not the admin account.
      If you look at the attached script, Line 16 uses the @UserName variable and returns the SID for the admin account I used to launch the app.
      I want to use line 17 which passes the result of the _GetUsername function which is a username using  ($UserName) to the WMIService.
      I'm getting " The requested action with this object has failed.:" error message.
      Any suggestions would be appreciated!
       
      test1.au3
    • pranaynanda
      By pranaynanda
      I want to pop a message on each machine on our network. The message will be a simple AutoIt message. I need help with the WMI part or the deployment process.
    • TheDcoder
      By TheDcoder
      Hello, I found a VB snippet which I would love to use in AutoIt
      strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Process") For Each objItem in colItems Wscript.Echo objItem.Name Wscript.Echo objItem.CommandLine Next Despite my best efforts, I am not able to understand a thing from that piece of code . All I know is that it outputs the Name and Commandline of all the processes currently running (Let's see if I am right).
      Can anyone help me with convert this into AutoIt? Thanks in Advance!
    • Irios
      By Irios
      First post here, please be gentle
       
      I've spent hours and hours trying to figure out this puzzle. It's impossible to google for because I don't know the precise terminology to use. All msdn links I find are either dead or has been removed like 10 years ago.
       
      Here is a tiny code example:
      $objWMIService = ObjGet("winmgmts:") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface Where Name like '%intel%'") For $objItem In $colItems ConsoleWrite($objItem.PacketsPersec & @CRLF) Next In that example I'm using the asterix * and it retrieves all properties in the "Win32_PerfRawData_Tcpip_NetworkInterface" class.  But I'm only utilizing "PacketsPersec" in the example.
      How could I enumerate all the properties without defining their names beforehand?
      (FYI, I do know their names, but the script doesn't know the names)
      In other words; how can I use "SELECT *" on any class and output all properties, one by one? Without having to manually specify each property with $objItem.<propertyname> ?

      As comparison, using wmic in a cmd shell ...
          wmic path Win32_PerfRawData_Tcpip_NetworkInterface  Where "Name like '%intel%'" get /value
      ...and it lists all properties in "Names=Value" manner.
      This is sort of the same function I'm looking for. How could I do the same in Autoit?
       
       
      EDIT: I cannot run a powershell or cmd  to "solve" the problem.  I need to find a way to do this "internally" in Autoit. I.e. by calling the WMI service directly with ObjGet(winmgmts:) or connect to the WMI system with CreateObject("WbemScripting.SWbemLocator"). Performance is a major factor.