ConnectServer Method |
Description
The IWbemLocator.ConnectServer method creates a connection through DCOM to a WMI namespace on the computer specified in the strNetworkResource parameter.
Starting with Windows Vista, SWbemLocator.ConnectServer can connect with computers running IPv6 using an IPv6 address in the strNetworkResource parameter.
Windows Server 2003, Windows XP, and Windows 2000: You can only use SWbemLocator.ConnectServer to connect to computers with IPv4 addresses.
C++ Syntax
PowerBASIC Syntax
Parameters
strNetworkResource
Pointer to a valid BSTR that contains the object path of the correct WMI namespace. 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, SWbemLocator.ConnectServer can connect with computers running IPv6 using an IPv6 address.
strUser
Pointer to a valid BSTR, which contains the user name you need for a connection. A NULL 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.
StrUserName = SysAllocString(L"Domain\\UserName");
The strUser parameter cannot be an empty string. Note that if the domain is specified in strAuthority, then it must not be specified here. Specifying the domain in both parameters results in an invalid parameter error.
You can use the user principal name (UPN) format, which is Username@DomainName to specify the strUser.
Windows 2000 and Windows NT 4.0: You cannot use the user principal name (UPN) format.
strPassword
Pointer to a valid BSTR that contains the password you need for a connection. A NULL value indicates the current security context. A blank string "" specifies a valid zero-length password.
strLocale
If NULL, the current locale is used. If not NULL, this parameter must be a valid BSTR, which 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".
lSecurityFlags
Long value used to pass flag values to ConnectServer. A value of zero (0) for this parameter results in the call to ConnectServer returning only after connection to the server is established. This could result in your program hanging indefinitely if the server is broken. The following table lists the other valid values for lSecurityFlags.
strAuthority
This parameter contains the name of the domain of the user to authenticate.
strAuthority can have the following values:
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 authentication is used and this parameter should contain a Kerberos principal name.
NT LAN Manager authentication is used and this parameter should contain an NTLM domain name.
pCtx
Typically, this is NULL. Otherwise, this is a pointer to an IWbemContext object required by one or more dynamic class providers. The values in the context object must be specified in the documentation for the providers in question.
ppNamespace
Receives a pointer to an IWbemServices object bound to the specified namespace. This pointer has a positive reference count. This pointer is set to point to NULL when there is an error.
Return Value
This method returns an HRESULT that indicates the status of the method call. The following table lists the value contained within an HRESULT.
COM-specific error codes may be returned if network problems cause you to lose the remote connection to WMI.
These error return codes are defined in the Wbemcli.h file in the WMI section of the PSDK \Include directory. For more information see WMI Error Constants.
Remarks
Do not specify strUser, strPassword, or strAuthority when making a connection to a local namespace.
Requirements
|