Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old


Connects to WMI server.

Component Version macOS Windows Linux Server iOS SDK
WMIQuery 5.2 ❌ No ✅ Yes ❌ No ✅ Yes, on Windows ❌ No
MBS( "WMIQuery.Connect"; WMIQueryRef; NetworkResource { ; UserName; Password; Locale; Authority } )   More


Parameter Description Example Flags
WMIQueryRef The reference to the query. Create it with WMIQuery.New and destroy them with WMIQuery.Release. $ref
NetworkResource The path of the correct WMI namespace to connect to. For local access to the default namespace, use a simple object path: "root\default" or "\\.\root\default". For access to the default namespace on a remote computer using COM or Microsoft-compatible networking, include the computer name: "\\myserver\root\default". The computer name also can be a DNS name or IP address. Starting with Windows Vista, Connect can connect with computers running IPv6 using an IPv6 address. "ROOT\CimV2"
UserName The user name you need for a connection. An empty value indicates the current security context. If the user name is from a domain different from the current domain, the string may contain the domain name and user name separated by a backslash. Optional
Password The password you need for a connection. An empty value indicates the current security context. A blank string "" specifies a valid zero-length password. Optional
Locale If empty, the current locale is used. If not empty, this parameter indicates the correct locale for information retrieval. For Microsoft locale identifiers, the format of the string is "MS_xxx", where xxx is a string in hexadecimal form that indicates the Local Identification (LCID), for example, American English would appear as "MS_409". If an invalid locale is specified, then the method returns "Invalid Parameter".
Windows 7:  If an invalid locale is specified, then the default locale of the server is used unless there is a server-supported locale provided by the user application.
Authority This parameter contains the name of the domain of the user to authenticate.
Authority can have the following values:
Empty: If you leave this parameter blank, NTLM authentication is used and the NTLM domain of the current user is used. If the domain is specified in strUser, which is the recommended location, then it must not be specified here. Specifying the domain in both parameters results in an invalid parameter error.
Kerberos:<principal name>Kerberos authentication is used and this parameter should contain a Kerberos principal name.
NTLMDOMAIN:<domain name>NT LAN Manager authentication is used and this parameter should contain an NTLM domain name.


Returns OK or error.


Connects to WMI server.
Connects through DCOM to a WMI namespace on the computer specified in the strNetworkResource parameter.


Connect locally:

MBS( "WMIQuery.Connect"; "ROOT\CimV2" )

Connect and Query:

Set Variable [$q; Value:MBS("WMIQuery.New")]
If [MBS("IsError") = 0]
    Set Field [WMI Query::QueryID; $q]
    #connect to server
    Set Variable [$r; Value:MBS("WMIQuery.Connect"; $q; WMI Query::NetworkResource; WMI Query::User; WMI Query::Password; WMI Query::Locale; WMI Query::Authority)]
    If [MBS("IsError") = 0]
        #run query
        Set Variable [$r; Value:MBS("WMIQuery.Query"; $q; WMI Query::Query)]
        If [MBS("IsError") = 0]
            #show result
            Go to Related Record [Show only related records; From table: “Result”; Using layout: “Result” (Result)]
            Go to Layout [“Result” (Result)]
            Delete All Records [No dialog]
                Set Variable [$r; Value:MBS("WMIQuery.Next"; $q)]
                Exit Loop If [$r ≠ "OK"]
                #show properties
                Set Variable [$Names; Value:MBS("WMIQuery.PropertyNames"; $q)]
                If [MBS("IsError")]
                    Show Custom Dialog ["Query Error"; $r]
                    Exit Script []
                    #loop properties
                    Set Variable [$count; Value:ValueCount ( $Names )]
                    Set Variable [$index; Value:1]
                        #property name, type and value
                        Set Variable [$name; Value:GetValue($Names; $index)]
                        Set Variable [$type; Value:MBS("WMIQuery.PropertyType"; $q; $name)]
                        Set Variable [$value; Value:MBS("WMIQuery.PropertyValue"; $q; $name)]
                        New Record/Request
                        Set Field [Result::Name; $name]
                        Set Field [Result::Type; $type]
                        Set Field [Result::Text; $value]
                        Set Field [Result::QueryID; $q]
                        Commit Records/Requests [No dialog]
                        Set Variable [$index; Value:$index +1]
                        Exit Loop If [$index > $count]
                    End Loop
                End If
            End Loop
            Show Custom Dialog ["Query Error"; $r]
        End If
        Show Custom Dialog ["Connect Error"; $r]
    End If
    Set Variable [$r; Value:MBS("WMIQuery.Release"; $q)]
End If

See also

Example Databases

This function checks for a license.

Created 22nd June 2015, last changed 29th February 2016

WMFP.UpdateVideo - WMIQuery.New