Getfunction
Retrieves an object, that is either a class definition or an instance, based on the object path.
Syntax
FUNCTION Get (BYREF wszObjectPath AS WsTRING, BYVAL iFlags AS LONG = 0, BYVAL objWbemNamedValueSet AS Afx_IDispatch PTR = NULL) AS HRESULT
Parameters
| Name | Description | |
|---|---|---|
wszObjectPath | A string that contains the object path of the object to retrieve. If this value is empty, the empty object that is returned can become a new class. | |
iFlags | Optional. An integer value that determines the behavior of the query. This parameter can accept the following value: wbemFlagUseAmendedQualifiers: Causes WMI to return class amendment data with the base class definition. | |
objWbemNamedValueSet | Optional. Typically, this is undefined. Otherwise, this is an SWbemNamedValueSet object whose elements represent the context information that can be used by the provider that is servicing the request. A provider that supports or requires such information must document the recognized value names, data type of the value, allowed values, and semantics. |
Return value
S_OK on success or an error code.
May return one of the error codes in the following list:
Description
Retrieves an object, that is either a class definition or an instance, based on the object path. This method retrieves only objects from the namespace that is associated with the current SWbemServices object.
Examples
#include "AfxNova/CWmiDisp.inc" using AfxNova
' // Connect to WMI using a moniker DIM pServices AS CWmiServices = $"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2"
' // Get an instance of the printer "OKI B410" --> change me DIM hr AS HRESULT = pServices.Get("Win32_Printer.DeviceID='OKI B410'")
' // Number of properties PRINT "Number of properties: ", pServices.PropsCount PRINT
' // Display some properties PRINT "Port name: "; pServices.PropValue("PortName") PRINT "Attributes: "; pServices.PropValue("Attributes") PRINT "Paper sizes supported: "; pServices.PropValue("PaperSizesSupported")
#include "AfxNpva/CWmiDisp.inc" USING AfxNova
' // Connect to WMI using a moniker 'DIM pServices AS CWmiServices = $"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2" ' Use the constructor for server connection, just for trying... DIM pServices AS CWmiServices = CWmiServices(".", "root\cimv2")
'// Get an instance of a file --> change me DIM dwsPath AS DWSTRING = ExePath & "\EX_CWMI_Get_01.bas" ' --> change me DIM hr AS HRESULT = pServices.Get("CIM_DataFile.Name='" & dwsPath & "'")
' // Number of properties PRINT "Number of properties: ", pServices.PropsCount PRINT
' // Display some properties PRINT "Relative path: "; pServices.PropValue("Path") PRINT "FileName: "; pServices.PropValue("FileName") PRINT "Extension: "; pServices.PropValue("Extension") PRINT "Size: "; pServices.PropValue("Filesize") 'PRINT pServices.PropValue("LastModified") PRINT "Date last modified: "; pServices.WmiDateToStr(pServices.PropValue("LastModified"), "dd-MM-yyyy") ' // change the mask if needed
Example
Reference
- Include file
CWmiDisp.inc - Documented in COM/CWmiDisp Class.md
- Topic: Windows Management Instrumentation (WMI)