Skip to main content
WSManRunShellCommand function

Starts the execution of a command within an existing shell and does not wait for the completion of the command.


void WINAPI WSManRunShellCommand(
  _Inout_  HANDLE                shell,
           DWORD                 flags,
  _In_     PCWSTR                commandLine,
  _In_opt_ WSMAN_COMMAND_ARG_SET *args,
  _In_opt_ WSMAN_OPTION_SET      *options,
  _In_     WSMAN_SHELL_ASYNC     *async,
  _Out_    HANDLE                *command


shell [in, out]

Specifies the shell handle returned by the WSManCreateShell call. This parameter cannot be NULL.


Reserved for future use. Must be zero.

commandLine [in]

Defines a required null-terminated string that represents the command to be executed. Typically, the command is specified without any arguments, which are specified separately. However, a user can specify the command line and all of the arguments by using this parameter. If arguments are specified for the commandLine parameter, the args parameter should be NULL.

args [in, optional]

A pointer to a WSMAN_COMMAND_ARG_SET structure that defines an array of argument values, which are passed to the command on creation. If no arguments are required, this parameter should be NULL.

options [in, optional]

Defines a set of options for the command. These options are passed to the service to modify or refine the command execution. This parameter can be NULL. For more information about the options, see WSMAN_OPTION_SET.

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 WSManCloseCommand method.

command [out]

Defines the command object associated with a command within a shell. This handle is returned on a successful call and is used to send and receive data and to signal the command. This handle should be closed by calling the WSManCloseCommand 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