WSManCreateShell function

Creates a shell object. The returned shell handle identifies an object that defines the context in which commands can be run. The context is defined by the environment variables, the input and output streams, and the working directory. The context can directly affect the behavior of a command. A shell context is created on the remote computer specified by the connection parameter and authenticated by using the credentials parameter.


void WINAPI WSManCreateShell(
  _Inout_  HANDLE                   session,
           DWORD                    flags,
  _In_     PCWSTR                   resourceUri,
  _In_opt_ WSMAN_SHELL_STARTUP_INFO *startupInfo,
  _In_opt_ WSMAN_OPTION_SET         *options,
  _In_opt_ WSMAN_DATA               *createXml,
  _In_     WSMAN_SHELL_ASYNC        *async,
  _Out_    HANDLE                   *shell


session [in, out]

Specifies the session handle returned by a WSManCreateSession call. This parameter cannot be NULL.


Reserved for future use. Must be zero.

resourceUri [in]

Defines the shell type to create. The shell type is defined by a unique URI. The actual shell object returned by the call is dependent on the URI specified. This parameter cannot be NULL. To create a Windows cmd.exe shell, use the WSMAN_CMDSHELL_URI resource URI.

startupInfo [in, optional]

A pointer to a WSMAN_SHELL_STARTUP_INFO structure that specifies the input and output streams, working directory, idle time-out, and options for the shell. If this parameter is NULL, the default values will be used.

options [in, optional]

A pointer to a WSMAN_OPTION_SET structure that specifies a set of options for the shell.

createXml [in, optional]

A pointer to a WSMAN_DATA structure that defines an open context for the shell. The content should be a valid XML string. This parameter can be NULL.

async [in]

Defines an asynchronous structure. The asynchronous structure contains an optional user context and a mandatory callback function. See the WSMAN_SHELL_ASYNC structure for more information. This parameter cannot be NULL and should be closed by calling the WSManCloseShell method.

shell [out]

Defines a shell handle that uniquely identifies the shell object. The resource handle is used to track the client endpoint for the shell and is used by other WinRM methods to interact with the shell object. The shell object should be deleted by calling the WSManCloseShell method. This parameter cannot be NULL.

Return value

This function does not return a value.


Minimum supported client

Windows 7

Minimum supported server

Windows Server 2008 R2


Windows Management Framework on Windows Server 2008 with SP2 and Windows Vista with SP2