WSManCreateSession function (wsman.h)

Creates a session object.


DWORD WSManCreateSession(
  [in]           WSMAN_API_HANDLE                 apiHandle,
  [in, optional] PCWSTR                           connection,
                 DWORD                            flags,
  [in, optional] WSMAN_AUTHENTICATION_CREDENTIALS *serverAuthenticationCredentials,
  [in, optional] WSMAN_PROXY_INFO                 *proxyInfo,
  [out]          WSMAN_SESSION_HANDLE             *session


[in] apiHandle

Specifies the API handle returned by the WSManInitialize call. This parameter cannot be NULL.

[in, optional] connection

Indicates to which protocol and agent to connect. If this parameter is NULL, the connection will default to localhost ( This parameter can be a simple host name or a complete URL. The format is the following:

[transport://]host[:port][/prefix] where:

Element Description
transport Either HTTP or HTTPS. Default is HTTP.
host Can be in a DNS name, NetBIOS name, or IP address.
port Defaults to 80 for HTTP and to 443 for HTTPS. The defaults can be changed in the local configuration.
prefix Any string. Default is "wsman". The default can be changed in the local configuration.


Reserved for future use. Must be zero.

[in, optional] serverAuthenticationCredentials

Defines the authentication method such as Negotiate, Kerberos, Digest, Basic, or client certificate. If the authentication mechanism is Negotiate, Kerberos, Digest, or Basic, the structure can also contain the credentials used for authentication. If client certificate authentication is used, the certificate thumbprint must be specified.

If credentials are specified, this parameter contains the user name and password of a local account or domain account. If this parameter is NULL, the default credentials are used. The default credentials are the credentials that the current thread is executing under. The client must explicitly specify the credentials when Basic or Digest authentication is used. If explicit credentials are used, both the user name and the password must be valid. For more information about the authentication credentials, see the WSMAN_AUTHENTICATION_CREDENTIALS structure.

[in, optional] proxyInfo

A pointer to a WSMAN_PROXY_INFO structure that specifies proxy information. This value can be NULL.

[out] session

Defines the session handle that uniquely identifies the session. This parameter cannot be NULL. This handle should be closed by calling the WSManCloseSession method.

Return value

If the function succeeds, the return value is zero. Otherwise, the return value is an error code.


Minimum supported client Windows 7
Minimum supported server Windows Server 2008 R2
Target Platform Windows
Header wsman.h
Library WsmSvc.lib
DLL WsmSvc.dll
Redistributable Windows Management Framework on Windows Server 2008 with SP2 and Windows Vista with SP2