DWbemLocator.ConnectServer

[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
 

Parameters

NetworkResource
A string containing the object path of the desired CIMOM and namespace. For local machine access to the default namespace, for example, use a simple object path: "root\default" or "\\.\root\default".

For access to the default namespace on a remote machine using Distributed COM (DCOM), include the machine name: "\\myserver\root\default".

See Object Paths.

User
A string that specifies the user name to use while attempting to connect. Use vbNullString to use the user name of the current logged-on user.
Password
A string that specifies the password to use when attempting to connect. Use vbNullString, but not a blank string, to use the password of the current logged-on user. A blank string is treated as a valid password.
Locale
A string that specifies the localization code. Use vbNullString to use the current locale. If not vbNullString, this parameter must be a string that indicates the desired locale in which information should be retrieved. For Microsoft locale identifiers, the format of the string is "MS\xxxx", where xxxx is a string in hexadecimal form that indicates the LCID.

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.

lSecurityFlags
Must be 0.
Authority
Reserved. It should be set to vbNullString.
pCtx
DWbemContext type object required by the dynamic class provider that is producing the class instances. You must specify the values in the context object in the documentation for the provider in question. This can be NOTHING if no context is being provided.
ppNamespace
DIWbemServices type object bound to the specified namespace. On error, this is set to NOTHING.

Return Values

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.

Sample Code

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

See Also

DIWbemServices