It is currently Sat Jan 23, 2021 7:24 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: PB.Ex WMI (Windows)
PostPosted: Thu Mar 08, 2018 8:56 pm 
Offline
Moderator
Moderator

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1113
Location: Gernsbach (Germany)
Hello,

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:
      Result = ExecuteWMIQuery(Namespace$, Query$, @Output$)

    • Description: Executes a query.
    • Parameter:
      1. Namespace$: Name of the namespace.
      2. Query$: Query of the class.
      3. @Output$: The result of the query is stored in XML format in the string variable.
    • Return value:
      • 0: The process was successful.
    • Example:
      Code:
      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

  • ExecuteWMIMethod()
    • Syntax:
      Code:
      Result = ExecuteWMIMethod(Namespace$, Query$, Method$, ParameterArray, ParameterArraySize)

    • Description: Executes a method.
    • Parameter:
      1. Namespace$: Name of the namespace.
      2. Query$: Query of the class and optional with conditions.
      3. Method$: Name of the method to be executed.
      4. ParameterArray: A string array with parameters to pass. Parameter name and value are separated with an equal sign without spaces.
      5. ParameterArraySize: Number of elements.
    • Return value:
      • 0: The process was successful.
    • Example:
      Code:
      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

  • WaitWMIEvent()
    • Syntax:
      Code:
      Result = WaitWMIEvent(Class$, Query$, Timeout = 0)

    • Description: Waiting for an event.
    • Parameter:
      1. Query$: Query of the class and optional with conditions.
      2. 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:
      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


System requirements:
  • Windows XP or higher
  • .NET Framework 3.5 or higher
  • Unicode activation (standard from PB 5.50)
Since the required. NET Framework is preinstalled by default from Windows 7 and can be installed on XP and Vista, this shouldn't be a problem to use this version.
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:
Quote:
Copyright © 2019 RSBasic.de


Download: http://www.rsbasic.de/downloads/downloa ... Ex_WMI.zip
Image

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 :)

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye