Help Center

Constructor (Server)constructor

Connects to the namespace that is specified on the *wszNamespace* parameter on the computer that is specified in the *wszServer* parameter. The target computer can be either local or remote, but it must have WMI installed.

COMconstructorCWmiDisp.incdoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

Syntax

CONSTRUCTOR CWmiServices (BYREF wszServer AS WSTRING, BYREF wszNamespace AS WSTRING, BYREF wszUser AS WSTRING = "", BYREF wszPassword AS WSTRING = "", BYREF wszLocale AS WSTRING = "", BYREF wszAuthority AS WSTRING = "", BYVAL iSecurityFlags AS LONG = wbemConnectFlagUseMaxWait)

Parameters

NameDescription
wszServerThe computer name to which you are connecting. If the remote computer is in a different domain than the user account under which you log in, then use the fully qualified computer name. If you do not provide this parameter, the call defaults to the local computer.
Example: server1.network.fabrikam
You also can use an IP address in this parameter. If the IP address is in IPv6 format, the target computer must be running IPv6. An address in IPv4 looks like 111.222.333.444. An IP address in IPv6 format looks like 2010:836B:4179::836B:4179
wszNamespaceA string that specifies the namespace to which you log on. For example, to log on to the root\default namespace, use root\\default. If you do not specify this parameter, it defaults to the namespace that is configured as the default namespace for scripting.
Example: DIM pServices AS CWmiServices = CWmiServices(".", "root\\cimv2")
where "." is a shortcut for the local computer.
wszPasswordA string that specifies the password to use when attempting to connect. Leave the parameter blank to use the current security context. The wszPassword parameter should only be used with connections to remote WMI servers. If you attempt to specify wszPassword for a local WMI connection, the connection attempt fails. If Kerberos authentication is in use then the username and password that is specified in wszUser and wszPassword cannot be intercepted on the network.
wszLocaleA string that specifies the localization code. If you want to use the current locale, leave it blank. If not blank, this parameter must be a string that indicates the desired locale where information must be retrieved. For Microsoft locale identifiers, the format of the string is "MS_xxxx", where xxxx is a string in the hexadecimal form that indicates the LCID. For example, American English would appear as "MS_409".
wszAuthorityOptional.
"": This parameter is optional. However, if specified, only Kerberos or NTLMDomain can be used.
"Kerberos": If the wszAuthority parameter begins with the string "Kerberos:", then Kerberos authentication is used and this parameter should contain a Kerberos principal name. The Kerberos principal name is specified as Kerberos:domain, such as Kerberos:fabrikam where fabrikam is the server to which you are attempting to connect. Example: "Kerberos:DOMAIN"
"NTLMDomain": To use NT Lan Manager (NTLM) authentication, you must specify it as NTLMDomain:domain, such as NTLMDomain:fabrikam where fabrikam is the name of the domain. Example: "NTLMDomain:DOMAIN"
If you leave this parameter blank, the operating system negotiates with COM to determine whether NTLM or Kerberos authentication is used. This parameter should only be used with connections to remote WMI servers. If you attempt to set the authority for a local WMI connection, the connection attempt fails.
Note: If the domain is specified in wszUser, which is the preferred location, then it must not be specified here. Specifying the domain in both parameters results in an Invalid Parameter error.
iSecurityFlagsOptional. Used to pass flag values to the ConnectServer method of the ISWbemLocator interface.
0 (&h0): A value of 0 for this parameter causes the call to ConnectServer to return only after the connection to the server is established. This could cause your program to stop responding indefinitely if the connection cannot be established.
wbemConnectFlagUseMaxWait (128 (&H80))<> The ConnectServer call is guaranteed to return in 2 minutes or less. Use this flag to prevent your program from ceasing to respond indefinitely if the connection cannot be established.

Return value

If successful, WMI returns an SWbemServices object that is bound to the namespace that is specified in wszNamespace on the computer that is specified in wszServer.

Usage example (with the local computer):

Description

Connects to the namespace that is specified on the wszNamespace parameter on the computer that is specified in the wszServer parameter. The target computer can be either local or remote, but it must have WMI installed.

Remarks

The ConnectServer method is often used when connecting to an account with a different username and password—credentials—on a remote computer because you cannot specify a different password in a moniker string.

Using an IPv4 address to connect to a remote server may result in unexpected behavior. The likely cause is stale DNS entries in your environment. In these circumstances, the stale PTR entry for the machine will be used, with unpredictable results. To avoid this behavior, you can append a period (".") to the IP address before calling ConnectServer. This causes the reverse DNS lookup to fail, but may allow the ConnectServer call to succeed on the correct machine.

Example

DIM pServices AS CWmiServices = CWmiServices(".", "root\cimv2")

Reference