WMI (Windows Management Instrumentation) is an interface to retrieve information (e. g. battery status, PC information, hard disk information, network information, programs,...), to execute methods (e. g. domain registration, fan control, activate/deactivate network connections, printer management,...) and to query events (e. g. whether the process has been started or stopped,...).
Functions:
- ExecuteWMIQuery()
- Syntax:
Code: Select all
Result = ExecuteWMIQuery(Namespace$, Query$, @Output$)
- Description: Executes a query.
- Parameter:
- Namespace$: Name of the namespace.
- Query$: Query of the class.
- @Output$: The result of the query is stored in XML format in the string variable.
- Return value:
- 0: The process was successful.
- Example:
Code: Select all
EnableExplicit Global PBEx_WMI CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 PBEx_WMI = OpenLibrary(#PB_Any, "PB.Ex_WMI_x86.dll") CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 PBEx_WMI = OpenLibrary(#PB_Any, "PB.Ex_WMI_x64.dll") CompilerEndIf If PBEx_WMI Prototype ExecuteWMIQuery(Namespace.p-Unicode, Query.p-Unicode, Output) Global ExecuteWMIQuery.ExecuteWMIQuery = GetFunction(PBEx_WMI, "ExecuteWMIQuery") Prototype ExecuteWMIMethod(Namespace.p-Unicode, Query.p-Unicode, Method.p-Unicode, ParameterArray, ParameterArraySize) Global ExecuteWMIMethod.ExecuteWMIMethod = GetFunction(PBEx_WMI, "ExecuteWMIMethod") Prototype WaitWMIEvent(Query.p-Unicode, Timeout = 0) Global WaitWMIEvent.WaitWMIEvent = GetFunction(PBEx_WMI, "WaitWMIEvent") Define Output$ = Space(1000000) ExecuteWMIQuery("root\CIMV2", "SELECT * FROM Win32_LogicalDisk", @Output$) ParseXML(1, Output$) FormatXML(1, #PB_XML_WindowsNewline | #PB_XML_ReFormat | #PB_XML_ReIndent) Debug ComposeXML(1) CloseLibrary(PBEx_WMI) EndIf
- Syntax:
- ExecuteWMIMethod()
- Syntax:
Code: Select all
Result = ExecuteWMIMethod(Namespace$, Query$, Method$, ParameterArray, ParameterArraySize)
- Description: Executes a method.
- Parameter:
- Namespace$: Name of the namespace.
- Query$: Query of the class and optional with conditions.
- Method$: Name of the method to be executed.
- ParameterArray: A string array with parameters to pass. Parameter name and value are separated with an equal sign without spaces.
- ParameterArraySize: Number of elements.
- Return value:
- 0: The process was successful.
- Example:
Code: Select all
EnableExplicit Global PBEx_WMI CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 PBEx_WMI = OpenLibrary(#PB_Any, "PB.Ex_WMI_x86.dll") CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 PBEx_WMI = OpenLibrary(#PB_Any, "PB.Ex_WMI_x64.dll") CompilerEndIf If PBEx_WMI Prototype ExecuteWMIQuery(Namespace.p-Unicode, Query.p-Unicode, Output) Global ExecuteWMIQuery.ExecuteWMIQuery = GetFunction(PBEx_WMI, "ExecuteWMIQuery") Prototype ExecuteWMIMethod(Namespace.p-Unicode, Query.p-Unicode, Method.p-Unicode, ParameterArray, ParameterArraySize) Global ExecuteWMIMethod.ExecuteWMIMethod = GetFunction(PBEx_WMI, "ExecuteWMIMethod") Prototype WaitWMIEvent(Query.p-Unicode, Timeout = 0) Global WaitWMIEvent.WaitWMIEvent = GetFunction(PBEx_WMI, "WaitWMIEvent") ;Administrator rights required Dim ParameterArray.s(0) ParameterArray(0) = "Name=YourNewUsername" Debug ExecuteWMIMethod("root\CIMV2", "Win32_UserAccount.Domain='YourWorkgroup',Name='YourUsername'", "Rename", ParameterArray(), ArraySize(ParameterArray())+1) CloseLibrary(PBEx_WMI) EndIf
- Syntax:
- WaitWMIEvent()
- Syntax:
Code: Select all
Result = WaitWMIEvent(Class$, Query$, Timeout = 0)
- Description: Waiting for an event.
- Parameter:
- Query$: Query of the class and optional with conditions.
- Timeout: Time in milliseconds, how long the maximum waiting time for an event should be. If nothing or 0 is specified, the system waits until the event has been triggered.
- Return value:
- 0: The process was successful.
- Example:
Code: Select all
EnableExplicit Global PBEx_WMI CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 PBEx_WMI = OpenLibrary(#PB_Any, "PB.Ex_WMI_x86.dll") CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 PBEx_WMI = OpenLibrary(#PB_Any, "PB.Ex_WMI_x64.dll") CompilerEndIf If PBEx_WMI Prototype ExecuteWMIQuery(Namespace.p-Unicode, Query.p-Unicode, Output) Global ExecuteWMIQuery.ExecuteWMIQuery = GetFunction(PBEx_WMI, "ExecuteWMIQuery") Prototype ExecuteWMIMethod(Namespace.p-Unicode, Query.p-Unicode, Method.p-Unicode, ParameterArray, ParameterArraySize) Global ExecuteWMIMethod.ExecuteWMIMethod = GetFunction(PBEx_WMI, "ExecuteWMIMethod") Prototype WaitWMIEvent(Query.p-Unicode, Timeout = 0) Global WaitWMIEvent.WaitWMIEvent = GetFunction(PBEx_WMI, "WaitWMIEvent") ;Administrator rights required Debug "Wait until the calculator is started...." If WaitWMIEvent("SELECT * FROM Win32_ProcessStartTrace WHERE ProcessName = 'calc.exe'") = 0 Debug "Calculator was started." Else Debug "Error" EndIf CloseLibrary(PBEx_WMI) EndIf
- Syntax:
- Windows XP or higher
- .NET Framework 3.5 or higher
- Unicode activation (standard from PB 5.50)
No assembly registration with regasm.exe with administrator rights is necessary as with COMatePLUS.
Licence: This DLL file is free of charge and may be used both privately and commercially.
The following copyright texts must be provided:
Download: https://www.rsbasic.de/downloads/downlo ... Ex_WMI.zipCopyright © 2019 RSBasic.de
I would be happy to receive feedback, suggestions for improvement, bug reports or requests. If you want to support me, you can also donate me a little something. Thank you