' ########################################################################################
' Microsoft Windows
' File: wsman.inc
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_wsman_PBI)
#DEFINE PBX_wsman_PBI
%EQUATE `WSMAN_INC = 1
'#include <specstrings.h>
'#if defined(WSMAN_API_VERSION_1_0)
'#else
'#error "Define WSMAN_API_VERSION_1_0 before including wsman.h"
'#endif
'//
'// -----------------------------------------------------------------------------
'// WSMan - Public Client API v1.0
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// BEGIN COMMON: Shared between client and plug-in
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// Structure for a data object. These structures are used as output and input
'// to operations. Eg, output from a WSManReceiveShellOutput and input to a
'// WSManSendShellInput.
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// data as text
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_DATA_TEXT DWORD
 bufferLength AS DWORD
 buffer AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// binary data used by API like for example WSManSendShellInput and
'// WSManReceiveShellOutput for Shell API, the data can be stream text
'// (ANSI/UNICODE), binary content or objects or partial or full XML
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_DATA_BINARY DWORD
 dataLength AS DWORD
 data AS BYTE PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// type of the data used by the WSMAN_DATA structure
'// -----------------------------------------------------------------------------
'//
' enum WSManDataType
%EQUATE `WSMAN_DATA_NONE = 0
%EQUATE `WSMAN_DATA_TYPE_TEXT = 1
%EQUATE `WSMAN_DATA_TYPE_BINARY = 2
%EQUATE `WSMAN_DATA_TYPE_DWORD = 4
'//
'// -----------------------------------------------------------------------------
'// Structure used to pass data as XML text, binary data or DWORD
'// -----------------------------------------------------------------------------
'//
' // Size = 4 bytes
UNION WSMAN_DATA_UNION DWORD
 text AS WSMAN_DATA_TEXT ' WSMAN_DATA_TEXT
 binaryData AS WSMAN_DATA_BINARY ' WSMAN_DATA_BINARY
 number AS DWORD
END UNION
' // Size = 8 bytes
TYPE WSMAN_DATA DWORD
 type AS LONG ' WSManDataType
 WSMAN_DATA_UNION
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Error structure containing fault code (a Windows error code that maps to
'// a SOAP fault) and extended error information.
'// The extended error information is the soap fault description from the protocol layer
'// including the machine where the fault was reported as well as plug-in
'// specific error text.
'//
'// This error structure is used by callbacks to return detailed error information.
'//
'// The error structure can contain also a transport error.
'// -----------------------------------------------------------------------------
'//
' // Size = 20 bytes
TYPE WSMAN_ERROR DWORD
 code AS DWORD
 ' // extended error information
 errorDetail AS WSTRINGZ PTR
 ' // it can be NULL, for example in out of memory conditions
 language AS WSTRINGZ PTR
 machineName AS WSTRINGZ PTR
 pluginName AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Username and password on the remote machine
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_USERNAME_PASSWORD_CREDS DWORD
 username AS WSTRINGZ PTR
 password AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// flags used by the authenticationMechanism member of WSMAN_AUTHENTICATION_CREDENTIALS structure
'// -----------------------------------------------------------------------------
'//
' enum WSManAuthenticationFlags
%EQUATE `WSMAN_FLAG_DEFAULT_AUTHENTICATION = &H0 ' // Use the default authentication
%EQUATE `WSMAN_FLAG_NO_AUTHENTICATION = &H1 ' // Use no authentication for a remote operation
%EQUATE `WSMAN_FLAG_AUTH_DIGEST = &H2 ' // Use digest authentication for a remote operation
%EQUATE `WSMAN_FLAG_AUTH_NEGOTIATE = &H4 ' // Use negotiate authentication for a remote operation (may use kerberos or ntlm)
%EQUATE `WSMAN_FLAG_AUTH_BASIC = &H8 ' // Use basic authentication for a remote operation
%EQUATE `WSMAN_FLAG_AUTH_KERBEROS = &H10 ' // Use kerberos authentication for a remote operation
'#if (WINVER >= &H600)
%EQUATE `WSMAN_FLAG_AUTH_CREDSSP = &H80 ' // Use CredSSP authentication for a remote operation
'#endif
%EQUATE `WSMAN_FLAG_AUTH_CLIENT_CERTIFICATE = &H20 ' // Use client certificate authentication for a remote operation
'//
'// -----------------------------------------------------------------------------
'// Structure for passing the credentials and the authentication mechanism
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
UNION WSMAN_AUTHENTICATION_CREDENTIALS_UNION DWORD
 userAccount AS WSMAN_USERNAME_PASSWORD_CREDS
 certificateThumbprint AS WSTRINGZ PTR
END UNION
' // Size = 12 bytes
TYPE WSMAN_AUTHENTICATION_CREDENTIALS DWORD
 authenticationMechanism AS DWORD ' DWORD // can be 0 (the user did not specify an
 ' // authentication mechanism, WSMan client
 ' // will choose between Kerberos and Negotiate only);
 ' // if it is not 0, it must be one of the
 ' // values from WSManAuthenticationFlags
 ' // enumeration
 WSMAN_AUTHENTICATION_CREDENTIALS_UNION
END TYPE
'//
'// -----------------------------------------------------------------------
'// Options
'// -----------------------------------------------------------------------
'//
' // Size = 12 bytes
TYPE WSMAN_OPTION DWORD
 name AS WSTRINGZ PTR
 value AS WSTRINGZ PTR
 mustComply AS LONG
END TYPE
' // Size = 12 bytes
TYPE WSMAN_OPTION_SET DWORD
 optionsCount AS DWORD
 options AS WSMAN_OPTION PTR
 optionsMustUnderstand AS LONG
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Structures containing information for addressing the endpoint.
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_KEY DWORD
 key AS WSTRINGZ PTR
 value AS WSTRINGZ PTR
END TYPE
' // Size = 8 bytes
TYPE WSMAN_SELECTOR_SET DWORD
 numberKeys AS DWORD ' DWORD // Number of keys (selectors)
 keys AS WSMAN_KEY PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Structure reserved for future use (Fragment Level WS-Transfer)
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_FRAGMENT DWORD
 path AS WSTRINGZ PTR
 dialect AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Structure reserved for future use (Filter Enumeration/Eventing)
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_FILTER DWORD
 filter AS WSTRINGZ PTR
 dialect AS WSTRINGZ PTR
END TYPE
' // Size = 36 bytes
TYPE WSMAN_OPERATION_INFO DWORD
 fragment AS WSMAN_FRAGMENT
 filter AS WSMAN_FILTER
 selectorSet AS WSMAN_SELECTOR_SET
 optionSet AS WSMAN_OPTION_SET
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Client Initialization/Deinitialization functions
'// -----------------------------------------------------------------------------
'//
'typedef struct WSMAN_API *WSMAN_API_HANDLE;
'//
'// -----------------------------------------------------------------------------
'// This API is used to initialize the WinRM client;
'// It can be used by different clients on the same process, ie svchost.exe.
'// Returns a nonzero error code upon failure
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManInitialize LIB "wsmsvc.dll" ALIAS "WSManInitialize" ( BYVAL flags AS QUAD , BYREF apiHandle AS QUAD ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// This API deinitializes the Winrm client stack; all operations will
'// finish before this API will return; this is a sync call;
'// it is highly recommended that all operations are explictly cancelled
'// and all sessions are closed before calling this API
'// Returns non zero error code upon failure
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManDeinitialize LIB "wsmsvc.dll" ALIAS "WSManDeinitialize" ( BYVAL flags AS QUAD , BYREF apiHandle AS QUAD ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// This API returns a NULL terminated unicode string containing the message
'// of an error number and an optional language identifier. The optional
'// parameter languageCode specifies the UI language as RFC 3066 language code
'// that should be used to localize the message (if not specified, the thread's
'// UI language will be used). If the function cannot find a message for that
'// language, it returns ERROR_RESOURCE_LANG_NOT_FOUND. The function copies
'// the formatted message text to an output buffer.
'//
'// Returns non zero error code upon failure. If the output buffer is not
'// big enough or NULL, the function returns ERROR_INSUFFICIENT_BUFFER and
'// the messageLengthUsed parameter contains the requested size of the buffer.
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManGetErrorMessage LIB "wsmsvc.dll" ALIAS "WSManGetErrorMessage" ( BYREF apiHandle AS QUAD , BYVAL flags AS QUAD , BYREF languageCode AS WSTRINGZ , BYVAL errorCode AS QUAD , BYVAL messageLength AS QUAD , BYREF message AS WSTRINGZ , BYREF messageLengthUsed AS QUAD ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// Unsigned long integer value that contains the proxy access type
'// By default, wsman uses WSMAN_OPTION_PROXY_WINHTTP_PROXY_CONFIG -
'// the proxy settings configured for WinHTTP. The WinHTTP proxy settings
'// can be set with Proxycfg.exe or by using netsh command.
'// When WSMAN_OPTION_PROXY_IE_PROXY_CONFIG is specified, the current user's
'// Internet Explorer proxy settings for the current active network connection.
'// This option requires the user profile to be loaded, so the option can
'// be directly used when called within a process that is running under
'// an interactive user account identity; if the client application is running
'// under a user context different then the interactive user, the client
'// application has to explicitly load the user profile prior to using this option.
'// IMPORTANT: proxy configuration is supported for HTTPS only; for HTTP, the direct
'// connection to the server is used
'// -----------------------------------------------------------------------------
'//
' enum WSManProxyAccessType
%EQUATE `WSMAN_OPTION_PROXY_IE_PROXY_CONFIG = 1 ' // use the Internet Explorer proxy configuration for the current user
%EQUATE `WSMAN_OPTION_PROXY_WINHTTP_PROXY_CONFIG = 2 ' // default: proxy settings configured for WinHTTP, using the ProxyCfg.exe utility
%EQUATE `WSMAN_OPTION_PROXY_AUTO_DETECT = 4 ' // Force autodetection of proxy
%EQUATE `WSMAN_OPTION_PROXY_NO_PROXY_SERVER = 8 ' // do not use a proxy server - resolves all host names locally
'//
'// -----------------------------------------------------------------------------
'// Structure used to set the proxy information per session
'// -----------------------------------------------------------------------------
'//
' // Size = 16 bytes
TYPE WSMAN_PROXY_INFO DWORD
 accessType AS DWORD
 authenticationCredentials AS WSMAN_AUTHENTICATION_CREDENTIALS
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Client Session
'// -----------------------------------------------------------------------------
'//
'typedef struct WSMAN_SESSION *WSMAN_SESSION_HANDLE;
'//
'// -----------------------------------------------------------------------------
'// Creates a session which can be used to perform subsequent operations
'// Returns a non zero error code upon failure
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManCreateSession LIB "wsmsvc.dll" ALIAS "WSManCreateSession" ( BYVAL apiHandle AS QUAD , BYREF connection AS WSTRINGZ , BYVAL flags AS QUAD , BYREF serverAuthenticationCredentials AS WSMAN_AUTHENTICATION_CREDENTIALS , BYREF proxyInfo AS WSMAN_PROXY_INFO , BYREF session AS QUAD ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// Frees memory of session and closes all related operations before returning; this is sync call
'// it is recommended that all pending operations are either completed or cancelled before calling this API
'// Returns a non zero error code upon failure
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManCloseSession LIB "wsmsvc.dll" ALIAS "WSManCloseSession" ( BYVAL session AS QUAD , BYVAL flags AS QUAD ) AS QUAD
'//
'// default operation timeout for network operations - 1 min = 60000ms
'//
%EQUATE `WSMAN_DEFAULT_TIMEOUT_MS = 60000
'//
'// -----------------------------------------------------------------------------
'// Extended options set for the session
'// -----------------------------------------------------------------------------
'//
' enum WSManSessionOption
' //
' // Timeouts
' //
%EQUATE `WSMAN_OPTION_DEFAULT_OPERATION_TIMEOUTMS = 1 ' // DWORD - default timeout in ms that applies to all operations on the client side
%EQUATE `WSMAN_OPTION_TIMEOUTMS_CREATE_SHELL = 12 ' // DWORD - timeout in ms for WSManCreateShell operations
%EQUATE `WSMAN_OPTION_TIMEOUTMS_RUN_SHELL_COMMAND = 13 ' // DWORD - timeout in ms for WSManRunShellCommand operations
%EQUATE `WSMAN_OPTION_TIMEOUTMS_RECEIVE_SHELL_OUTPUT = 14 ' // DWORD - timeout in ms for WSManReceiveShellOutput operations
%EQUATE `WSMAN_OPTION_TIMEOUTMS_SEND_SHELL_INPUT = 15 ' // DWORD - timeout in ms for WSManSendShellInput operations
%EQUATE `WSMAN_OPTION_TIMEOUTMS_SIGNAL_SHELL = 16 ' // DWORD - timeout in ms for WSManSignalShell and WSManCloseCommand operations
%EQUATE `WSMAN_OPTION_TIMEOUTMS_CLOSE_SHELL = 17 ' // DWORD - timeout in ms for WSManCloseShell operations
' //
' // connection options
' //
%EQUATE `WSMAN_OPTION_SKIP_CA_CHECK = 18 ' // DWORD - 1 to not validate the CA on the server certificate; 0 - default
%EQUATE `WSMAN_OPTION_SKIP_CN_CHECK = 19 ' // DWORD - 1 to not validate the CN on the server certificate; 0 - default
%EQUATE `WSMAN_OPTION_UNENCRYPTED_MESSAGES = 20 ' // DWORD - 1 to not encrypt the messages; 0 - default
%EQUATE `WSMAN_OPTION_UTF16 = 21 ' // DWORD - 1 Send all network packets for remote operatons in UTF16; 0 - default is UTF8
%EQUATE `WSMAN_OPTION_ENABLE_SPN_SERVER_PORT = 22 ' // DWORD - 1 When using negotiate, include port number in the connection SPN; 0 - default
 ' // Used when not talking to the main OS on a machine but, for instance, a BMC
%EQUATE `WSMAN_OPTION_MACHINE_ID = 23 ' // DWORD - 1 Identify this machine to the server by including the MachineID header; 0 - default
' //
' // other options
' //
%EQUATE `WSMAN_OPTION_LOCALE = 25 ' // string - RFC 3066 language code
%EQUATE `WSMAN_OPTION_UI_LANGUAGE = 26 ' // string - RFC 3066 language code
%EQUATE `WSMAN_OPTION_MAX_ENVELOPE_SIZE_KB = 28 ' // DWORD - max SOAP envelope size (kb) - default 150kb from winrm config
 ' // (see 'winrm help config' for more details); the client SOAP packet size cannot surpass
 ' // this value; this value will be also sent to the server in the SOAP request as a
 ' // MaxEnvelopeSize header; the server will use min(MaxEnvelopeSizeKb from server configuration,
 ' // MaxEnvelopeSize value from SOAP).
%EQUATE `WSMAN_OPTION_SHELL_MAX_DATA_SIZE_PER_MESSAGE_KB = 29 ' // DWORD (read only) - max data size (kb) provided by the client, guaranteed by
 ' // the winrm client implementation to fit into one SOAP packet; this is an
 ' // approximate value calculated based on the %WSMAN_OPTION_MAX_ENVELOPE_SIZE_KB (default 150kb),
 ' // the maximum possible size of the SOAP headers and the overhead of the base64
 ' // encoding which is specific to WSManSendShellInput API; this option can be used
 ' // with WSManGetSessionOptionAsDword API; it cannot be used with WSManSetSessionOption API.
%EQUATE `WSMAN_OPTION_REDIRECT_LOCATION = 30 ' // string - read-only, cannot set
%EQUATE `WSMAN_OPTION_SKIP_REVOCATION_CHECK = 31 ' // DWORD - 1 to not validate the revocation status on the server certificate; 0 - default
%EQUATE `WSMAN_OPTION_ALLOW_NEGOTIATE_IMPLICIT_CREDENTIALS = 32 ' // DWORD - 1 to allow default credentials for Negotiate (this is for SSL only); 0 - default
%EQUATE `WSMAN_OPTION_USE_SSL = 33 ' // DWORD - When using just a machine name in the connection string use an SSL connection. 0 means HTTP, 1 means HTTPS. Default is 0.
'//
'// -----------------------------------------------------------------------------
'// WSManSetSessionOption API - set session options
'// Returns a non zero error code upon failure
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManSetSessionOption LIB "wsmsvc.dll" ALIAS "WSManSetSessionOption" ( BYVAL session AS QUAD , BYVAL option AS LONG , BYREF data AS WSMAN_DATA ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// WSManGetSessionOptionAsDword API - get a session option
'// Returns a non zero error code upon failure
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManGetSessionOptionAsDword LIB "wsmsvc.dll" ALIAS "WSManGetSessionOptionAsDword" ( BYVAL session AS QUAD , BYVAL option AS LONG , BYREF value AS QUAD ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// WSManGetSessionOptionAsString API - get a session option
'// Returns a non zero error code upon failure
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManGetSessionOptionAsString LIB "wsmsvc.dll" ALIAS "WSManGetSessionOptionAsString" ( BYVAL session AS QUAD , BYVAL option AS LONG , BYVAL stringLength AS QUAD , BYREF string AS WSTRINGZ , BYREF stringLengthUsed AS QUAD ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// Handle returned by WS-Transfer and WS-Enumerate operations
'// -----------------------------------------------------------------------------
'//
'typedef struct WSMAN_OPERATION *WSMAN_OPERATION_HANDLE;
'//
'// -----------------------------------------------------------------------------
'// flags used by WSMAN_SHELL_COMPLETION_FUNCTION callback function
'// -----------------------------------------------------------------------------
'//
' enum WSManCallbackFlags
'//
'// Flag that marks the end of any single step of multistep operation
'//
%EQUATE `WSMAN_FLAG_CALLBACK_END_OF_OPERATION = &H1
'//
'// WSMAN_SHELL_COMPLETION_FUNCTION API specific flags
'// end of a particular stream; it is used for optimization purposes if the shell
'// knows that no more output will occur for this stream; in some conditions this
'// cannot be determined.
'//
%EQUATE `WSMAN_FLAG_CALLBACK_END_OF_STREAM = &H8
'//
'// -----------------------------------------------------------------------------
'// Closes an asynchronous operation; if the callback associated with the operation
'// is pending and have not completed when WSManCloseOperation is called, then
'// the function marks the operation for deletion and returns; If the callback was not called,
'// the operation is cancelled and the operation callback is called with
'// WSMAN_ERROR_OPERATION_ABORTED error; the operation handle is freed in all cases
'// after the callback returns.
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManCloseOperation LIB "wsmsvc.dll" ALIAS "WSManCloseOperation" ( BYVAL operationHandle AS QUAD , BYVAL flags AS QUAD ) AS QUAD
'//
'//------------------------------------------------------------------------
'// Shell Client API
'// The API set includes the ability to create a shell, execute one or
'// more commands, possibly pipe input stream to the command, collect the
'// output stream from the command, terminate the command and finally
'// close the shell. The client must retrieve the output initiating
'// a WSManReceiveShellOutput once; the underlying implementation will
'// handle pulling the data from the command, until the command is done.
'// For each received stream, the completion function will be called with
'// the status of the command.
'//
'// WSManCloseCommand or WSManCloseShell can be called any time to close the
'// commmand or a shell operation. The callback will be called with
'// WSMAN_FLAG_CALLBACK_END_OF_OPERATION flag to mark the end of the operation.
'// See WSManCloseCommand/WSManCloseShell API description for more info.
'// -----------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------
'// Shell handle returned by WSManCreateShell API
'// -----------------------------------------------------------------------
'//
'typedef struct WSMAN_SHELL *WSMAN_SHELL_HANDLE;
'//
'// -----------------------------------------------------------------------
'// Command handle returned by WSManRunShellCommand API
'// -----------------------------------------------------------------------
'//
'typedef struct WSMAN_COMMAND *WSMAN_COMMAND_HANDLE;
'//
'// -----------------------------------------------------------------------
'// predefined stream ids
'// -----------------------------------------------------------------------
'//
$$WSMAN_STREAM_ID_STDIN = "stdin"$$
$$WSMAN_STREAM_ID_STDOUT = "stdout"$$
$$WSMAN_STREAM_ID_STDERR = "stderr"$$
'//
'// -----------------------------------------------------------------------
'// stream selector - array of stream ids; ie L"stdin" or L"stdout" or L"stderr"
'// -----------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_STREAM_ID_SET DWORD
 streamIDsCount AS DWORD
 streamIDs AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------
'// Environment variable
'// -----------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_ENVIRONMENT_VARIABLE DWORD
 name AS WSTRINGZ PTR
 value AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------
'// environment variable set - array of environment variables
'// -----------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_ENVIRONMENT_VARIABLE_SET DWORD
 varsCount AS DWORD
 vars AS WSMAN_ENVIRONMENT_VARIABLE PTR
END TYPE
'//
'// -----------------------------------------------------------------------
'// Shell initialization parameters
'// -----------------------------------------------------------------------
'//
' // Size = 20 bytes
TYPE WSMAN_SHELL_STARTUP_INFO DWORD
 inputStreamSet AS WSMAN_STREAM_ID_SET PTR ' WSMAN_STREAM_ID_SET *
 outputStreamSet AS WSMAN_STREAM_ID_SET PTR ' WSMAN_STREAM_ID_SET *
 idleTimeoutMs AS DWORD
 workingDirectory AS WSTRINGZ PTR
 variableSet AS WSMAN_ENVIRONMENT_VARIABLE_SET PTR ' WSMAN_ENVIRONMENT_VARIABLE_SET *
END TYPE
'//
'// -----------------------------------------------------------------------
'// Pre-defined URIs
'// -----------------------------------------------------------------------
'//
'#define WSMAN_SHELL_NS_LEN (sizeof(WSMAN_SHELL_NS)/sizeof(WCHAR)-1)
$$WSMAN_SHELL_NS = "http://schemas.microsoft.com/wbem/wsman/1/windows/shell"$$
'//
'// -----------------------------------------------------------------------
'// URI to create a Windows command shell; used with WSManCreateShell API
'// -----------------------------------------------------------------------
'//
$$WSMAN_CMDSHELL_URI = $$WSMAN_SHELL_NS & "/cmd"$$
'//
'// -----------------------------------------------------------------------
'// Windows shell options
'// -----------------------------------------------------------------------
'//
' enum WSManShellFlag
'//Turn off compression for Send/Receive operations. By default compression is
'//turned on, but if communicating with a down-level box it may be necessary to
'//do this. Other reasons for turning it off is due to the extra memory consumption
'//and CPU utilization that is used as a result of compression.
%EQUATE `WSMAN_FLAG_NO_COMPRESSION = 1
'//
'// -----------------------------------------------------------------------
'// Windows command shell specific options
'// -----------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------
'// Code page option name to be used with WSManCreateShell
'// API to remotely set the code page
'// -----------------------------------------------------------------------
'//
$$WSMAN_CMDSHELL_OPTION_CODEPAGE = "WINRS_CODEPAGE"$$
'//
'// -----------------------------------------------------------------------
'// Option name used with WSManCreateShell API to not load the
'// user profile on the remote server
'// -----------------------------------------------------------------------
'//
$$WSMAN_SHELL_OPTION_NOPROFILE = "WINRS_NOPROFILE"$$
'//
'// -----------------------------------------------------------------------
'// Option name used with WSManRunShellCommand API to
'// indicate that the client side mode of standard input is Console;
'// default implies Pipe.
'// -----------------------------------------------------------------------
'//
$$WSMAN_CMDSHELL_OPTION_CONSOLEMODE_STDIN = "WINRS_CONSOLEMODE_STDIN"$$
'//
'// -----------------------------------------------------------------------
'// to be used with WSManRunShellCommand API to not use cmd.exe /c prefix when launching the command
'// -----------------------------------------------------------------------
'//
$$WSMAN_CMDSHELL_OPTION_SKIP_CMD_SHELL = "WINRS_SKIP_CMD_SHELL"$$
'//
'// -----------------------------------------------------------------------
'// pre-defined command states
'// -----------------------------------------------------------------------
'//
$$WSMAN_COMMAND_STATE_DONE = $$WSMAN_SHELL_NS & "/CommandState/Done"$$
$$WSMAN_COMMAND_STATE_PENDING = $$WSMAN_SHELL_NS & "/CommandState/Pending"$$
$$WSMAN_COMMAND_STATE_RUNNING = $$WSMAN_SHELL_NS & "/CommandState/Running"$$
'//
'// -----------------------------------------------------------------------
'// Data structure returned after a Receive operation; each WSMAN_RECEIVE_DATA_RESULT
'// has a stream element with data that can be text (ANSI/UNICODE), binary content,
'// objects, or partial or full XML. In addition, the command state is reported
'// to the client and exitCode if the command is done.
'//
'// This structure is allocated and owned by the winrm stack and it is valid
'// in the completion function only
'// -----------------------------------------------------------------------
'//
' // Size = 24 bytes
TYPE WSMAN_RECEIVE_DATA_RESULT
 streamId AS WSTRINGZ PTR ' PCWSTR // string - any output stream name from the list passed to
 ' // the server when creating the shell
 streamData AS WSMAN_DATA ' WSMAN_DATA // always data as binary; can be stream text (ANSI/UNICODE), binary content or objects or partial or full XML
 ' // command state string values (shell specific) - the state of the command for which status is being reported
 commandState AS WSTRINGZ PTR ' PCWSTR // if WSMAN_COMMAND_STATE_DONE then the command should be closed at this moment
 exitCode AS DWORD
END TYPE
'//
'// -----------------------------------------------------------------------
'// Completion function used by all Shell functions
'// Returns error->code != 0 upon error; use error->errorDetail structure
'// for extended error informations; the callback is called for each
'// shell operation; after a WSManReceiveShellOutput operation is initiated,
'// the callback is called for each output stream element or if error;
'// the underlying implementation handles the polling of stream data
'// from the command or shell. If WSMAN_COMMAND_STATE_DONE state is received, no more
'// streams will be received from the command, so the command can be closed
'// using WSManCloseCommand(command).
'//
'// If error->code != 0, the result is guaranteed to be NULL
'//
'// The error and result objects are allocated and owned by the winrm
'// client stack; they are valid during the callback only; the user
'// has to synchronously copy the data in the callback
'//
'// This callback function will use the current access token, whether it is
'// a process or impersonation token.
'// -----------------------------------------------------------------------
'//
'typedef void (CALLBACK *WSMAN_SHELL_COMPLETION_FUNCTION)(
' DWORD flags, // one or more flags from WSManCallbackFlags
' // valid only within this function
' );
'SUB WSMAN_SHELL_COMPLETION_FUNCTION ( ' BYVAL operationContext AS DWORD
' , BYVAL flags AS DWORD
' , BYREF perror AS WSMAN_ERROR
' , BYVAL hshell AS DWORD
' , BYVAL pcommand AS DWORD
' , BYVAL operationHandle AS DWORD
' , BYREF pdata AS WSMAN_RECEIVE_DATA_RESULT
' ' // valid only within this function
'END SUB
'//
'// -----------------------------------------------------------------------------
'// Asynchronous structure to be passed to all Shell operations;
'// it contains an optional user context and the callback function
'// -----------------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_SHELL_ASYNC DWORD
 operationContext AS DWORD
 completionFunction AS DWORD
END TYPE
'//
'// -----------------------------------------------------------------------------
'// WSManCreateShell API - wxf:Create
'// -----------------------------------------------------------------------------
'//
DECLARE SUB WSManCreateShell LIB "wsmsvc.dll" ALIAS "WSManCreateShell" ( BYVAL session AS QUAD , BYREF flags AS WSTRINGZ , BYREF resourceUri AS WSTRINGZ , BYREF startupInfo AS WSMAN_SHELL_STARTUP_INFO , BYREF options AS WSMAN_OPTION_SET , BYREF createXml AS WSMAN_DATA , BYREF async AS WSMAN_SHELL_ASYNC , BYREF shell AS QUAD ) ' void
'//
'// -----------------------------------------------------------------------------
'// WSManRunShellCommand API - rsp:Command
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------
'// array of command arguments
'// -----------------------------------------------------------------------
'//
' // Size = 8 bytes
TYPE WSMAN_COMMAND_ARG_SET DWORD
 argsCount AS DWORD
 args AS WSTRINGZ PTR
END TYPE
DECLARE SUB WSManRunShellCommand LIB "wsmsvc.dll" ALIAS "WSManRunShellCommand" ( BYVAL shell AS QUAD , BYVAL flags AS QUAD , BYREF commandLine AS WSTRINGZ , BYREF args AS WSMAN_COMMAND_ARG_SET , BYREF options AS WSMAN_OPTION_SET , BYREF async AS WSMAN_SHELL_ASYNC , BYREF command AS QUAD ) ' void
'//
'// -----------------------------------------------------------------------------
'// WSManSignalShell API - rsp:Signal
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------
'// control codes for the command
'// -----------------------------------------------------------------------
'//
$$WSMAN_SIGNAL_SHELL_CODE_TERMINATE = $$WSMAN_SHELL_NS & "/signal/terminate"$$
$$WSMAN_SIGNAL_SHELL_CODE_CTRL_C = $$WSMAN_SHELL_NS & "/signal/ctrl_c"$$
$$WSMAN_SIGNAL_SHELL_CODE_CTRL_BREAK = $$WSMAN_SHELL_NS & "/signal/ctrl_break"$$
DECLARE SUB WSManSignalShell LIB "wsmsvc.dll" ALIAS "WSManSignalShell" ( BYVAL shell AS QUAD , BYVAL command AS QUAD , BYVAL flags AS QUAD , BYREF code AS WSTRINGZ , BYREF async AS WSMAN_SHELL_ASYNC , BYREF signalOperation AS QUAD ) ' void
'//
'// -----------------------------------------------------------------------------
'// WSManReceiveShellOutput API - rsp:Receive
'// -----------------------------------------------------------------------------
'//
DECLARE SUB WSManReceiveShellOutput LIB "wsmsvc.dll" ALIAS "WSManReceiveShellOutput" ( BYVAL shell AS QUAD , BYVAL command AS QUAD , BYVAL flags AS QUAD , BYREF desiredStreamSet AS WSMAN_STREAM_ID_SET , BYREF async AS WSMAN_SHELL_ASYNC , BYREF receiveOperation AS QUAD ) ' void
'//
'// -----------------------------------------------------------------------------
'// WSManSendShellInput API - rsp:Send
'// -----------------------------------------------------------------------------
'//
DECLARE SUB WSManSendShellInput LIB "wsmsvc.dll" ALIAS "WSManSendShellInput" ( BYVAL shell AS QUAD , BYVAL command AS QUAD , BYVAL flags AS QUAD , BYREF streamId AS WSTRINGZ , BYREF streamData AS WSMAN_DATA , BYVAL endOfStream AS LONG , BYREF async AS WSMAN_SHELL_ASYNC , BYREF sendOperation AS QUAD ) ' void
'//
'// -----------------------------------------------------------------------------
'// WSManCloseCommand API
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// Closes a command (signals the termination of a command); the WSManCloseCommand callback
'// is called with WSMAN_FLAG_CALLBACK_END_OF_OPERATION flag as result of this operation
'// -----------------------------------------------------------------------------
'//
DECLARE SUB WSManCloseCommand LIB "wsmsvc.dll" ALIAS "WSManCloseCommand" ( BYVAL commandHandle AS QUAD , BYVAL flags AS QUAD , BYREF async AS WSMAN_SHELL_ASYNC ) ' void
'//
'// -----------------------------------------------------------------------------
'// WSManCloseShell API
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// Closes a shell; the WSManCloseShell callback is called with
'// WSMAN_FLAG_CALLBACK_END_OF_OPERATION flag as result of this operation
'// -----------------------------------------------------------------------------
'//
DECLARE SUB WSManCloseShell LIB "wsmsvc.dll" ALIAS "WSManCloseShell" ( BYVAL shellHandle AS QUAD , BYVAL flags AS QUAD , BYREF async AS WSMAN_SHELL_ASYNC ) ' void
'//
'// -----------------------------------------------------------------------------
'// Plug-in APIs. These APIs are used by plug-ins for reporting results
'// -----------------------------------------------------------------------------
'//
'//
'// ------------------------------------------------------------------------
'// Sender information
'// ------------------------------------------------------------------------
'//
' // Size = 16 bytes
TYPE WSMAN_CERTIFICATE_DETAILS DWORD
 subject AS WSTRINGZ PTR ' PCWSTR // Certificate subject in distinguished form
 ' // Ex: "CN=xyz.com, OU=xyz management, O=Microsoft, L=Redmond, S=Washington, C=US"
 issuerName AS WSTRINGZ PTR ' PCWSTR // Certificate issuer in distinguished form
 ' // Ex: "CN=Microsoft Secure Server Authority, DC=redmond, DC=corp, DC=microsoft, DC=com"
 issuerThumbprint AS WSTRINGZ PTR ' PCWSTR // Thumbprint of Certificate issuer
 subjectName AS WSTRINGZ PTR ' PCWSTR // Certificate Subject Alternative Name (SAN) if available or subject Common Name (CN)
 ' // Ex: "xyz.com"
END TYPE
' // Size = 20 bytes
TYPE WSMAN_SENDER_DETAILS DWORD
 senderName AS WSTRINGZ PTR ' PCWSTR // Username of the sender
 authenticationMechanism AS WSTRINGZ PTR
 certificateDetails AS WSMAN_CERTIFICATE_DETAILS PTR ' WSMAN_CERTIFICATE_DETAILS * // valid only if the authentication is client certificates
 clientToken AS DWORD
 httpURL AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// A pointer to a WSMAN_PLUGIN_REQUEST structure is passed to all operation
'// entry points within the plug-in. All result notification APIs use this
'// pointer to match the result with the request. All information in the
'// structure will stay valid until the plug-in calls WSManPluginOperationComplete
'// on the operation. A plug-in has two ways of handling cancellation of an
'// operation. The plug-in can check the shutdownNotification boolean value
'// if it iterates through a set of results, or if the plug-in is more
'// asynchronous in nature then the shutdownNotificationHandle can be used
'// when queuing up asynchronous notification threads.
'// -----------------------------------------------------------------------------
'//
' // Size = 28 bytes
TYPE WSMAN_PLUGIN_REQUEST DWORD
 senderDetails AS WSMAN_SENDER_DETAILS PTR ' WSMAN_SENDER_DETAILS *
 locale AS WSTRINGZ PTR
 resourceUri AS WSTRINGZ PTR
 operationInfo AS WSMAN_OPERATION_INFO PTR ' WSMAN_OPERATION_INFO *
 shutdownNotification AS LONG ' volatile BOOL
 shutdownNotificationHandle AS DWORD
 dataLocale AS WSTRINGZ PTR
END TYPE
'//
'// -----------------------------------------------------------------------------
'// This API is called by a plug-in that supports Shell commands. When
'// Create Shell and Create Command plug-in entry points are called the plug-in
'// need to return a context to that shell or command before data can be channelled
'// into the plug-in, or before data can be returned to the called. WS-Man calls
'// the WSMAN_PLUGIN_RELEASE_SHELL_CONTEXT entry point during shell shutdown when
'// it is safe to delete the plug-in shell context, and WS-Man calls the
'// WSMAN_PLUGIN_RELEASE_COMMAND_CONTEXT entry point when it is safe to delete
'// the plug-in command context. Any context reported through
'// WSManPluginReportContext may not be deleted until the corresponding release
'// function has been called. Failure to follow the contract will result in
'// errors being generated.
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManPluginReportContext LIB "wsmsvc.dll" ALIAS "WSManPluginReportContext" ( BYREF requestDetails AS WSMAN_PLUGIN_REQUEST , BYVAL flags AS QUAD , BYVAL context AS QUAD ) AS QUAD
'typedef VOID (WINAPI *WSMAN_PLUGIN_RELEASE_SHELL_CONTEXT)(
' );
'SUB WSMAN_PLUGIN_RELEASE_SHELL_CONTEXT ( ' BYVAL shellContext AS DWORD
' )
'typedef VOID (WINAPI *WSMAN_PLUGIN_RELEASE_COMMAND_CONTEXT)(
' );
'SUB WSMAN_PLUGIN_RELEASE_COMMAND_CONTEXT ( ' BYVAL shellContext AS DWORD
' , BYVAL commandContext AS DWORD
' )
'//
'// -----------------------------------------------------------------------------
'// This API is used by most a shell plug-in to report data for the Receive
'// operation. This is the only operation that returns results that has a
'// different API due to the extra shell data that is needed. This API
'// is called for every result in the stream. Once all data is received
'// the WSManPluginOperationComplete API must be called.
'// stream and streamResult are one pair of information that if one parameter
'// is specified the other is needed otherwise ERROR_INVALID_PARAMETER is
'// returned. commandState and exitCode are also a pair, and exitCode is
'// ignored in all cases but when commandState is WSMAN_COMMAND_STATE_DONE
'// is specified. Both pairs of parameters are independent to each other
'// so the API can be used to register the stream data, command state or
'// both.
'// flags:
'// WSMAN_FLAG_RECEIVE_RESULT_NO_MORE_DATA
'// No more data on this stream. Only valid when a stream is specified.
'// WSMAN_FLAG_RECEIVE_FLUSH
'// Send the data as soon as possible. Normally data is held onto in
'// order to maximise the size of the response packet. This should
'// only be used if a request/response style of data is needed between
'// the send and receive data streams.
'// -----------------------------------------------------------------------------
'//
%EQUATE `WSMAN_FLAG_RECEIVE_RESULT_NO_MORE_DATA = 1
%EQUATE `WSMAN_FLAG_RECEIVE_FLUSH = 2
DECLARE FUNCTION WSManPluginReceiveResult LIB "wsmsvc.dll" ALIAS "WSManPluginReceiveResult" ( BYREF requestDetails AS WSMAN_PLUGIN_REQUEST , BYVAL flags AS QUAD , BYREF stream AS WSTRINGZ , BYREF streamResult AS WSMAN_DATA , BYREF commandState AS WSTRINGZ , BYVAL exitCode AS QUAD ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// This API is used by all plug-ins to report the completion of an operation.
'// For operations like Get, Put, Create and Invoke this API is likely to be
'// called after the result has been called. For Delete operations where no
'// result is needed other than status, this API is all that is needed.
'// For more complex operations like Enumerations, Subscriptions and shell
'// Receive operations this API is is used to report the completion of the
'// data stream. The Create Shell and Create Command operations must also
'// call this when the shell and command operations a completed fully.
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManPluginOperationComplete LIB "wsmsvc.dll" ALIAS "WSManPluginOperationComplete" ( BYREF requestDetails AS WSMAN_PLUGIN_REQUEST , BYVAL flags AS QUAD , BYVAL errorCode AS QUAD , OPTIONAL BYREF extendedErrorInformation AS WSTRINGZ ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'//This API is used to get operational information for items such as timeouts
'//and data restrictions associated with the operation. It is not recommended
'//that a plug-in handles these kinds of parameters for anything other than
'//informational use.
'//
'//Locale parameters return WSMAN_DATA_TEXT, which is owned internally,
'//so you don't need to delete the text buffers.
'// -----------------------------------------------------------------------------
'//
%EQUATE `WSMAN_PLUGIN_PARAMS_MAX_ENVELOPE_SIZE = 1
%EQUATE `WSMAN_PLUGIN_PARAMS_TIMEOUT = 2
%EQUATE `WSMAN_PLUGIN_PARAMS_REMAINING_RESULT_SIZE = 3
%EQUATE `WSMAN_PLUGIN_PARAMS_LARGEST_RESULT_SIZE = 4
%EQUATE `WSMAN_PLUGIN_PARAMS_GET_REQUESTED_LOCALE = 5 ' /* Returns WSMAN_DATA_TEXT */
%EQUATE `WSMAN_PLUGIN_PARAMS_GET_REQUESTED_DATA_LOCALE = 6 ' /* Returns WSMAN_DATA_TEXT */
DECLARE FUNCTION WSManPluginGetOperationParameters LIB "wsmsvc.dll" ALIAS "WSManPluginGetOperationParameters" ( BYREF requestDetails AS WSMAN_PLUGIN_REQUEST , BYVAL flags AS QUAD , BYREF data AS WSMAN_DATA ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// This API is used release memory that is held for the purpose of populating
'// the WSMAN_PLUGIN_REQUEST that is passed into operation plug-in entry points.
'// This API can be called any time between a plug-in entry point is called and
'// the entry point calling WSManPluginOperationComplete. This API does not need
'// to be called. Not calling it will result in all memory being freed up when
'// WSManPluginOperationComplete is called. Calling this method can result in
'// significant amounts of memory to be freed up. After calling this API
'// the plug-in must not access any member variables from within the
'// WSMAN_PLUGIN_REQUEST structure.
'// A good use of this API is in the following situation:
'// A plug-in implements the Shell infrastructure. The WSMAN_PLUGIN_SHELL
'// entry point is called and that method calls WSManPluginReportContext.
'// No other information from the shell WSMAN_PLUGIN_REQUEST is needed from this
'// point on and because WSManPluginOperationComplete is not called for
'// potentially a long time in the future, calling WSManPluginFreeRequestDetails
'// can potentially free a lot of resources. The command and receive entry
'// points are also good categories as they are called once, but the plugin may
'// not call the operation complete method for some time.
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManPluginFreeRequestDetails LIB "wsmsvc.dll" ALIAS "WSManPluginFreeRequestDetails" ( BYREF requestDetails AS WSMAN_PLUGIN_REQUEST ) AS QUAD
'//
'// -----------------------------------------------------------------------------
'// Plug-in DLL Entry points. A plug-in needs to have their catalog registered
'// with the WSMan service and it contains the names of the plug-in DLL entry
'// points. The entry points themselves need to conform to these prototype
'// definitions
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// Each plug-in needs to support the Startup callback. A plug-in may be
'// initialized more than once within the same process, but only once per
'// applicationIdentification.
'// -----------------------------------------------------------------------------
'//
'typedef DWORD (WINAPI *WSMAN_PLUGIN_STARTUP)(
' );
'FUNCTION WSMAN_PLUGIN_STARTUP ( ' BYVAL flags AS DWORD
' , BYREF applicationIdentification AS WSTRINGZ
' , BYREF extraInfo AS WSTRINGZ
' , BYREF pluginContext AS DWORD
' ) AS DWORD
'//
'// -----------------------------------------------------------------------------
'// Each plug-in needs to support the Shutdown callback. Each successful call
'// to Startup will result in a call to Shutdown before the DLL is unloaded.
'// It is important to make sure the plug-in tracks the number of times the
'// Startup entry point is called so the plug-in is not shutdown prematurely.
'// -----------------------------------------------------------------------------
'//
%EQUATE `WSMAN_PLUGIN_SHUTDOWN_SYSTEM = 1
%EQUATE `WSMAN_PLUGIN_SHUTDOWN_SERVICE = 2
%EQUATE `WSMAN_PLUGIN_SHUTDOWN_IISHOST = 3
'typedef DWORD (WINAPI *WSMAN_PLUGIN_SHUTDOWN)(
' );
'FUNCTION WSMAN_PLUGIN_SHUTDOWN ( ' BYVAL pluginContext AS DWORD
' , BYVAL flags AS DWORD
' , BYVAL reason AS DWORD
' ) AS DWORD
'//
'// -----------------------------------------------------------------------------
'// A plug-in that supports the Shell operations needs to implement this callback
'// to allow commands to be created and to allow data to be streamed into either
'// a shell or command. The plug-in must call WSManPluginReportContext to
'// report the shell context. Once the shell is completed or when it is closed
'// via the operationClosed boolean value or operationClosedHandle in the
'// requestDetails the plug-in needs to call WSManPluginOperationComplete.
'// The shell is active until this time.
'// -----------------------------------------------------------------------------
'//
'typedef VOID (WINAPI *WSMAN_PLUGIN_SHELL)(
' );
'SUB WSMAN_PLUGIN_SHELL ( ' BYVAL pluginContext AS DWORD
' , BYREF requestDetails AS WSMAN_PLUGIN_REQUEST
' , BYVAL flags AS DWORD
' , BYREF startupInfo AS WSMAN_SHELL_STARTUP_INFO
' , BYREF inboundShellInformation AS WSMAN_DATA
' ) ' void
'//
'// -----------------------------------------------------------------------------
'// A plug-in that supports the Shell operations and needs to create commands
'// that are associated with the shell needs to implement this callback.
'// The plug-in must call WSManPluginReportContext to
'// report the command context. Once the command is completed or when it is closed
'// via the operationClosed boolean value or operationClosedHandle in the
'// requestDetails the plug-in needs to call WSManPluginOperationComplete.
'// The command is active until this time.
'// -----------------------------------------------------------------------------
'//
'typedef VOID (WINAPI *WSMAN_PLUGIN_COMMAND)(
' );
'SUB WSMAN_PLUGIN_COMMAND ( ' BYREF requestDetails AS WSMAN_PLUGIN_REQUEST
' , BYVAL flags AS DWORD
' , BYVAL shellContext AS DWORD
' , BYREF commandLine AS WSTRINGZ
' , BYREF arguments AS WSMAN_COMMAND_ARG_SET
' ) ' void
'//
'// -----------------------------------------------------------------------------
'// A plug-in receives an inbound data stream to either the shell or command
'// via this callback. Each piece of data causes the callback to be called once.
'// For each piece of data the plug-in calls WSManPluginOperationComplete to
'// acknowledge receipt and to allow the next piece of data to be delivered.
'// -----------------------------------------------------------------------------
'//
%EQUATE `WSMAN_FLAG_SEND_NO_MORE_DATA = 1
'typedef VOID (WINAPI *WSMAN_PLUGIN_SEND)(
' );
'SUB WSMAN_PLUGIN_SEND ( ' BYREF requestDetails AS WSMAN_PLUGIN_REQUEST
' , BYVAL flags AS DWORD
' , BYVAL shellContext AS DWORD
' , BYVAL commandContext AS DWORD
' , BYREF stream AS WSTRINGZ
' , BYREF inboundData AS WSMAN_DATA
' ) ' void
'//
'// -----------------------------------------------------------------------------
'// A plug-in sends an outbound data stream from either the shell or command
'// via this callback. This API is called when an inbound request from a client
'// is received. This callback may be called against the shell and/or command
'// based on the client request. Each piece of data that needs to be sent back
'// to the client is done so through the WSManPluginReceiveResult API. Once
'// all data has been send, when the stream is terminated via some internal means,
'// or if the receive call is cancelled through the operationClosed boolean
'// value or operationClosedHandle, the plug-in needs to call
'// WSManPluginOperationComplete. The operation is marked as active until this
'// time.
'// -----------------------------------------------------------------------------
'//
'typedef VOID (WINAPI *WSMAN_PLUGIN_RECEIVE)(
' );
'SUB WSMAN_PLUGIN_RECEIVE ( ' BYREF requestDetails AS WSMAN_PLUGIN_REQUEST
' , BYVAL flags AS DWORD
' , BYVAL shellContext AS DWORD
' , BYVAL commandContext AS DWORD
' , BYREF streamSet AS WSMAN_STREAM_ID_SET
' ) ' void
'//
'// -----------------------------------------------------------------------------
'// A plug-in receives an inbound signal to either the shell or command
'// via this callback. Each signal causes the callback to be called once.
'// For each call the plug-in calls WSManPluginOperationComplete to
'// acknowledge receipt and to allow the next signal to be received.
'// A signal can cause the shell or command to be terminated, so the result
'// of this callback may be many completion calls for the Signal, Receive, Command
'// and Shell operations.
'// -----------------------------------------------------------------------------
'//
'typedef VOID (WINAPI *WSMAN_PLUGIN_SIGNAL)(
' );
'SUB WSMAN_PLUGIN_SIGNAL ( ' BYREF requestDetails AS WSMAN_PLUGIN_REQUEST
' , BYVAL flags AS DWORD
' , BYVAL shellContext AS DWORD
' , BYVAL commandContext AS DWORD
' , BYREF pcode AS WSTRINGZ
' ) ' void
'//
'// -----------------------------------------------------------------------------
'// Authorization Plug-in Structures
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// WSMAN_AUTHZ_QUOTA
'// Any of the maxAllowed entries can be set to MAX_DWORD to mark quota as
'// unlimited. If maxAllowedOperationsPerTimeslot is MAX_DWORD the timeslotSize
'// is ignored.
'// -----------------------------------------------------------------------------
'//
' // Size = 16 bytes
TYPE WSMAN_AUTHZ_QUOTA DWORD
 maxAllowedConcurrentShells AS DWORD
 maxAllowedConcurrentOperations AS DWORD
 timeslotSize AS DWORD
 maxAllowedOperationsPerTimeslot AS DWORD
END TYPE
'//
'// -----------------------------------------------------------------------------
'// Authorization Plug-in entry points
'// -----------------------------------------------------------------------------
'//
'//
'// -----------------------------------------------------------------------------
'// WSMAN_PLUGIN_AUTHORIZE_USER
'// Plug-in needs to have a DLL export of WSManPluginAuthzUser to handle this
'// request. When a user issues a request and has not made a request in
'// some configurable time this entry point is called to determin if the
'// user is allowed to carry out any request at all. The plug-in must call
'// WSManPluginAuthzUserComplete to report either the user is not authorized
'// with ERROR_ACCESS_DENIED or for successful authorization NO_ERROR.
'// ERROR_WSMAN_REDIRECT_REQUIRED should be reported if a HTTP redirect is
'// required for this user, in which case the new HTTP URI should be recorded
'// in the extendedErrorInformation. All other errors are report a failure
'// to the client but no specific information is reported.
'// -----------------------------------------------------------------------------
'//
'typedef VOID (WINAPI * WSMAN_PLUGIN_AUTHORIZE_USER)(
' );
'SUB WSMAN_PLUGIN_AUTHORIZE_USER ( ' BYVAL pluginContext AS DWORD
' , BYREF senderDetails AS WSMAN_SENDER_DETAILS
' , BYVAL flags AS DWORD
' ) ' void
'//
'// -----------------------------------------------------------------------------
'// WSMAN_PLUGIN_AUTHORIZE_USER
'// Plug-in needs to have a DLL export of WSManPluginAuthzOperation to handle this
'// request. The plug-in must call WSManPluginAuthzUserComplete to report either
'// the user is not authorized with ERROR_ACCESS_DENIED or for successful
'// authorization NO_ERROR. All other errors are reported as a failure
'// to the client as a SOAP fault with information given in the
'// extendedErrorInformation parameter.
'// -----------------------------------------------------------------------------
'//
'typedef VOID (WINAPI * WSMAN_PLUGIN_AUTHORIZE_OPERATION)(
' );
'SUB WSMAN_PLUGIN_AUTHORIZE_OPERATION ( ' BYVAL pluginContext AS DWORD
' , BYREF senderDetails AS WSMAN_SENDER_DETAILS
' , BYVAL flags AS DWORD
' , BYVAL operation AS DWORD
' , BYREF action AS WSTRINGZ
' , BYREF resourceUri AS WSTRINGZ
' ) ' void
'typedef VOID (WINAPI * WSMAN_PLUGIN_AUTHORIZE_QUERY_QUOTA)(
' );
'SUB WSMAN_PLUGIN_AUTHORIZE_QUERY_QUOTA ( ' BYVAL pluginContext AS DWORD
' , BYREF senderDetails AS WSMAN_SENDER_DETAILS
' , BYVAL flags AS DWORD
' ) ' void
'typedef VOID (WINAPI * WSMAN_PLUGIN_AUTHORIZE_RELEASE_CONTEXT)(
' );
'SUB WSMAN_PLUGIN_AUTHORIZE_RELEASE_CONTEXT ( ' BYVAL userAuthorizationContext AS DWORD
' ) ' void
'//
'// -----------------------------------------------------------------------------
'// Authorization Plug-in Callback methods
'// -----------------------------------------------------------------------------
'//
DECLARE FUNCTION WSManPluginAuthzUserComplete LIB "wsmsvc.dll" ALIAS "WSManPluginAuthzUserComplete" ( BYREF senderDetails AS WSMAN_SENDER_DETAILS , BYVAL flags AS QUAD , BYVAL userAuthorizationContext AS QUAD , BYVAL impersonationToken AS QUAD , BYVAL userIsAdministrator AS LONG , BYVAL errorCode AS QUAD , OPTIONAL BYREF extendedErrorInformation AS WSTRINGZ ) AS QUAD
DECLARE FUNCTION WSManPluginAuthzOperationComplete LIB "wsmsvc.dll" ALIAS "WSManPluginAuthzOperationComplete" ( BYREF senderDetails AS WSMAN_SENDER_DETAILS
 , BYVAL flags AS DWORD
 , BYVAL userAuthorizationContext AS DWORD
 , BYVAL errorCode AS DWORD
 , OPTIONAL BYREF extendedErrorInformation AS WSTRINGZ
 ) AS DWORD
DECLARE FUNCTION WSManPluginAuthzQueryQuotaComplete LIB "wsmsvc.dll" ALIAS "WSManPluginAuthzQueryQuotaComplete" ( BYREF senderDetails AS WSMAN_SENDER_DETAILS
 , BYVAL flags AS DWORD
 , BYREF quota AS WSMAN_AUTHZ_QUOTA
 , BYVAL errorCode AS DWORD
 , OPTIONAL BYREF extendedErrorInformation AS WSTRINGZ
 ) AS DWORD
#ENDIF
