Sign in to follow this  
Followers 0
SIMPLE_XP

WMI - WMI help needed

7 posts in this topic

Ok, so I figured out how to create a new namespace in WMI...

Func ADD_ROOT_NAMESPACE($PASSED_LOCAL_COMPUTER, $PASSED_NAMESPACE)

Dim $OBJ_WMI_SERVICE, $OBJ_ITEM, $OBJ_NAME_SPACE

$OBJ_WMI_SERVICE = ObjGet("winmgmts:\\" & $PASSED_LOCAL_COMPUTER & "\root")

$OBJ_ITEM = $OBJ_WMI_SERVICE.Get("__Namespace")

$OBJ_NAME_SPACE = $OBJ_ITEM.SpawnInstance_

$OBJ_NAME_SPACE.Name = $PASSED_NAMESPACE

$OBJ_NAME_SPACE.Put_

EndFunc

How do I now create Classes etc... and then write to them?

Thanks in advance...


Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

Share this post


Link to post
Share on other sites



Anybody?

Ok, so I figured out how to create a new namespace in WMI...

Func ADD_ROOT_NAMESPACE($PASSED_LOCAL_COMPUTER, $PASSED_NAMESPACE)

Dim $OBJ_WMI_SERVICE, $OBJ_ITEM, $OBJ_NAME_SPACE

$OBJ_WMI_SERVICE = ObjGet("winmgmts:\\" & $PASSED_LOCAL_COMPUTER & "\root")

$OBJ_ITEM = $OBJ_WMI_SERVICE.Get("__Namespace")

$OBJ_NAME_SPACE = $OBJ_ITEM.SpawnInstance_

$OBJ_NAME_SPACE.Name = $PASSED_NAMESPACE

$OBJ_NAME_SPACE.Put_

EndFunc

How do I now create Classes etc... and then write to them?

Thanks in advance...


Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

Share this post


Link to post
Share on other sites

Not knowing what exactly you are trying to achieve, I can give you an example how to access services and processes on some machine.

$strComputer = "localhost"
$wmiLocator = ObjCreate("WbemScripting.SWbemLocator")
$wmiService = $wmiLocator.ConnectServer($strComputer, "root\cimv2", "user", "password")

$colServices = $wmiService.ExecQuery("Select * from Win32_Service")
; enumerate windows services and start Scheduler
For $objService in $colServices
    ConsoleWrite($objService.Name & ": " & $objService.DisplayName & " (" & $objService.State & ")")
    If $objService.Name = "Scheduler" Then $objService.StartService()
Next

; select running notepad and kill it
$colProcess = $wmiService.ExecQuery("Select * from Win32_Process Where Name = 'Notepad.exe'")
For $objProcess in $colProcess
    ConsoleWrite($objProcess.Name & ": " & $objProcess.ExecutablePath)
    $objProcess.Terminate()
Next

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

Thanks for replying, but I know how to read from WMI, I am trying to figure out how to write to WMI (In the namespace I created with the posted code) without an intermediary providor. Is this possible in AutoIT?

Not knowing what exactly you are trying to achieve, I can give you an example how to access services and processes on some machine.

$strComputer = "localhost"
$wmiLocator = ObjCreate("WbemScripting.SWbemLocator")
$wmiService = $wmiLocator.ConnectServer($strComputer, "root\cimv2", "user", "password")

$colServices = $wmiService.ExecQuery("Select * from Win32_Service")
; enumerate windows services and start Scheduler
For $objService in $colServices
    ConsoleWrite($objService.Name & ": " & $objService.DisplayName & " (" & $objService.State & ")")
    If $objService.Name = "Scheduler" Then $objService.StartService()
Next

; select running notepad and kill it
$colProcess = $wmiService.ExecQuery("Select * from Win32_Process Where Name = 'Notepad.exe'")
For $objProcess in $colProcess
    ConsoleWrite($objProcess.Name & ": " & $objProcess.ExecutablePath)
    $objProcess.Terminate()
Next

Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

Share this post


Link to post
Share on other sites

Ok, I think I figured it out... (found some cool stuff in vbscript) I will post the code as soon as I have it validated. I am sure someone else will want to know how to do this in AutoIT as well. Maybe I will make WMI UDF if I have time.

Thanks for replying, but I know how to read from WMI, I am trying to figure out how to write to WMI (In the namespace I created with the posted code) without an intermediary providor. Is this possible in AutoIT?


Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sorry it took so long... I have been busy at work. I created a basic wmifunctions.au3 UDF.

Here is the lowdown:

  • Create a new namespace in the root
  • Delete a namespace in the root
  • Add a Class, set the key property and add additional properties
It is Beta, so please do not make fun!

I will add some additional functionality in the future.

Example of how to use the functions:

CODE
#include <wmifunctions.au3>

$LOCAL_COMPUTER = "."

$NAME_SPACE = "AutoIT"

$CLASS = "WMIisFun"

$KEYPROPERTY = "KeyProperty,False"

$PROPERTYLIST = "FirstProperty,False|SecondProperty,False|ThirdProperty,False"

_ADD_ROOT_NAMESPACE($LOCAL_COMPUTER, $NAME_SPACE)

_CREATE_NAMESPACE_CLASS($LOCAL_COMPUTER, $NAME_SPACE, $CLASS, $KEYPROPERTY, $PROPERTYLIST)

_DELETE_NAMESPACE($LOCAL_COMPUTER, $NAME_SPACE)

wmifunctions.au3

Edited by SIMPLE_XP

Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

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