[This is preliminary documentation and subject to change.]
The DWbemLocator.ConnectServer method connects to CIMOM on the machine specified in the NetworkResource parameter. This is typically a Microsoft® Windows NT® or Microsoft® Windows® 95/98 target machine, which must have an operational CIMOM. If method is succesfull then a DIWbemServices object will be returned that is bound to the namespace on the host machine.
DWbemLocator.ConnectServer(
[in] NetworkResource As String,
[in] User As String,
[in] Password As String,
[in] Locale As String,
[in] lSecurityFlags As Long,
[in] Authority As String,
[in] pCtx As Object,
[out] ppNamespace As Object
) As Long
For access to the default namespace on a remote machine using Distributed COM (DCOM), include the machine name: "\\myserver\root\default".
See Object Paths.
For example, American English would appear as "MS\0x409"
Since WBEM accommodates other localization schemes besides Microsoft 32-bit LCIDs, you need to use this string format. Other schemes are ISO 639 and RFC 1766. See WBEM Localization.
WBEM_E_ACCESS_DENIED | The current or specified user name and password were not valid or authorized to make the connection. |
WBEM_E_FAILED | Unspecified error. |
WBEM_E_INVALID_NAMESPACE | The specified namespace did not exist on the server. |
WBEM_E_INVALID_PARAMETER | An invalid parameter was specified, or the namespace could not be parsed. |
WBEM_E_OUT_OF_MEMORY | There was not enough memory to complete the operation. |
WBEM_E_TRANSPORT_FAILURE | A networking error occurred, preventing normal operation. |
WBEM_E_SERVER_NOT_FOUND | The specified server could not be located. |
WBEM_NO_ERROR | Success. |
Function Wbem_logon()
Dim NetworkResource
Dim ErrObj As DWbemClassObject
Dim pLocator As New DWbemLocator
On Error GoTo ErrorHandler
' This example attempts to log on to the root\cimv2 namespace.
' Pass vbNullstring for the username, password, locale and authority
' to use the currently logged in user password and the default locale
' and authority
' ppNamespace is a DWbemServices type object that will be bound to the
' namespace.
pLocator.ConnectServer Me.Namespace, vbNullString, vbNullString, vbNullString, 0, vbNullString, Nothing, ppNamespace
Wbem_logon = WBEM_NO_ERROR
Exit Function
ErrorHandler:
' Calls a custom function that converts error codes to descriptive strings.
MsgBox "An error has occurred: " & show_wbem_error(Err.Number)
show_wbem_error (Err.Number)
Wbem_logon = -1 'indicate an error
Exit Function
End Function