namespace Vanara.PInvoke; /// Items from the WsmSvc.dll public static partial class WsmSvc { /// Code page option name to be used with WSManCreateShell API to remotely set the code page public const string WSMAN_CMDSHELL_OPTION_CODEPAGE = "WINRS_CODEPAGE"; /// /// Option name used with WSManRunShellCommand API to indicate that the client side mode of standard input is Console; default implies Pipe. /// public const string 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 public const string WSMAN_CMDSHELL_OPTION_SKIP_CMD_SHELL = "WINRS_SKIP_CMD_SHELL"; /// pre-defined command states public const string WSMAN_COMMAND_STATE_DONE = "/CommandState/Done"; /// pre-defined command states public const string WSMAN_COMMAND_STATE_PENDING = "/CommandState/Pending"; /// pre-defined command states public const string WSMAN_COMMAND_STATE_RUNNING = "/CommandState/Running"; /// Option name used with WSManCreateShell API to not load the user profile on the remote server public const string WSMAN_SHELL_OPTION_NOPROFILE = "WINRS_NOPROFILE"; /// public const string WSMAN_STREAM_ID_STDERR = "stderr"; /// public const string WSMAN_STREAM_ID_STDIN = "stdin"; /// public const string WSMAN_STREAM_ID_STDOUT = "stdout"; private const string Lib_WsmSvc = "wsmsvc.dll"; /// /// Authorizes a specific operation. /// The DLL entry point name for this method must be WSManPluginAuthzOperation. /// /// /// Specifies the context that was returned by a call to WSManPluginStartup. This parameter represents a specific application /// initialization of a WinRM plug-in. /// /// /// A pointer to the WSMAN_SENDER_DETAILS structure that specifies the identification information of the user. /// /// Reserved for future use. Must be set to zero. /// /// Represents the operation that is being performed. This parameter can be one of the following values: /// Get /// WSManOperationGet /// Put /// WSManOperationPut /// Create /// WSManOperationCreate /// Delete /// WSManOperationDelete /// Enumerate /// WSManOperationEnumerate /// Subscribe /// WSManOperationSubscribe /// Shell /// WSManOperationShell /// Command /// WSManOperationCommand /// Invoke /// WSManOperationInvoke /// /// /// Specifies the action of the request received. This parameter can be one of the following values: /// Get
http://schemas.xmlsoap.org/ws/2004/09/transfer/Get
/// Put
http://schemas.xmlsoap.org/ws/2004/09/transfer/Put
/// Create
http://schemas.xmlsoap.org/ws/2004/09/transfer/Create
/// Note Shell creation will appear as Create.

Delete
http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete
/// Enumerate
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate
/// Subscribe
http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe
/// Command
http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command
/// Invoke
This operation will have a custom string.
/// /// Specifies the resource URI of the inbound operation. /// None /// /// The plug-in must call WSManPluginAuthzOperationComplete to report either that the user was successfully authorized to perform the /// operation with NO_ERROR or that the user was not authorized with ERROR_ACCESS_DENIED. All other errors report a failure /// to the client, but no specific information is reported. /// // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_authorize_operation WSMAN_PLUGIN_AUTHORIZE_OPERATION // WsmanPluginAuthorizeOperation; void WsmanPluginAuthorizeOperation( [in] PVOID pluginContext, [in] WSMAN_SENDER_DETAILS *senderDetails, // [in] DWORD flags, [in] DWORD operation, [in] PCWSTR action, [in] PCWSTR resourceUri ) {...} [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_AUTHORIZE_OPERATION")] [UnmanagedFunctionPointer(CallingConvention.Winapi, SetLastError = false)] public delegate void WSMAN_PLUGIN_AUTHORIZE_OPERATION([In] IntPtr pluginContext, in WSMAN_SENDER_DETAILS senderDetails, [Optional] uint flags, uint operation, [MarshalAs(UnmanagedType.LPWStr)] string action, [MarshalAs(UnmanagedType.LPWStr)] string resourceUri); /// /// /// Retrieves quota information for the user after a connection has been authorized. This method will be called only if the configuration /// specifies that quotas are enabled within the authorization plug-in. /// /// The DLL entry point name for this method must be WSManPluginAuthzQueryQuota. /// /// /// Specifies the context that was returned by a call to WSManPluginStartup. This parameter represents a specific application /// initialization of a WinRM plug-in. /// /// /// A pointer to the WSMAN_SENDER_DETAILS structure that specifies the identification information of the user. /// /// Reserved for future use. Must be zero. /// None /// /// /// The quota is queried on the first call by a particular user and will not be requeried until after the user record times out due to an /// idle time-out of activity or until a system-wide configuration period is exceeded. /// /// /// The plug-in must call the WSManPluginAuthzQueryQuotaComplete function to terminate the operation whether or not the plug-in can carry /// out the request. If successful, the plug-in should give a set of quota information that is relevant for this particular user. If the /// plug-in fails to process the request for any reason, an appropriate error should be recorded through the callback method and the /// error will get propagated back to the client as a Simple Object Access Protocol (SOAP) fault if possible; otherwise, the error will /// be an empty HTTP 500 status error. /// /// // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_authorize_query_quota // WSMAN_PLUGIN_AUTHORIZE_QUERY_QUOTA WsmanPluginAuthorizeQueryQuota; void WsmanPluginAuthorizeQueryQuota( [in] PVOID pluginContext, [in] // WSMAN_SENDER_DETAILS *senderDetails, [in] DWORD flags ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_AUTHORIZE_QUERY_QUOTA")] public delegate void WSMAN_PLUGIN_AUTHORIZE_QUERY_QUOTA(IntPtr pluginContext, in WSMAN_SENDER_DETAILS senderDetails, uint flags); /// /// /// Releases the context that a plug-in reports from either WSManPluginAuthzUserComplete or WSManPluginAuthzOperationComplete. For a /// particular user, the context reported for both calls is allowed to be the same, as long as the plug-in infrastructure handles the /// scenario appropriately. This method is synchronous, and there are no callbacks that are called as a result. /// /// This method will be called under the following scenarios: /// /// /// /// After the operation is complete, the WSManPluginAuthzOperationComplete context is released. For some operations, such as get, the /// context will be released after the response is sent for the get operation. For more complex operations, such as enumeration, the /// context will not be released until the enumeration has completed. /// /// /// /// /// When the user record times out due to inactivity, the WSManPluginAuthzUser method will be called again the next time a request comes /// in for that user. /// /// /// /// /// If re-authorization needs to occur, the old context will be released after the new one is acquired. The old context will always be /// released regardless of whether the authorization succeeds. /// /// /// /// The DLL entry point name for this method must be WSManPluginAuthzReleaseContext. /// /// /// Specifies the context that was returned by either WSManPluginAuthzUserComplete or WSManPluginAuthzOperationComplete. If these methods /// return no context, this method will not be called. /// /// None // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_authorize_release_context // WSMAN_PLUGIN_AUTHORIZE_RELEASE_CONTEXT WsmanPluginAuthorizeReleaseContext; void WsmanPluginAuthorizeReleaseContext( [in] PVOID // userAuthorizationContext ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_AUTHORIZE_RELEASE_CONTEXT")] public delegate void WSMAN_PLUGIN_AUTHORIZE_RELEASE_CONTEXT(IntPtr userAuthorizationContext); /// /// /// Authorizes a connection. The plug-in should verify that this user is allowed to perform any operations. If the user is allowed to /// perform operations, the plug-in must report a success. If the user is not allowed to carry out any type of operation, a failure must /// be returned. /// /// /// Every new connection does not need to be authorized. After a user has been authorized to connect, a user record is created to track /// the activities of the user. While that record exists, all new connections will automatically be authorized. The user record will /// time-out after a configurable amount of time after no activity is detected. /// /// The DLL entry point name for this method must be WSManPluginAuthzUser. /// /// /// Specifies the context that was returned by a call to WSManPluginStartup. This parameter represents a specific application /// initialization of a WinRM plug-in. /// /// /// A pointer to the WSMAN_SENDER_DETAILS structure that specifies the identification information of the user to be authorized. /// /// Reserved for future use. Must be set to zero. /// None /// /// The plug-in must call WSManPluginAuthzUserComplete to report either that the user was successfully authorized with NO_ERROR or /// that the user was not authorized with ERROR_ACCESS_DENIED. An ERROR_WSMAN_REDIRECT_REQUIRED error should be reported if /// an HTTP redirect is required for this user, and the new HTTP URI should be recorded in extendedErrorInformation of the /// WSManPluginAuthzUserComplete method. All other errors report a failure to the client, but no specific information is reported. /// // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_authorize_user WSMAN_PLUGIN_AUTHORIZE_USER // WsmanPluginAuthorizeUser; void WsmanPluginAuthorizeUser( [in] PVOID pluginContext, [in] WSMAN_SENDER_DETAILS *senderDetails, [in] // DWORD flags ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_AUTHORIZE_USER")] public delegate void WSMAN_PLUGIN_AUTHORIZE_USER(IntPtr pluginContext, in WSMAN_SENDER_DETAILS senderDetails, uint flags = 0); /// /// /// Defines the command callback for a plug-in. This function is called when a request for a command is received. All Windows Remote /// Management plug-ins that support shell operations and need to create commands must implement this callback. /// /// The DLL entry point name must be WSManPluginCommand. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for the request. /// /// Reserved for future use. Must be set to zero. /// Specifies the context returned from creating the shell for which this command needs to be associated. /// Specifies the command line to be run. /// /// A pointer to a WSMAN_COMMAND_ARG_SET structure that specifies the command-line arguments to be passed to the command. /// /// None /// /// The WinRM (WinRM) plug-in will call the WSManPluginReportContext method to register a command context for the command. All operations /// on this command are passed into this context. The context must be valid until the WSManPluginOperationComplete method is called by /// the plug-in to indicate that either the command is complete or the shell was shut down. All parameters passed in are valid until the /// WinRM plug-in calls WSManPluginOperationComplete. /// // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_command WSMAN_PLUGIN_COMMAND WsmanPluginCommand; void // WsmanPluginCommand( WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, PVOID shellContext, PCWSTR commandLine, WSMAN_COMMAND_ARG_SET // *arguments ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_COMMAND")] public delegate void WSMAN_PLUGIN_COMMAND(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, IntPtr shellContext, [MarshalAs(UnmanagedType.LPWStr)] string commandLine, IntPtr arguments); /// /// Defines the connect callback for a plug-in. /// The DLL entry point name must be WSManPluginConnect. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for the request. /// /// Reserved for future use. Must be set to zero. /// /// Specifies the context returned from creating the shell for which this connection request needs to be associated. /// /// /// If this request is aimed at a command and not a shell, this is the context returned from the winrm create operation; /// otherwise, this parameter is NULL. /// /// /// A pointer to a WSMAN_DATA structure that specifies an optional inbound object that contains extra data for the connection. /// /// None // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_connect WSMAN_PLUGIN_CONNECT WsmanPluginConnect; void // WsmanPluginConnect( [in] WSMAN_PLUGIN_REQUEST *requestDetails, [in] DWORD flags, [in] PVOID shellContext, [in, optional] PVOID // commandContext, [in, optional] WSMAN_DATA *inboundConnectInformation ) {...} [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_CONNECT")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void WSMAN_PLUGIN_CONNECT(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, IntPtr shellContext, [Optional] IntPtr commandContext, [Optional] IntPtr inboundConnectInformation); /// /// Defines the receive callback for a plug-in. This function is called when an inbound request to receive data is received. /// The DLL entry point name must be WSManPluginReceive. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for the request. /// /// Reserved for future use. Must be zero. /// Specifies the context that was received when the shell was created. /// /// If this request is aimed at a command and not a shell, this is the context returned from the winrm create operation; /// otherwise, this parameter is NULL. /// /// /// A WSMAN_STREAM_ID_SET structure that contains a list of streams for which data is to be received. If this list is empty, all streams /// that were configured in the shell are implied, which means that all streams are available. /// /// None /// /// Based on the client request, the WSMAN_PLUGIN_RECEIVE callback function can be called against the shell and/or the command. /// The plug-in calls the WSManPluginReceiveResult method for each piece of data that needs to be sent back to the client. After all of /// the data has been sent, the plug-in calls WSManPluginOperationComplete to end the stream. All parameters passed in are valid until /// the Windows Remote Management (WinRM) plug-in calls WSManPluginOperationComplete. /// // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_receive WSMAN_PLUGIN_RECEIVE WsmanPluginReceive; void // WsmanPluginReceive( WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, PVOID shellContext, PVOID commandContext, WSMAN_STREAM_ID_SET // *streamSet ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_RECEIVE")] public delegate void WSMAN_PLUGIN_RECEIVE(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, IntPtr shellContext, [Optional] IntPtr commandContext, IntPtr streamSet); /// /// Defines the release command callback for the plug-in. This function is called to delete the plug-in command context. /// The DLL entry point name must be WSManPluginReleaseCommandContext. /// /// Specifies the context that was received when the shell was created. /// /// If this request is aimed at a command and not a shell, this is the context returned from the winrm create operation; /// otherwise, this parameter is NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_release_command_context // WSMAN_PLUGIN_RELEASE_COMMAND_CONTEXT WsmanPluginReleaseCommandContext; void WsmanPluginReleaseCommandContext( PVOID shellContext, // PVOID commandContext ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_RELEASE_COMMAND_CONTEXT")] public delegate void WSMAN_PLUGIN_RELEASE_COMMAND_CONTEXT(IntPtr shellContext, [Optional] IntPtr commandContext); /// /// Defines the release shell callback for the plug-in. This function is called to delete the plug-in shell context. /// The DLL entry point name must be WSManPluginReleaseCommandContext. /// /// Specifies the context that was received when the shell was created. /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_release_shell_context // WSMAN_PLUGIN_RELEASE_SHELL_CONTEXT WsmanPluginReleaseShellContext; void WsmanPluginReleaseShellContext( PVOID shellContext ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_RELEASE_SHELL_CONTEXT")] public delegate void WSMAN_PLUGIN_RELEASE_SHELL_CONTEXT(IntPtr shellContext); /// /// /// Defines the send callback for a plug-in. This function is called for each object that is received from a client. Each object received /// causes the callback to be called once. After the data is processed, the Windows Remote Management (WinRM) plug-in calls /// WSManPluginOperationComplete to acknowledge receipt and to allow the next object to be delivered. /// /// The DLL entry point name must be WSManPluginSend. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for the request. /// /// /// If this is the last object for the stream, this parameter is set to WSMAN_FLAG_NO_MORE_DATA. Otherwise, it is set to zero. /// /// Specifies the context that was received when the shell was created. /// /// If this request is aimed at a command and not a shell, this is the context returned from the winrm create operation; /// otherwise, this parameter is NULL. /// /// Specifies the stream that is associated with the inbound object. /// /// A pointer to a WSMAN_DATA structure that contains data being sent to the specified stream. It is in the form of binary data. /// /// None // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_send WSMAN_PLUGIN_SEND WsmanPluginSend; void // WsmanPluginSend( WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, PVOID shellContext, PVOID commandContext, PCWSTR stream, // WSMAN_DATA *inboundData ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_SEND")] public delegate void WSMAN_PLUGIN_SEND(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, IntPtr shellContext, [Optional] IntPtr commandContext, [MarshalAs(UnmanagedType.LPWStr)] string stream, in WSMAN_DATA inboundData); /// /// /// Defines the shell callback for a plug-in. This function is called when a request for a new shell is received. All Windows Remote /// Management plug-ins that support shell operations need to implement this callback. /// /// The DLL entry point name must be WSManPluginShell. /// /// /// Specifies the context that was returned by a call to the WSManPluginStartup method. This parameter represents a specific application /// initialization of a WinRM plug-in. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for the request. /// /// Reserved for future use. Must be set to zero. /// A pointer to a WSMAN_SHELL_STARTUP_INFO structure that contains startup information for the shell. /// /// A pointer to a WSMAN_DATA structure that specifies an optional inbound object that contains extra data for the shell. /// /// None /// /// The WinRM (WinRM) plug-in calls WSManPluginReportContext to register a shell context for the shell. All operations on this shell pass /// into this context. If the shell has shut down or the plug-in checks the requestDetails parameter and reports that the /// operation was canceled, the plug-in should call WSManPluginOperationComplete. All parameters passed in are valid until the WinRM /// plug-in calls WSManPluginOperationComplete. /// // https://learn.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_shell WSMAN_PLUGIN_SHELL WsmanPluginShell; void // WsmanPluginShell( PVOID pluginContext, WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, WSMAN_SHELL_STARTUP_INFO *startupInfo, // WSMAN_DATA *inboundShellInformation ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_SHELL")] public delegate void WSMAN_PLUGIN_SHELL(IntPtr pluginContext, in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, IntPtr startupInfo, [Optional] IntPtr inboundShellInformation); /// /// /// Defines the shutdown callback for the plug-in. This function is called after all operations have been canceled and before the Windows /// Remote Management plug-in DLL is unloaded. All WinRM plug-ins must implement this callback function. /// /// The DLL entry point name must be WSManPluginShutdown. /// /// /// Specifies the context that was returned by a call to the WSManPluginStartup method. This parameter represents a specific application /// initialization of a WinRM plug-in. The shutdown entry point will be called for each application that initialized it. /// /// Reserved for future use. Must be set to zero. /// /// Specifies the reason that the plug-in is shutting down. /// WSMAN_PLUGIN_SHUTDOWN_SYSTEM /// The system shut down. /// WSMAN_PLUGIN_SHUTDOWN_SERVICE /// The WinRM service shut down. /// WSMAN_PLUGIN_SHUTDOWN_IISHOST /// The IIS host shut down. /// /// /// The method returns NO_ERROR if it succeeded; otherwise, it returns an error code. /// Note If this method fails, the plug-in will not call back in. /// /// /// /// Each successful call to WSManPluginStartup will result in a call to this function before the WinRM plug-in DLL is unloaded. It is /// important to ensure that the WinRM plug-in tracks the number of times that this startup entry point is called so that the plug-in is /// not shut down prematurely. /// /// /// This function must ensure that all plug-in threads are shut down before it returns. If the plug-in handles only synchronous /// operations and all threads report a cancellation result before they return, this function performs only plug-in cleanup. However, for /// an asynchronous plug-in, any threads that are used to process the plug-in threads, including the ones that just reported the /// cancellation for all operations, need to be completely shut down. If all of the threads are not shut down, crashes in the DLL might /// occur because code might be executed after the DLL is unloaded. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_shutdown WSMAN_PLUGIN_SHUTDOWN WsmanPluginShutdown; // DWORD WsmanPluginShutdown( PVOID pluginContext, DWORD flags, DWORD reason ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_SHUTDOWN")] public delegate uint WSMAN_PLUGIN_SHUTDOWN(IntPtr pluginContext, uint flags, WSMAN_SHUTDOWN reason); /// /// Defines the signal callback for a plug-in. This function is called when an inbound signal is received from a client call. /// The DLL entry point name for this method must be WSManPluginSignal. /// /// /// Reserved for future use. Must be zero. /// Specifies the context that was received when the shell was created. /// /// If this request is aimed at a command and not a shell, this is the context returned from the winrm create operation; /// otherwise, this parameter is NULL. /// /// /// Specifies the signal that is received from the client. The following codes are common. /// WSMAN_SIGNAL_SHELL_CODE_TERMINATE /// The shell or Command Prompt window was closed. The plug-in should call the WSManPluginOperationComplete function. /// WSMAN_SIGNAL_SHELL_CODE_CTRL_C /// The signal for CTRL+C was received, and the process was halted. The plug-in should call the WSManPluginOperationComplete function. /// WSMAN_SIGNAL_SHELL_CODE_CTRL_BREAK /// /// The signal for CTRL+BREAK was received, and the process was halted. The plug-in should call the WSManPluginOperationComplete function. /// /// /// None /// /// A signal can be received for processing a CTRL+C sequence or one of many other types of custom signals. The callback is called once /// for each signal that is received. The plug-in determines which signals cause commands and/or shells to be shut down. Because signals /// are shell-specific, the plug-in must initiate the shutdown by calling the WSManPluginOperationComplete method. For each call, the /// plug-in should call WSManPluginOperationComplete to acknowledge receipt and to allow the next signal to be received. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_signal WSMAN_PLUGIN_SIGNAL WsmanPluginSignal; void // WsmanPluginSignal( WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, PVOID shellContext, PVOID commandContext, PCWSTR code ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_SIGNAL")] public delegate void WSMAN_PLUGIN_SIGNAL(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, IntPtr shellContext, [Optional] IntPtr commandContext, [MarshalAs(UnmanagedType.LPWStr)] string code); /// /// /// Defines the startup callback for the plug-in. Because multiple applications can be hosted in the same process, this method can be /// called multiple times, but only once for each application initialization. A plug-in can be initialized more than once within the same /// process but only once for each applicationIdentification value. The context that is returned from this method should be application /// specific. The returned context will be passed into all future plug-in calls that are specific to the application. All Windows Remote /// Management (WinRM) plug-ins must implement this callback function. /// /// The DLL entry point name for this method must be WSManPluginStartup. /// /// Reserved for future use. Must be zero. /// /// A unique identifier for the hosted application. For the main WinRM service, the default is wsman. For an Internet Information /// Services (IIS) host, this identifier is related to the application endpoint for that host. For example, wsman/MyCompany/MyApplication. /// /// /// A string that contains configuration information, if any information was stored when the plug-in was registered. When the plug-in is /// registered using the WinRM configuration, the plug-in can add extra configuration parameters that are useful during initialization to /// an optional node. This information can be especially useful if a plug-in is used in different IIS hosting scenarios and requires /// slightly different run-time semantics during initialization. This string is a copy of the XML from the configuration, if one is /// present. Otherwise, this parameter is set to NULL. /// /// /// /// The method returns NO_ERROR if it succeeded; otherwise, it returns an error code. If this method returns an error, the /// WSManPluginShutdown entry point will not be called. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_plugin_startup WSMAN_PLUGIN_STARTUP WsmanPluginStartup; DWORD // WsmanPluginStartup( DWORD flags, PCWSTR applicationIdentification, PCWSTR extraInfo, PVOID *pluginContext ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_STARTUP")] public delegate uint WSMAN_PLUGIN_STARTUP([Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string applicationIdentification, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? extraInfo, out IntPtr pluginContext); /// The callback function that is called for shell operations, which result in a remote request. /// /// Represents user-defined context passed to the WinRM (WinRM) Client Shell application programming interface (API) . /// /// Specifies one or more flags from the WSManCallbackFlags enumeration. /// /// /// Specifies the shell handle associated with the user context. The shell handle must be closed by calling the WSManCloseShell method. /// /// /// Specifies the command handle associated with the user context. The command handle must be closed by calling the WSManCloseCommand API method. /// /// /// Defines the operation handle associated with the user context. The operation handle is valid only for callbacks that are associated /// with WSManReceiveShellOutput, WSManSendShellInput, and WSManSignalShell calls. This handle must be closed by calling the /// WSManCloseOperation method. /// /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nc-wsman-wsman_shell_completion_function WSMAN_SHELL_COMPLETION_FUNCTION // WsmanShellCompletionFunction; void WsmanShellCompletionFunction( PVOID operationContext, DWORD flags, WSMAN_ERROR *error, // WSMAN_SHELL_HANDLE shell, WSMAN_COMMAND_HANDLE command, WSMAN_OPERATION_HANDLE operationHandle, WSMAN_RESPONSE_DATA *data ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_SHELL_COMPLETION_FUNCTION")] public delegate void WSMAN_SHELL_COMPLETION_FUNCTION(IntPtr operationContext, WSManCallbackFlags flags, in WSMAN_ERROR error, [In, Optional] WSMAN_SHELL_HANDLE shell, [In, Optional] WSMAN_COMMAND_HANDLE command, [In, Optional] WSMAN_OPERATION_HANDLE operationHandle, [In, Optional] IntPtr data); /// Flags for . [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManInitialize")] public enum WSMAN_FLAG_REQUESTED_API_VERSION { /// WSMAN_FLAG_REQUESTED_API_VERSION_1_0 = 0x0, /// For clients that will use the disconnect-reconnect functionality. WSMAN_FLAG_REQUESTED_API_VERSION_1_1 = 0x1 } /// [Flags] public enum WSMAN_FLAG_SERVER_BUFFERING_MODE : uint { /// /// 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. /// WSMAN_FLAG_NO_COMPRESSION = 0x1, /// WSMAN_FLAG_DELETE_SERVER_SESSION = 0x2, /// Enable the service to drop operation output when running disconnected. WSMAN_FLAG_SERVER_BUFFERING_MODE_DROP = 0x4, /// Enable the service to block operation progress when output buffers are full. WSMAN_FLAG_SERVER_BUFFERING_MODE_BLOCK = 0x8, /// Enable receive call to not immediately retrieve results. Only applicable for Receive calls on commands WSMAN_FLAG_RECEIVE_DELAY_OUTPUT_STREAM = 0X10 } /// Specifies the options that are available for retrieval. [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginGetOperationParameters")] public enum WSMAN_PLUGIN_PARAMS_OP { /// /// /// Specifies the maximum size of the operation response packet. The size includes the size of the data along with the Simple /// Object Access Protocol (SOAP) overhead. /// /// /// Note Some operations have a single call into the plug-in that can cause multiple roundtrips to occur. If no requests /// are waiting for data when this method is called, the maximum envelope size for the previous packet is given. /// /// WSMAN_PLUGIN_PARAMS_MAX_ENVELOPE_SIZE = 1, /// /// Specifies the time-out of the current operation. /// /// Note Some operations have a single call into the plug-in that can cause multiple roundtrips to occur. If no requests /// are waiting for data when this method is called, the time-out for the previous packet is given. /// /// WSMAN_PLUGIN_PARAMS_TIMEOUT = 2, /// /// /// Specifies how much space is left for data for the current operation. The size is based on the type of operation. For /// example, this flag would represent how large the single result item can be for a get operation. For enumerations, the size /// will decrease after each object is added. After the current packet has been filled with enumerations and get operations, it /// will be returned to the client even though more data is being accepted and cached. /// /// /// Note Some operations have a single call into the plug-in that can cause multiple roundtrips to occur. If no requests /// are waiting for data when this method is called, the remaining size is given for a cached item. /// /// WSMAN_PLUGIN_PARAMS_REMAINING_RESULT_SIZE = 3, /// Specifies the maximum size of the data for the current operation. WSMAN_PLUGIN_PARAMS_LARGEST_RESULT_SIZE = 4, /// Specifies the language locale that was requested by the client for the operation. WSMAN_PLUGIN_PARAMS_GET_REQUESTED_LOCALE = 5, /* Returns WSMAN_DATA_TEXT */ /// Specifies the language locale of the data that was requested by the client. WSMAN_PLUGIN_PARAMS_GET_REQUESTED_DATA_LOCALE = 6, /* Returns WSMAN_DATA_TEXT */ } /// Specifies the reason that the plug-in is shutting down. [PInvokeData("wsman.h", MSDNShortId = "NC:wsman.WSMAN_PLUGIN_SHUTDOWN")] public enum WSMAN_SHUTDOWN { /// The system shut down. WSMAN_PLUGIN_SHUTDOWN_SYSTEM = 1, /// The WinRM service shut down. WSMAN_PLUGIN_SHUTDOWN_SERVICE = 2, /// The IIS host shut down. WSMAN_PLUGIN_SHUTDOWN_IISHOST = 3, /// WSMAN_PLUGIN_SHUTDOWN_IDLETIMEOUT_ELAPSED = 4, } /// Determines the authentication method for the operation. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ne-wsman-wsmanauthenticationflags typedef enum WSManAuthenticationFlags // { WSMAN_FLAG_DEFAULT_AUTHENTICATION, WSMAN_FLAG_NO_AUTHENTICATION, WSMAN_FLAG_AUTH_DIGEST, WSMAN_FLAG_AUTH_NEGOTIATE, // WSMAN_FLAG_AUTH_BASIC, WSMAN_FLAG_AUTH_KERBEROS, WSMAN_FLAG_AUTH_CREDSSP, WSMAN_FLAG_AUTH_CLIENT_CERTIFICATE } ; [PInvokeData("wsman.h", MSDNShortId = "NE:wsman.WSManAuthenticationFlags")] [Flags] public enum WSManAuthenticationFlags { /// Use the default authentication. WSMAN_FLAG_DEFAULT_AUTHENTICATION = 0x0, /// Use no authentication for a remote operation. WSMAN_FLAG_NO_AUTHENTICATION = 0x1, /// /// Use Digest authentication. Only the client computer can initiate a Digest authentication request. The client sends a request /// to the server to authenticate and receives from the server a token string. The client then sends the resource request, /// including the user name and a cryptographic hash of the password combined with the token string. Digest authentication is /// supported for HTTP and HTTPS. WinRM Shell client scripts and applications can specify Digest authentication, but the service cannot. /// WSMAN_FLAG_AUTH_DIGEST = 0x2, /// /// Use Negotiate authentication. The client sends a request to the server to authenticate. The server determines whether to use /// Kerberos or NTLM. In general, Kerberos is selected to authenticate a domain account and NTLM is selected for local computer /// accounts. But there are also some special cases in which Kerberos/NTLM are selected. The user name should be specified in /// the form DOMAIN\username for a domain user or SERVERNAME\username for a local user on a server computer. /// WSMAN_FLAG_AUTH_NEGOTIATE = 0x4, /// /// Use Basic authentication. The client presents credentials in the form of a user name and password that are directly /// transmitted in the request message. You can specify the credentials only of a local administrator account on the remote computer. /// WSMAN_FLAG_AUTH_BASIC = 0x8, /// Use Kerberos authentication. The client and server mutually authenticate by using Kerberos certificates. WSMAN_FLAG_AUTH_KERBEROS = 0x10, /// /// Use CredSSP authentication for a remote operation. If a certificate from the local machine is used to authenticate the /// server, the Network service must be allowed access to the private key of the certificate. /// WSMAN_FLAG_AUTH_CREDSSP = 0x80, /// /// Use client certificate authentication. The certificate thumbprint is passed as part of the WSMAN_AUTHENTICATION_CREDENTIALS /// structure. The WinRM client will try to find the certificate in the computer store and then, if it is not found, in the /// current user store. If no matching certificate is found, an error will be reported to the user. /// WSMAN_FLAG_AUTH_CLIENT_CERTIFICATE = 0x20, } /// Defines a set of flags used by all callback functions. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ne-wsman-wsmancallbackflags typedef enum WSManCallbackFlags { // WSMAN_FLAG_CALLBACK_END_OF_OPERATION, WSMAN_FLAG_CALLBACK_END_OF_STREAM, WSMAN_FLAG_CALLBACK_SHELL_SUPPORTS_DISCONNECT, // WSMAN_FLAG_CALLBACK_SHELL_AUTODISCONNECTED, WSMAN_FLAG_CALLBACK_NETWORK_FAILURE_DETECTED, // WSMAN_FLAG_CALLBACK_RETRYING_AFTER_NETWORK_FAILURE, WSMAN_FLAG_CALLBACK_RECONNECTED_AFTER_NETWORK_FAILURE, // WSMAN_FLAG_CALLBACK_SHELL_AUTODISCONNECTING, WSMAN_FLAG_CALLBACK_RETRY_ABORTED_DUE_TO_INTERNAL_ERROR, // WSMAN_FLAG_CALLBACK_RECEIVE_DELAY_STREAM_REQUEST_PROCESSED } ; [PInvokeData("wsman.h", MSDNShortId = "NE:wsman.WSManCallbackFlags")] [Flags] public enum WSManCallbackFlags { /// /// Indicates the end of a single step of a multi-step operation. This flag is used for optimization purposes if the shell /// cannot be determined. /// WSMAN_FLAG_CALLBACK_END_OF_OPERATION = 0x1, /// /// Indicates the end of a particular stream. This flag is used for optimization purposes if an indication has been provided to /// the shell that no more output will occur for this stream. /// WSMAN_FLAG_CALLBACK_END_OF_STREAM = 0x8, /// Flag that if present on CreateShell callback indicates that it supports disconnect WSMAN_FLAG_CALLBACK_SHELL_SUPPORTS_DISCONNECT = 0x20, /// Flag that indicates that the shell got disconnected due to netowrk failure WSMAN_FLAG_CALLBACK_SHELL_AUTODISCONNECTED = 0x40, /// Flag indicates that the client shell detected a network failure WSMAN_FLAG_CALLBACK_NETWORK_FAILURE_DETECTED = 0x100, /// Flag indicates that client shell is retrying to establish network connection with the server WSMAN_FLAG_CALLBACK_RETRYING_AFTER_NETWORK_FAILURE = 0x200, /// /// Flag indicates that client shell successfully reconnected with the server after attempting to reconnect to the server /// WSMAN_FLAG_CALLBACK_RECONNECTED_AFTER_NETWORK_FAILURE = 0x400, /// Flag indicates that the client shell attempts to reconnect to the server failed and hence it is AutoDisconnecting WSMAN_FLAG_CALLBACK_SHELL_AUTODISCONNECTING = 0x800, /// /// Flag indicates that the client shell got into broken state in the middle of retry notification sequence due to some internal /// error at wsman layer /// WSMAN_FLAG_CALLBACK_RETRY_ABORTED_DUE_TO_INTERNAL_ERROR = 0x1000, /// Flag that indicates for a receive operation that a delay stream request has been processed WSMAN_FLAG_CALLBACK_RECEIVE_DELAY_STREAM_REQUEST_PROCESSED = 0x2000, } /// Specifies the current data type of the union in the WSMAN_DATA structure. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ne-wsman-wsmandatatype typedef enum WSManDataType { WSMAN_DATA_NONE, // WSMAN_DATA_TYPE_TEXT, WSMAN_DATA_TYPE_BINARY, WSMAN_DATA_TYPE_DWORD } ; [PInvokeData("wsman.h", MSDNShortId = "NE:wsman.WSManDataType")] public enum WSManDataType { /// The structure is not valid yet. WSMAN_DATA_NONE = 0, /// The structure contains text. WSMAN_DATA_TYPE_TEXT = 1, /// The structure contains binary data. WSMAN_DATA_TYPE_BINARY = 2, /// The structure contains a DWORD integer. WSMAN_DATA_TYPE_DWORD = 4, } /// Defines the proxy access type. /// /// /// The WSMAN_OPTION_PROXY_IE_PROXY_CONFIG option returns the current user Internet Explorer proxy settings for the current /// active network connection. This option requires the user profile to be loaded. This 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 that is different than the interactive user, the client application must explicitly load the user profile prior to using /// this option. /// /// /// If the Windows Remote Management API is called from a service, WSMAN_OPTION_PROXY_WINHTTP_PROXY_CONFIG or /// WSMAN_OPTION_PROXY_AUTO_DETECT should be used if a proxy is required. /// /// /// The WSMAN_OPTION_PROXY_WINHTTP_PROXY_CONFIG option translates into the WINHTTP_ACCESS_TYPE_DEFAULT_PROXY option in /// WinHTTP. WinHTTP retrieves the static proxy or direct configuration from the registry. WINHTTP_ACCESS_TYPE_DEFAULT_PROXY /// does not inherit browser proxy settings. WinHTTP does not share any proxy settings with Internet Explorer. This option gets the /// WinHTTP proxy configuration set by the ProxyCfg.exe utility. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ne-wsman-wsmanproxyaccesstype typedef enum WSManProxyAccessType { // WSMAN_OPTION_PROXY_IE_PROXY_CONFIG, WSMAN_OPTION_PROXY_WINHTTP_PROXY_CONFIG, WSMAN_OPTION_PROXY_AUTO_DETECT, // WSMAN_OPTION_PROXY_NO_PROXY_SERVER } ; [PInvokeData("wsman.h", MSDNShortId = "NE:wsman.WSManProxyAccessType")] [Flags] public enum WSManProxyAccessType { /// Use the Internet Explorer proxy configuration for the current user. This is the default setting. WSMAN_OPTION_PROXY_IE_PROXY_CONFIG = 1, /// Use the proxy settings configured for WinHTTP. WSMAN_OPTION_PROXY_WINHTTP_PROXY_CONFIG = 2, /// Force autodetection of a proxy. WSMAN_OPTION_PROXY_AUTO_DETECT = 4, /// Do not use a proxy server. All host names are resolved locally. WSMAN_OPTION_PROXY_NO_PROXY_SERVER = 8, } /// Defines a set of extended options for the session. These options are used with the WSManSetSessionOption method. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ne-wsman-wsmansessionoption typedef enum WSManSessionOption { // WSMAN_OPTION_DEFAULT_OPERATION_TIMEOUTMS, WSMAN_OPTION_MAX_RETRY_TIME, WSMAN_OPTION_TIMEOUTMS_CREATE_SHELL, // WSMAN_OPTION_TIMEOUTMS_RUN_SHELL_COMMAND, WSMAN_OPTION_TIMEOUTMS_RECEIVE_SHELL_OUTPUT, WSMAN_OPTION_TIMEOUTMS_SEND_SHELL_INPUT, // WSMAN_OPTION_TIMEOUTMS_SIGNAL_SHELL, WSMAN_OPTION_TIMEOUTMS_CLOSE_SHELL, WSMAN_OPTION_SKIP_CA_CHECK, WSMAN_OPTION_SKIP_CN_CHECK, // WSMAN_OPTION_UNENCRYPTED_MESSAGES, WSMAN_OPTION_UTF16, WSMAN_OPTION_ENABLE_SPN_SERVER_PORT, WSMAN_OPTION_MACHINE_ID, // WSMAN_OPTION_LOCALE, WSMAN_OPTION_UI_LANGUAGE, WSMAN_OPTION_MAX_ENVELOPE_SIZE_KB, // WSMAN_OPTION_SHELL_MAX_DATA_SIZE_PER_MESSAGE_KB, WSMAN_OPTION_REDIRECT_LOCATION, WSMAN_OPTION_SKIP_REVOCATION_CHECK, // WSMAN_OPTION_ALLOW_NEGOTIATE_IMPLICIT_CREDENTIALS, WSMAN_OPTION_USE_SSL, WSMAN_OPTION_USE_INTEARACTIVE_TOKEN } ; [PInvokeData("wsman.h", MSDNShortId = "NE:wsman.WSManSessionOption")] public enum WSManSessionOption { /// Default time-out in milliseconds that applies to all operations on the client side. [CorrespondingType(typeof(uint))] WSMAN_OPTION_DEFAULT_OPERATION_TIMEOUTMS = 1, /// [CorrespondingType(typeof(uint))] WSMAN_OPTION_MAX_RETRY_TIME = 11, /// Time-out in milliseconds for WSManCreateShell operations. [CorrespondingType(typeof(uint))] WSMAN_OPTION_TIMEOUTMS_CREATE_SHELL, /// Time-out in milliseconds for WSManRunShellCommand operations. [CorrespondingType(typeof(uint))] WSMAN_OPTION_TIMEOUTMS_RUN_SHELL_COMMAND, /// Time-out in milliseconds for WSManReceiveShellOutput operations. [CorrespondingType(typeof(uint))] WSMAN_OPTION_TIMEOUTMS_RECEIVE_SHELL_OUTPUT, /// Time-out in milliseconds for WSManSendShellInput operations. [CorrespondingType(typeof(uint))] WSMAN_OPTION_TIMEOUTMS_SEND_SHELL_INPUT, /// Time-out in milliseconds for WSManSignalShell and WSManCloseCommand operations. [CorrespondingType(typeof(uint))] WSMAN_OPTION_TIMEOUTMS_SIGNAL_SHELL, /// Time-out in milliseconds for WSManCloseShell operations connection options. [CorrespondingType(typeof(uint))] WSMAN_OPTION_TIMEOUTMS_CLOSE_SHELL, /// Set to 1 to not validate the CA on the server certificate. The default is 0. [CorrespondingType(typeof(uint))] WSMAN_OPTION_SKIP_CA_CHECK, /// Set to 1 to not validate the CN on the server certificate. The default is 0. [CorrespondingType(typeof(uint))] WSMAN_OPTION_SKIP_CN_CHECK, /// Set to 1 to not encrypt messages. The default is 0. [CorrespondingType(typeof(uint))] WSMAN_OPTION_UNENCRYPTED_MESSAGES, /// /// Set to 1 to send all network packets for remote operations in UTF16. Default of 0 causes network packets to be sent in UTF8. /// [CorrespondingType(typeof(uint))] WSMAN_OPTION_UTF16, /// Set to 1 when using Negotiate authentication and the port number is included in the connection. Default is 0. [CorrespondingType(typeof(uint))] WSMAN_OPTION_ENABLE_SPN_SERVER_PORT, /// Set to 1 to identify this machine to the server by including the MachineID. The default is 0. [CorrespondingType(typeof(uint))] WSMAN_OPTION_MACHINE_ID, /// /// The language locale options. For more information about the language locales, see the RFC 3066 specification from the /// Internet Engineering Task Force at http://www.ietf.org/rfc/rfc3066.txt. /// [CorrespondingType(typeof(string))] WSMAN_OPTION_LOCALE = 25, /// /// The UI language options. The UI language options are defined in RFC 3066 format. For more information about the UI language /// options, see the RFC 3066 specification from the Internet Engineering Task Force at http://www.ietf.org/rfc/rfc3066.txt. /// [CorrespondingType(typeof(string))] WSMAN_OPTION_UI_LANGUAGE, /// The maximum Simple Object Access Protocol (SOAP) envelope size. The default is 150 KB. [CorrespondingType(typeof(uint))] WSMAN_OPTION_MAX_ENVELOPE_SIZE_KB = 28, /// The maximum size of the data that is provided by the client. [CorrespondingType(typeof(uint))] WSMAN_OPTION_SHELL_MAX_DATA_SIZE_PER_MESSAGE_KB, /// The redirect location. [CorrespondingType(typeof(string))] WSMAN_OPTION_REDIRECT_LOCATION, /// Set to 1 to not validate the revocation status on the server certificate. The default is 0. [CorrespondingType(typeof(uint))] WSMAN_OPTION_SKIP_REVOCATION_CHECK, /// Set to 1 to allow default credentials for Negotiate. The default is 0. [CorrespondingType(typeof(uint))] WSMAN_OPTION_ALLOW_NEGOTIATE_IMPLICIT_CREDENTIALS, /// [CorrespondingType(typeof(uint))] WSMAN_OPTION_USE_SSL, /// [CorrespondingType(typeof(uint))] WSMAN_OPTION_USE_INTEARACTIVE_TOKEN, } /// Deletes a command and frees the resources that are associated with it. /// Specifies the command handle to be closed. This handle is returned by a WSManRunShellCommand call. /// Reserved for future use. Must be set to zero. /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanclosecommand void WSManCloseCommand( WSMAN_COMMAND_HANDLE // commandHandle, DWORD flags, WSMAN_SHELL_ASYNC *async ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCloseCommand")] public static extern void WSManCloseCommand(WSMAN_COMMAND_HANDLE commandHandle, [In, Optional] uint flags, in WSMAN_SHELL_ASYNC async); /// Cancels or closes an asynchronous operation. All resources that are associated with the operation are freed. /// Specifies the operation handle to be closed. /// Reserved for future use. Set to zero. /// This method returns zero on success. Otherwise, this method returns an error code. /// /// The method de-allocates local and remote resources associated with the operation. After the WSManCloseOperation method is /// called, the operationHandle parameter cannot be passed to any other call. If the callback associated with the operation is /// pending and has not completed before WSManCloseOperation is called, the operation is marked for deletion and the method /// returns immediately. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmancloseoperation DWORD WSManCloseOperation( // WSMAN_OPERATION_HANDLE operationHandle, DWORD flags ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCloseOperation")] public static extern Win32Error WSManCloseOperation(WSMAN_OPERATION_HANDLE operationHandle, uint flags = 0); /// Closes a session object. /// /// Specifies the session handle to close. This handle is returned by a WSManCreateSession call. This parameter cannot be NULL. /// /// Reserved for future use. Must be zero. /// This method returns zero on success. Otherwise, this method returns an error code. /// /// The WSManCloseSession method frees the memory associated with a session and closes all related operations before /// returning. This is a synchronous call. All operations are explicitly canceled. It is recommended that all pending operations are /// either completed or explicitly canceled before calling this function. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanclosesession DWORD WSManCloseSession( WSMAN_SESSION_HANDLE // session, DWORD flags ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCloseSession")] public static extern Win32Error WSManCloseSession(WSMAN_SESSION_HANDLE session, uint flags = 0); /// Deletes a shell object and frees the resources associated with the shell. /// /// Specifies the shell handle to close. This handle is returned by a WSManCreateShell call. This parameter cannot be NULL. /// /// Reserved for future use. Must be set to zero. /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmancloseshell void WSManCloseShell( WSMAN_SHELL_HANDLE // shellHandle, DWORD flags, WSMAN_SHELL_ASYNC *async ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCloseShell")] public static extern void WSManCloseShell(WSMAN_SHELL_HANDLE shellHandle, [Optional] uint flags, in WSMAN_SHELL_ASYNC async); /// Connects to an existing server session. /// Specifies the session handle returned by a WSManCreateSession function. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// Defines the shell type to which the connection will be made. The shell type is defined by a unique URI, therefore the shell /// object returned by the call is dependent on the URI that is specified by this parameter. The resourceUri parameter cannot be /// NULL and it is a null-terminated string. /// /// /// Specifies the shell identifier that is associated with the server shell session to which the client intends to connect. /// /// /// A pointer to a WSMAN_OPTION_SET structure that specifies a set of options for the shell. This parameter is optional. /// /// /// A pointer to a WSMAN_DATA structure that defines an open context for the connect shell operation. The content should be a valid /// XML string. This parameter can be NULL. /// /// /// Defines an asynchronous structure that contains an optional user context and a mandatory callback function. See the /// WSMAN_SHELL_ASYNC structure for more information. This parameter cannot be NULL. /// /// /// Specifies a shell handle that uniquely identifies the shell object that was returned by resourceURI. The resource handle tracks /// 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. /// /// None /// /// Connects to an existing server shell session identified by the ShellId parameter. This builds the necessary client side context, /// represented by the return parameter shell, that can be used to carry out subsequent operations such as running commands and /// sending and receiving output on the server shell session. This WSManConnectShell function does not automatically /// construct the client side contexts for any commands that are currently associated with the server shell session. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanconnectshell void WSManConnectShell( WSMAN_SESSION_HANDLE // session, DWORD flags, PCWSTR resourceUri, PCWSTR shellID, WSMAN_OPTION_SET *options, WSMAN_DATA *connectXml, WSMAN_SHELL_ASYNC // *async, WSMAN_SHELL_HANDLE *shell ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManConnectShell")] public static extern void WSManConnectShell(WSMAN_SESSION_HANDLE session, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, [MarshalAs(UnmanagedType.LPWStr)] string shellID, in WSMAN_OPTION_SET options, in WSMAN_DATA connectXml, in WSMAN_SHELL_ASYNC async, out SafeWSMAN_SHELL_HANDLE shell); /// Connects to an existing server session. /// Specifies the session handle returned by a WSManCreateSession function. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// Defines the shell type to which the connection will be made. The shell type is defined by a unique URI, therefore the shell /// object returned by the call is dependent on the URI that is specified by this parameter. The resourceUri parameter cannot be /// NULL and it is a null-terminated string. /// /// /// Specifies the shell identifier that is associated with the server shell session to which the client intends to connect. /// /// /// A pointer to a WSMAN_OPTION_SET structure that specifies a set of options for the shell. This parameter is optional. /// /// /// A pointer to a WSMAN_DATA structure that defines an open context for the connect shell operation. The content should be a valid /// XML string. This parameter can be NULL. /// /// /// Defines an asynchronous structure that contains an optional user context and a mandatory callback function. See the /// WSMAN_SHELL_ASYNC structure for more information. This parameter cannot be NULL. /// /// /// Specifies a shell handle that uniquely identifies the shell object that was returned by resourceURI. The resource handle tracks /// 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. /// /// None /// /// Connects to an existing server shell session identified by the ShellId parameter. This builds the necessary client side context, /// represented by the return parameter shell, that can be used to carry out subsequent operations such as running commands and /// sending and receiving output on the server shell session. This WSManConnectShell function does not automatically /// construct the client side contexts for any commands that are currently associated with the server shell session. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanconnectshell void WSManConnectShell( WSMAN_SESSION_HANDLE // session, DWORD flags, PCWSTR resourceUri, PCWSTR shellID, WSMAN_OPTION_SET *options, WSMAN_DATA *connectXml, WSMAN_SHELL_ASYNC // *async, WSMAN_SHELL_HANDLE *shell ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManConnectShell")] public static extern void WSManConnectShell(WSMAN_SESSION_HANDLE session, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, [MarshalAs(UnmanagedType.LPWStr)] string shellID, [In, Optional] IntPtr options, [In, Optional] IntPtr connectXml, in WSMAN_SHELL_ASYNC async, out SafeWSMAN_SHELL_HANDLE shell); /// Connects to an existing command running in a shell. /// Specifies the shell handle returned by the WSManCreateShell call. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// A null-terminated string that identifies a specific command, currently running in the server session, that the client intends to /// connect to. /// /// /// 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. /// /// /// A pointer to a WSMAN_DATA structure that defines an open context for the connect shell operation. The content must be a valid /// XML string. This parameter can be NULL. /// /// /// Defines an asynchronous structure to contain an optional user context and a mandatory callback function. For more information, /// see WSMAN_SHELL_ASYNC. This parameter cannot be NULL. /// /// /// This handle is returned on a successful call and is used to send and receive data and to signal the command. When you have /// finished using this handle, close it by calling the WSManCloseCommand method. This parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanconnectshellcommand void WSManConnectShellCommand( // WSMAN_SHELL_HANDLE shell, DWORD flags, PCWSTR commandID, WSMAN_OPTION_SET *options, WSMAN_DATA *connectXml, WSMAN_SHELL_ASYNC // *async, WSMAN_COMMAND_HANDLE *command ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManConnectShellCommand")] public static extern void WSManConnectShellCommand(WSMAN_SHELL_HANDLE shell, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandID, in WSMAN_OPTION_SET options, in WSMAN_DATA connectXml, in WSMAN_SHELL_ASYNC async, out WSMAN_COMMAND_HANDLE command); /// Connects to an existing command running in a shell. /// Specifies the shell handle returned by the WSManCreateShell call. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// A null-terminated string that identifies a specific command, currently running in the server session, that the client intends to /// connect to. /// /// /// 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. /// /// /// A pointer to a WSMAN_DATA structure that defines an open context for the connect shell operation. The content must be a valid /// XML string. This parameter can be NULL. /// /// /// Defines an asynchronous structure to contain an optional user context and a mandatory callback function. For more information, /// see WSMAN_SHELL_ASYNC. This parameter cannot be NULL. /// /// /// This handle is returned on a successful call and is used to send and receive data and to signal the command. When you have /// finished using this handle, close it by calling the WSManCloseCommand method. This parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanconnectshellcommand void WSManConnectShellCommand( // WSMAN_SHELL_HANDLE shell, DWORD flags, PCWSTR commandID, WSMAN_OPTION_SET *options, WSMAN_DATA *connectXml, WSMAN_SHELL_ASYNC // *async, WSMAN_COMMAND_HANDLE *command ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManConnectShellCommand")] public static extern void WSManConnectShellCommand(WSMAN_SHELL_HANDLE shell, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandID, [In, Optional] IntPtr options, [In, Optional] IntPtr connectXml, in WSMAN_SHELL_ASYNC async, out WSMAN_COMMAND_HANDLE command); /// Creates a session object. /// Specifies the API handle returned by the WSManInitialize call. This parameter cannot be NULL. /// /// /// Indicates to which protocol and agent to connect. If this parameter is NULL, the connection will default to localhost /// (127.0.0.1). 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. /// /// /// 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. /// /// /// A pointer to a WSMAN_PROXY_INFO structure that specifies proxy information. This value can be NULL. /// /// Defines the session handle that uniquely identifies the session. This parameter cannot be NULL. This handle should be /// closed by calling the WSManCloseSession method. /// /// If the function succeeds, the return value is zero. Otherwise, the return value is an error code. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmancreatesession DWORD WSManCreateSession( WSMAN_API_HANDLE // apiHandle, PCWSTR connection, DWORD flags, WSMAN_AUTHENTICATION_CREDENTIALS *serverAuthenticationCredentials, WSMAN_PROXY_INFO // *proxyInfo, WSMAN_SESSION_HANDLE *session ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCreateSession")] public static extern Win32Error WSManCreateSession(WSMAN_API_HANDLE apiHandle, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? connection, [Optional] uint flags, IntPtr serverAuthenticationCredentials, [In, Optional] IntPtr proxyInfo, out SafeWSMAN_SESSION_HANDLE session); /// /// 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. /// /// Specifies the session handle returned by a WSManCreateSession call. This parameter cannot be NULL. /// /// 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. /// /// /// /// 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. /// /// A pointer to a WSMAN_OPTION_SET structure that specifies a set of options for the shell. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmancreateshell void WSManCreateShell( WSMAN_SESSION_HANDLE // session, DWORD flags, PCWSTR resourceUri, WSMAN_SHELL_STARTUP_INFO *startupInfo, WSMAN_OPTION_SET *options, WSMAN_DATA // *createXml, WSMAN_SHELL_ASYNC *async, WSMAN_SHELL_HANDLE *shell ); [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCreateShell")] public static void WSManCreateShell(WSMAN_SESSION_HANDLE session, string resourceUri, [In, Optional] WSMAN_SHELL_STARTUP_INFO? startupInfo, [In, Optional] WSMAN_OPTION_SET? options, [In, Optional] WSMAN_DATA? createXml, in WSMAN_SHELL_ASYNC async, out WSMAN_SHELL_HANDLE shell) => WSManCreateShell(session, 0, resourceUri, (SafeCoTaskMemStruct)startupInfo, (SafeCoTaskMemStruct)options, (SafeCoTaskMemStruct)createXml, async, out shell); /// /// 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. /// /// Specifies the session handle returned by a WSManCreateSession call. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// 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. /// /// /// /// 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. /// /// A pointer to a WSMAN_OPTION_SET structure that specifies a set of options for the shell. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmancreateshell void WSManCreateShell( WSMAN_SESSION_HANDLE // session, DWORD flags, PCWSTR resourceUri, WSMAN_SHELL_STARTUP_INFO *startupInfo, WSMAN_OPTION_SET *options, WSMAN_DATA // *createXml, WSMAN_SHELL_ASYNC *async, WSMAN_SHELL_HANDLE *shell ); [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCreateShell")] [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] public static extern void WSManCreateShell(WSMAN_SESSION_HANDLE session, [Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, [In, Optional] IntPtr startupInfo, [In, Optional] IntPtr options, [In, Optional] IntPtr createXml, in WSMAN_SHELL_ASYNC async, out WSMAN_SHELL_HANDLE shell); /// /// Creates a shell object by using the same functionality as the WSManCreateShell function, with the addition of a client-specified /// shell ID. 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. /// /// Specifies the session handle returned by a WSManCreateSession call. This parameter cannot be NULL. /// Reserved for future use. Must be 0. /// /// 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. /// /// The client specified shellID. /// /// A pointer to a WSMAN_SHELL_STARTUP_INFO structure that specifies the input and output streams, working directory, idle timeout, /// and options for the shell. If this parameter is NULL, the default values will be used. /// /// A pointer to a WSMAN_OPTION_SET structure that specifies a set of options for the shell. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmancreateshellex void WSManCreateShellEx( // WSMAN_SESSION_HANDLE session, DWORD flags, PCWSTR resourceUri, PCWSTR shellId, WSMAN_SHELL_STARTUP_INFO *startupInfo, // WSMAN_OPTION_SET *options, WSMAN_DATA *createXml, WSMAN_SHELL_ASYNC *async, WSMAN_SHELL_HANDLE *shell ); [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCreateShellEx")] public static void WSManCreateShellEx(WSMAN_SESSION_HANDLE session, uint flags, string resourceUri, string shellId, [In, Optional] WSMAN_SHELL_STARTUP_INFO? startupInfo, [In, Optional] WSMAN_OPTION_SET? options, [In, Optional] WSMAN_DATA? createXml, in WSMAN_SHELL_ASYNC async, out WSMAN_SHELL_HANDLE shell) => WSManCreateShellEx(session, flags, resourceUri, shellId, (IntPtr)(SafeCoTaskMemStruct)startupInfo, (SafeCoTaskMemStruct)options, (SafeCoTaskMemStruct)createXml, async, out shell); /// /// Creates a shell object by using the same functionality as the WSManCreateShell function, with the addition of a client-specified /// shell ID. 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. /// /// Specifies the session handle returned by a WSManCreateSession call. This parameter cannot be NULL. /// Reserved for future use. Must be 0. /// /// 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. /// /// The client specified shellID. /// /// A pointer to a WSMAN_SHELL_STARTUP_INFO structure that specifies the input and output streams, working directory, idle timeout, /// and options for the shell. If this parameter is NULL, the default values will be used. /// /// A pointer to a WSMAN_OPTION_SET structure that specifies a set of options for the shell. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmancreateshellex void WSManCreateShellEx( // WSMAN_SESSION_HANDLE session, DWORD flags, PCWSTR resourceUri, PCWSTR shellId, WSMAN_SHELL_STARTUP_INFO *startupInfo, // WSMAN_OPTION_SET *options, WSMAN_DATA *createXml, WSMAN_SHELL_ASYNC *async, WSMAN_SHELL_HANDLE *shell ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManCreateShellEx")] public static extern void WSManCreateShellEx(WSMAN_SESSION_HANDLE session, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, [MarshalAs(UnmanagedType.LPWStr)] string shellId, [In, Optional] IntPtr startupInfo, [In, Optional] IntPtr options, [In, Optional] IntPtr createXml, in WSMAN_SHELL_ASYNC async, out WSMAN_SHELL_HANDLE shell); /// /// Deinitializes the Windows Remote Management client stack. All operations must be complete before a call to this function will /// return. This is a synchronous call. It is recommended that all operations are explicitly canceled and that all sessions are /// closed before calling this function. /// /// Specifies the API handle returned by a WSManInitialize call. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// This method returns zero on success. Otherwise, this method returns an error code. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmandeinitialize DWORD WSManDeinitialize( WSMAN_API_HANDLE // apiHandle, DWORD flags ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManDeinitialize")] public static extern Win32Error WSManDeinitialize(WSMAN_API_HANDLE apiHandle, uint flags = 0); /// Disconnects the network connection of an active shell and its associated commands. /// Specifies the handle returned by a call to the WSManCreateShell function. This parameter cannot be NULL. /// /// Can be a WSMAN_FLAG_SERVER_BUFFERING_MODE_DROP flag or a WSMAN_FLAG_SERVER_BUFFERING_MODE_BLOCK flag. /// /// /// A pointer to a WSMAN_SHELL_DISCONNECT_INFO structure that specifies an idle time-out that the server session may enforce. If /// this parameter is NULL, the server session idle time-out will not be changed. /// /// /// Defines an asynchronous structure to contain an optional user context and a mandatory callback function. For more information, /// see WSMAN_SHELL_ASYNC. This parameter cannot be NULL. /// /// None /// /// /// This function suspends network connection to an actively connected server session. Any operations performed on the shell /// instance, like WSManRunShellCommand, WSManSendShellInput, or WSManSignalShell, are bound to complete before disconnection. This /// ensures that any data sent through WSManSendShellInput is received by the server session before the shell disconnects. /// The client can optionally modify the server buffering mode by using flags. The following behavior is observed: /// /// /// /// /// WSMAN_FLAG_SERVER_BUFFERING_MODE_DROP–When buffers are full, the server drops earlier data in response stream buffers to /// ensure the corresponding command operation continues to run. /// /// /// /// /// WSMAN_FLAG_SERVER_BUFFERING_MODE_BLOCK–When response stream buffers are full, the server blocks command execution. If no /// flag is specified, the server continues to use either the configured mode or the mode specified when the shell was created. In /// case of a network failure, if the client is unable to contact the session to disconnect the shell, the following error is returned: /// ERROR_WINRS_SHELL_DISCONNECT_OPERATION_NOT_GRACEFUL /// /// The client session still goes into a disconnected state, but it is not guaranteed that any prior operations have completed /// before the session is disconnected. /// /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmandisconnectshell void WSManDisconnectShell( // WSMAN_SHELL_HANDLE shell, DWORD flags, WSMAN_SHELL_DISCONNECT_INFO *disconnectInfo, WSMAN_SHELL_ASYNC *async ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManDisconnectShell")] public static extern void WSManDisconnectShell(WSMAN_SHELL_HANDLE shell, WSMAN_FLAG_SERVER_BUFFERING_MODE flags, ref WSMAN_SHELL_DISCONNECT_INFO disconnectInfo, ref WSMAN_SHELL_ASYNC async); /// Disconnects the network connection of an active shell and its associated commands. /// Specifies the handle returned by a call to the WSManCreateShell function. This parameter cannot be NULL. /// /// Can be a WSMAN_FLAG_SERVER_BUFFERING_MODE_DROP flag or a WSMAN_FLAG_SERVER_BUFFERING_MODE_BLOCK flag. /// /// /// A pointer to a WSMAN_SHELL_DISCONNECT_INFO structure that specifies an idle time-out that the server session may enforce. If /// this parameter is NULL, the server session idle time-out will not be changed. /// /// /// Defines an asynchronous structure to contain an optional user context and a mandatory callback function. For more information, /// see WSMAN_SHELL_ASYNC. This parameter cannot be NULL. /// /// None /// /// /// This function suspends network connection to an actively connected server session. Any operations performed on the shell /// instance, like WSManRunShellCommand, WSManSendShellInput, or WSManSignalShell, are bound to complete before disconnection. This /// ensures that any data sent through WSManSendShellInput is received by the server session before the shell disconnects. /// The client can optionally modify the server buffering mode by using flags. The following behavior is observed: /// /// /// /// /// WSMAN_FLAG_SERVER_BUFFERING_MODE_DROP–When buffers are full, the server drops earlier data in response stream buffers to /// ensure the corresponding command operation continues to run. /// /// /// /// /// WSMAN_FLAG_SERVER_BUFFERING_MODE_BLOCK–When response stream buffers are full, the server blocks command execution. If no /// flag is specified, the server continues to use either the configured mode or the mode specified when the shell was created. In /// case of a network failure, if the client is unable to contact the session to disconnect the shell, the following error is returned: /// ERROR_WINRS_SHELL_DISCONNECT_OPERATION_NOT_GRACEFUL /// /// The client session still goes into a disconnected state, but it is not guaranteed that any prior operations have completed /// before the session is disconnected. /// /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmandisconnectshell void WSManDisconnectShell( // WSMAN_SHELL_HANDLE shell, DWORD flags, WSMAN_SHELL_DISCONNECT_INFO *disconnectInfo, WSMAN_SHELL_ASYNC *async ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManDisconnectShell")] public static extern void WSManDisconnectShell(WSMAN_SHELL_HANDLE shell, WSMAN_FLAG_SERVER_BUFFERING_MODE flags, [In, Optional] IntPtr disconnectInfo, ref WSMAN_SHELL_ASYNC async); /// Retrieves the error messages associated with a particular error and language codes. /// Specifies the API handle returned by a WSManInitialize call. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// Specifies the language code name that should be used to localize the error. For more information about the language code names, /// see the RFC 3066 specification from the Internet Engineering Task Force at http://www.ietf.org/rfc/rfc3066.txt. If a language /// code is not specified, the user interface language of the thread is used. /// /// /// Specifies the error code for the requested error message. This error code can be a hexadecimal or decimal error code from a /// WinRM, WinHTTP, or other Windows operating system feature. /// /// /// Specifies the number of characters that can be stored in the output message buffer, including the null terminator. If /// this parameter is zero, the message parameter must be NULL. /// /// /// Specifies the output buffer to store the message in. This buffer must be allocated and deallocated by the client. The buffer /// must be large enough to store the message and the null terminator. If this parameter is NULL, the messageLength /// parameter must be NULL. /// /// /// Specifies the actual number of characters written to the output buffer, including the null terminator. This parameter /// cannot be NULL. If either the messageLength or message parameters are zero, the function will return /// ERROR_INSUFFICIENT_BUFFER and this parameter will be set to the number of characters needed to store the message, /// including the null terminator. /// /// This method returns zero on success. Otherwise, this method returns an error code. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmangeterrormessage DWORD WSManGetErrorMessage( // WSMAN_API_HANDLE apiHandle, DWORD flags, PCWSTR languageCode, DWORD errorCode, DWORD messageLength, PWSTR message, DWORD // *messageLengthUsed ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManGetErrorMessage")] public static extern Win32Error WSManGetErrorMessage(WSMAN_API_HANDLE apiHandle, [Optional] uint flags, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? languageCode, uint errorCode, uint messageLength, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? message, out uint messageLengthUsed); /// Gets the value of a session option. /// Specifies the handle returned by a WSManCreateSession call. This parameter cannot be NULL. /// /// Specifies the option to get. Not all session options can be retrieved. The options are defined in the WSManSessionOption enumeration. /// /// Specifies the value of specified session option. /// This method returns zero on success. Otherwise, this method returns an error code. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmangetsessionoptionasdword DWORD // WSManGetSessionOptionAsDword( WSMAN_SESSION_HANDLE session, WSManSessionOption option, DWORD *value ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManGetSessionOptionAsDword")] public static extern Win32Error WSManGetSessionOptionAsDword(WSMAN_SESSION_HANDLE session, WSManSessionOption option, out uint value); /// Gets the value of a session option. /// Specifies the session handle returned by a WSManCreateSession call. This parameter cannot be NULL. /// /// Specifies the option to get. Not all session options can be retrieved. The values for the options are defined in the /// WSManSessionOption enumeration. /// /// Specifies the length of the storage location for string parameter. /// A pointer to the storage location for the value of the specified session option. /// Specifies the length of the string returned in the string parameter. /// This method returns zero on success. Otherwise, this method returns an error code. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmangetsessionoptionasstring DWORD // WSManGetSessionOptionAsString( WSMAN_SESSION_HANDLE session, WSManSessionOption option, DWORD stringLength, PWSTR string, DWORD // *stringLengthUsed ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManGetSessionOptionAsString")] public static extern Win32Error WSManGetSessionOptionAsString(WSMAN_SESSION_HANDLE session, WSManSessionOption option, uint stringLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder? @string, out uint stringLengthUsed); /// /// Initializes the Windows Remote Management Client API. WSManInitialize can be used by different clients on the same process. /// /// /// A flag of type WSMAN_FLAG_REQUESTED_API_VERSION_1_0 or WSMAN_FLAG_REQUESTED_API_VERSION_1_1. The client that will /// use the disconnect-reconnect functionality should use the WSMAN_FLAG_REQUESTED_API_VERSION_1_1 flag. /// /// /// Defines a handle that uniquely identifies the client. This parameter cannot be NULL. When you have finished used the /// handle, close it by calling the WSManDeinitialize method. /// /// This method returns zero on success. Otherwise, this method returns an error code. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmaninitialize DWORD WSManInitialize( DWORD flags, // WSMAN_API_HANDLE *apiHandle ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManInitialize")] public static extern Win32Error WSManInitialize(WSMAN_FLAG_REQUESTED_API_VERSION flags, out SafeWSMAN_API_HANDLE apiHandle); /// /// Called from the WSManPluginAuthzOperation plug-in entry point. It reports either a successful or failed authorization for a user operation. /// /// /// A pointer to the WSMAN_SENDER_DETAILS structure that was passed into the WSManPluginAuthzOperation plug-in call. /// /// Reserved for future use. Must be zero. /// /// Specifies a plug-in defined context that is used to help track user context information. This context can be returned to /// multiple calls, to this call, or to an operation call. The plug-in manages reference counting for all calls. If the user record /// times out or re-authorization is required, the WinRM (WinRM) infrastructure calls WSManPluginAuthzReleaseContext. /// /// /// Reports either a successful or failed authorization. If the authorization is successful, the code should be /// ERROR_SUCCESS. If the user is not authorized to perform the operation, the error should be ERROR_ACCESS_DENIED. If /// a failure happens for any other reason, an appropriate error code should be used. Any error from this call will be sent back as /// a Simple Object Access Protocol (SOAP) fault packet. /// /// /// Specifies an XML document that contains any extra error information that needs to be reported to the client. This parameter is /// ignored if errorCode is NO_ERROR. The user interface language of the thread should be used for localization. /// /// /// The method returns ERROR_SUCCESS if it succeeded; otherwise, it returns ERROR_INVALID_PARAMETER. If /// ERROR_INVALID_PARAMETER is returned, either the senderDetails parameter was NULL or the flags parameter was not zero. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginauthzoperationcomplete DWORD // WSManPluginAuthzOperationComplete( WSMAN_SENDER_DETAILS *senderDetails, DWORD flags, PVOID userAuthorizationContext, DWORD // errorCode, PCWSTR extendedErrorInformation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginAuthzOperationComplete")] public static extern Win32Error WSManPluginAuthzOperationComplete(in WSMAN_SENDER_DETAILS senderDetails, [Optional] uint flags, [In, Optional] IntPtr userAuthorizationContext, uint errorCode, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? extendedErrorInformation); /// /// Called from the WSManPluginAuthzQueryQuota plug-in entry point and must be called whether or not the plug-in can carry out the request. /// /// /// A pointer to the WSMAN_SENDER_DETAILS structure that was passed into the WSManPluginAuthzQueryQuota plug-in call. /// /// Reserved for future use. Must be zero. /// A pointer to a WSMAN_AUTHZ_QUOTA structure that specifies quota information for a specific user. /// /// Reports either a successful or failed authorization. If the authorization is successful, the code should be /// ERROR_SUCCESS. If a failure happens for any other reason, an appropriate error code should be used. Any error from this /// call will be sent back as a Simple Object Access Protocol (SOAP) fault packet. /// /// /// Specifies an XML document that contains any extra error information that needs to be reported to the client. This parameter is /// ignored if errorCode is NO_ERROR. The user interface language of the thread should be used for localization. /// /// /// The method returns ERROR_SUCCESS if it succeeded; otherwise, it returns ERROR_INVALID_PARAMETER. If /// ERROR_INVALID_PARAMETER is returned, either the senderDetails parameter was NULL or the flags parameter was not /// zero. If the method fails, the default quota is used. /// /// /// If the quota parameter is null and the errorCode is NO_ERROR, the method returns ERROR_INVALID_PARAMETER /// and the plug-in returns the default quota information. If the plug-in is not returning a quota, the authorization plug-in should /// not specify that quotas are available in the configuration because performance might be affected. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginauthzqueryquotacomplete DWORD // WSManPluginAuthzQueryQuotaComplete( WSMAN_SENDER_DETAILS *senderDetails, DWORD flags, WSMAN_AUTHZ_QUOTA *quota, DWORD errorCode, // PCWSTR extendedErrorInformation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginAuthzQueryQuotaComplete")] public static extern Win32Error WSManPluginAuthzQueryQuotaComplete(in WSMAN_SENDER_DETAILS senderDetails, [Optional] uint flags, in WSMAN_AUTHZ_QUOTA quota, uint errorCode, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? extendedErrorInformation); /// /// Called from the WSManPluginAuthzQueryQuota plug-in entry point and must be called whether or not the plug-in can carry out the request. /// /// /// A pointer to the WSMAN_SENDER_DETAILS structure that was passed into the WSManPluginAuthzQueryQuota plug-in call. /// /// Reserved for future use. Must be zero. /// A pointer to a WSMAN_AUTHZ_QUOTA structure that specifies quota information for a specific user. /// /// Reports either a successful or failed authorization. If the authorization is successful, the code should be /// ERROR_SUCCESS. If a failure happens for any other reason, an appropriate error code should be used. Any error from this /// call will be sent back as a Simple Object Access Protocol (SOAP) fault packet. /// /// /// Specifies an XML document that contains any extra error information that needs to be reported to the client. This parameter is /// ignored if errorCode is NO_ERROR. The user interface language of the thread should be used for localization. /// /// /// The method returns ERROR_SUCCESS if it succeeded; otherwise, it returns ERROR_INVALID_PARAMETER. If /// ERROR_INVALID_PARAMETER is returned, either the senderDetails parameter was NULL or the flags parameter was not /// zero. If the method fails, the default quota is used. /// /// /// If the quota parameter is null and the errorCode is NO_ERROR, the method returns ERROR_INVALID_PARAMETER /// and the plug-in returns the default quota information. If the plug-in is not returning a quota, the authorization plug-in should /// not specify that quotas are available in the configuration because performance might be affected. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginauthzqueryquotacomplete DWORD // WSManPluginAuthzQueryQuotaComplete( WSMAN_SENDER_DETAILS *senderDetails, DWORD flags, WSMAN_AUTHZ_QUOTA *quota, DWORD errorCode, // PCWSTR extendedErrorInformation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginAuthzQueryQuotaComplete")] public static extern Win32Error WSManPluginAuthzQueryQuotaComplete(in WSMAN_SENDER_DETAILS senderDetails, [Optional] uint flags, [In, Optional] IntPtr quota, uint errorCode, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? extendedErrorInformation); /// /// Called from the WSManPluginAuthzUser plug-in entry point and reports either a successful or failed user connection authorization. /// /// /// A pointer to the WSMAN_SENDER_DETAILS structure that was passed into the WSManPluginAuthzUser plug-in call. /// /// Reserved for future use. Must be set to zero. /// /// Specifies a plug-in defined context that is used to help track user context information. This context can be returned to /// multiple calls, to this call, or to an operation call. The plug-in manages reference counting for all calls. If the user record /// times out or re-authorization is required, the WinRM infrastructure calls WSManPluginAuthzReleaseContext. /// /// /// /// Specifies the identity of the user. This parameter is the clientToken that was passed into senderDetails. If the plug-in changes /// the user context, a new impersonation token should be returned. /// /// Note This token is released after the operation has been completed. /// /// Set to TRUE if the user is an administrator. Otherwise, this parameter is FALSE. /// /// Reports either a successful or failed authorization. If the authorization is successful, the code should be /// ERROR_SUCCESS. If the user is not authorized to perform the operation, the error should be ERROR_ACCESS_DENIED. If /// a failure happens for any other reason, an appropriate error code should be used. Any error from this call will be sent back as /// a SOAP fault packet. /// /// /// Specifies an XML document that contains any extra error information that needs to be reported to the client. This parameter is /// ignored if errorCode is NO_ERROR. The user interface language of the thread should be used for localization. /// /// /// The method returns ERROR_SUCCESS if it succeeded; otherwise, it returns ERROR_INVALID_PARAMETER. If /// ERROR_INVALID_PARAMETER is returned, either the senderDetails parameter was NULL or the flags parameter was not zero. /// /// /// /// If the impersonation token passed into senderDetails is not the identity with which the operation should be performed, or if no /// impersonation token is available and the plug-in specifies a new identity to carry out the request, the plug-in should return /// the new impersonationToken that the WSMan infrastructure will use to impersonate the client before calling into the operation /// plug-in. If an impersonation token is provided in the senderDetails and the plug-in wants to carry out the operation under that /// identity, the plug-in should copy the impersonation token from the senderDetails into the impersonationToken parameter. If the /// plug-in wants to carry out the request under the context of the Internet Information Services (IIS) host process, the /// impersonationToken should be NULL. If the impersonationToken is NULL, the thread will impersonate the process /// token before calling into the operation plug-in. /// /// /// If the userIsAdministrator parameter is set to TRUE, the user is allowed to view and delete shells owned by different users. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginauthzusercomplete DWORD // WSManPluginAuthzUserComplete( WSMAN_SENDER_DETAILS *senderDetails, DWORD flags, PVOID userAuthorizationContext, HANDLE // impersonationToken, BOOL userIsAdministrator, DWORD errorCode, PCWSTR extendedErrorInformation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginAuthzUserComplete")] public static extern Win32Error WSManPluginAuthzUserComplete(in WSMAN_SENDER_DETAILS senderDetails, [Optional] uint flags, [In, Optional] IntPtr userAuthorizationContext, [In, Optional] HTOKEN impersonationToken, [MarshalAs(UnmanagedType.Bool)] bool userIsAdministrator, uint errorCode, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? extendedErrorInformation); /// /// Releases memory that is allocated for the WSMAN_PLUGIN_REQUEST structure, which is passed into operation plug-in entry points. /// This method is optional and can be called at any point after a plug-in entry point is called and before the entry point calls /// the WSManPluginOperationComplete method. After this method is called, the memory will be released and the plug-in will be unable /// to access any of the parameters in the WSMAN_PLUGIN_REQUEST structure. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for /// the request. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginfreerequestdetails DWORD // WSManPluginFreeRequestDetails( WSMAN_PLUGIN_REQUEST *requestDetails ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginFreeRequestDetails")] public static extern Win32Error WSManPluginFreeRequestDetails(in WSMAN_PLUGIN_REQUEST requestDetails); /// /// Gets operational information for items such as time-outs and data restrictions that are associated with the operation. A plug-in /// should not use these parameters for anything other than informational purposes. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for /// the request. /// /// /// /// Specifies the options that are available for retrieval. This parameter must be set to either one of the following values or to a /// value defined by the plug-in. /// /// WSMAN_PLUGIN_PARAMS_MAX_ENVELOPE_SIZE (1) /// /// Specifies the maximum size of the operation response packet. The size includes the size of the data along with the Simple Object /// Access Protocol (SOAP) overhead. /// /// /// Note Some operations have a single call into the plug-in that can cause multiple roundtrips to occur. If no requests are /// waiting for data when this method is called, the maximum envelope size for the previous packet is given. /// /// WSMAN_PLUGIN_PARAMS_TIMEOUT (2) /// Specifies the time-out of the current operation. /// /// Note Some operations have a single call into the plug-in that can cause multiple roundtrips to occur. If no requests are /// waiting for data when this method is called, the time-out for the previous packet is given. /// /// WSMAN_PLUGIN_PARAMS_REMAINING_RESULT_SIZE (3) /// /// Specifies how much space is left for data for the current operation. The size is based on the type of operation. For example, /// this flag would represent how large the single result item can be for a get operation. For enumerations, the size will decrease /// after each object is added. After the current packet has been filled with enumerations and get operations, it will be returned /// to the client even though more data is being accepted and cached. /// /// /// Note Some operations have a single call into the plug-in that can cause multiple roundtrips to occur. If no requests are /// waiting for data when this method is called, the remaining size is given for a cached item. /// /// WSMAN_PLUGIN_PARAMS_LARGEST_RESULT_SIZE (4) /// Specifies the maximum size of the data for the current operation. /// WSMAN_PLUGIN_PARAMS_GET_REQUESTED_LOCALE (5) /// Specifies the language locale that was requested by the client for the operation. /// WSMAN_PLUGIN_PARAMS_GET_REQUESTED_DATA_LOCALE (6) /// Specifies the language locale of the data that was requested by the client. /// /// A pointer to a WSMAN_DATA structure that specifies the result object. /// /// The method returns NO_ERROR if it succeeded; otherwise, it returns an error code. The following are the most common error codes: /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanplugingetoperationparameters DWORD // WSManPluginGetOperationParameters( WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, WSMAN_DATA *data ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginGetOperationParameters")] public static extern Win32Error WSManPluginGetOperationParameters(in WSMAN_PLUGIN_REQUEST requestDetails, WSMAN_PLUGIN_PARAMS_OP flags, out WSMAN_DATA data); /// /// Reports the completion of an operation by all operation entry points except for the WSManPluginStartup and WSManPluginShutdown methods. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for /// the request. /// /// Reserved for future use. Must be zero. /// /// Reports any failure in the operation. If this parameter is not NO_ERROR, any result data that has not been sent will be /// discarded and the error will be sent. /// /// /// Specifies an XML document that contains any extra error information that needs to be reported to the client. This parameter is /// ignored if errorCode is NO_ERROR. The user interface language of the thread should be used for localization. /// /// /// The method returns NO_ERROR if it succeeded; otherwise, it returns an error code. If the operation is unsuccessful, the /// plug-in must stop the current operation and clean up any data associated with this operation. The requestDetails structure is /// not valid if an error is received and must not be passed to any other WinRM (WinRM) method. /// /// /// The WSManPluginOperationComplete function is used to report the completion of the data stream for WSManPluginReceive. The /// WSManPluginShell and WSManPluginCommand operations must also call this function when the shell and command operations are complete. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginoperationcomplete DWORD // WSManPluginOperationComplete( WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, DWORD errorCode, PCWSTR extendedInformation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginOperationComplete")] public static extern Win32Error WSManPluginOperationComplete(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, uint errorCode, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? extendedInformation); /// /// Reports results for the WSMAN_PLUGIN_RECEIVE plug-in call and is used by most shell plug-ins that return results. After all of /// the data is received, the WSManPluginOperationComplete method must be called. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for /// the request. /// /// Reserved for future use. Must be set to zero. /// /// Specifies the stream that the data is associated with. Any stream can be used, but the standard streams are STDIN, STDOUT, and STDERR. /// /// /// A pointer to a WSMAN_DATA structure that specifies the result object that is returned to the client. The result can be in either /// binary or XML format. /// /// /// /// Specifies the state of the command. This parameter must be set either to one of the following values or to a value defined by /// the plug-in. /// /// WSMAN_RECEIVE_STATE_NONE /// The operation requires no action. /// WSMAN_RECEIVE_STATE_NORMAL_TERMINATION /// The operation was terminated normally. /// WSMAN_RECEIVE_STATE_ABNORMAL_TERMINATION /// The operation was terminated unexpectedly. /// WSMAN_RECEIVE_STATE_WAITING /// The operation is waiting for input. /// WSMAN_RECEIVE_STATE_INPUT_REQUIRED /// The operation requires command-line input. /// /// /// Ignored in all cases except when commandState is either WSMAN_RECEIVE_STATE_NORMAL_TERMINATION or /// WSMAN_RECEIVE_STATE_ABNORMAL_TERMINATION. Each result can have separate error codes. If the command or stream has failed, /// the plug-in must call the WSManPluginOperationComplete method. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginreceiveresult DWORD WSManPluginReceiveResult( // WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, PCWSTR stream, WSMAN_DATA *streamResult, PCWSTR commandState, DWORD exitCode ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginReceiveResult")] public static extern Win32Error WSManPluginReceiveResult(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? stream, in WSMAN_DATA streamResult, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? commandState, uint exitCode); /// /// Reports results for the WSMAN_PLUGIN_RECEIVE plug-in call and is used by most shell plug-ins that return results. After all of /// the data is received, the WSManPluginOperationComplete method must be called. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for /// the request. /// /// Reserved for future use. Must be set to zero. /// /// Specifies the stream that the data is associated with. Any stream can be used, but the standard streams are STDIN, STDOUT, and STDERR. /// /// /// A pointer to a WSMAN_DATA structure that specifies the result object that is returned to the client. The result can be in either /// binary or XML format. /// /// /// /// Specifies the state of the command. This parameter must be set either to one of the following values or to a value defined by /// the plug-in. /// /// WSMAN_RECEIVE_STATE_NONE /// The operation requires no action. /// WSMAN_RECEIVE_STATE_NORMAL_TERMINATION /// The operation was terminated normally. /// WSMAN_RECEIVE_STATE_ABNORMAL_TERMINATION /// The operation was terminated unexpectedly. /// WSMAN_RECEIVE_STATE_WAITING /// The operation is waiting for input. /// WSMAN_RECEIVE_STATE_INPUT_REQUIRED /// The operation requires command-line input. /// /// /// Ignored in all cases except when commandState is either WSMAN_RECEIVE_STATE_NORMAL_TERMINATION or /// WSMAN_RECEIVE_STATE_ABNORMAL_TERMINATION. Each result can have separate error codes. If the command or stream has failed, /// the plug-in must call the WSManPluginOperationComplete method. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginreceiveresult DWORD WSManPluginReceiveResult( // WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, PCWSTR stream, WSMAN_DATA *streamResult, PCWSTR commandState, DWORD exitCode ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginReceiveResult")] public static extern Win32Error WSManPluginReceiveResult(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? stream, [In, Optional] IntPtr streamResult, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? commandState, uint exitCode); /// /// Reports shell and command context back to the Windows Remote Management (WinRM) infrastructure so that further operations can be /// performed against the shell and/or command. This method is called only for WSManPluginShell and WSManPluginCommand plug-in entry points. /// /// /// A pointer to a WSMAN_PLUGIN_REQUEST structure that specifies the resource URI, options, locale, shutdown flag, and handle for /// the request. /// /// Reserved for future use. Must be set to zero. /// /// Defines the value to pass into all future shell and command operations. Represents either the shell or the command. This value /// should be unique for all shells, and it should also be unique for all commands associated with a shell. /// /// /// The method returns NO_ERROR if it succeeded; otherwise, it returns an error code. If this method returns an error, the /// plug-in should shut down the current operation and call the WSManPluginOperationComplete method. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanpluginreportcontext DWORD WSManPluginReportContext( // WSMAN_PLUGIN_REQUEST *requestDetails, DWORD flags, PVOID context ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManPluginReportContext")] public static extern Win32Error WSManPluginReportContext(in WSMAN_PLUGIN_REQUEST requestDetails, [Optional] uint flags, [In, Optional] IntPtr context); /// Retrieves output from a running command or from the shell. /// Specifies the shell handle returned by a WSManCreateShell call. This parameter cannot be NULL. /// Specifies the command handle returned by a WSManRunShellCommand call. /// Reserved for future use. Must be set to zero. /// Specifies the requested output from a particular stream or a list of streams. /// /// 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 WSManCloseOperation method. /// /// /// Defines the operation handle for the receive operation. This handle is returned from a successful call of the function and can /// be used to asynchronously cancel the receive operation. This handle should be closed by calling the WSManCloseOperation method. /// This parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanreceiveshelloutput void WSManReceiveShellOutput( // WSMAN_SHELL_HANDLE shell, WSMAN_COMMAND_HANDLE command, DWORD flags, WSMAN_STREAM_ID_SET *desiredStreamSet, WSMAN_SHELL_ASYNC // *async, WSMAN_OPERATION_HANDLE *receiveOperation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManReceiveShellOutput")] public static extern void WSManReceiveShellOutput(WSMAN_SHELL_HANDLE shell, [In, Optional] WSMAN_COMMAND_HANDLE command, [In, Optional] uint flags, in WSMAN_STREAM_ID_SET desiredStreamSet, in WSMAN_SHELL_ASYNC async, out SafeWSMAN_OPERATION_HANDLE receiveOperation); /// Retrieves output from a running command or from the shell. /// Specifies the shell handle returned by a WSManCreateShell call. This parameter cannot be NULL. /// Specifies the command handle returned by a WSManRunShellCommand call. /// Reserved for future use. Must be set to zero. /// Specifies the requested output from a particular stream or a list of streams. /// /// 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 WSManCloseOperation method. /// /// /// Defines the operation handle for the receive operation. This handle is returned from a successful call of the function and can /// be used to asynchronously cancel the receive operation. This handle should be closed by calling the WSManCloseOperation method. /// This parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanreceiveshelloutput void WSManReceiveShellOutput( // WSMAN_SHELL_HANDLE shell, WSMAN_COMMAND_HANDLE command, DWORD flags, WSMAN_STREAM_ID_SET *desiredStreamSet, WSMAN_SHELL_ASYNC // *async, WSMAN_OPERATION_HANDLE *receiveOperation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManReceiveShellOutput")] public static extern void WSManReceiveShellOutput(WSMAN_SHELL_HANDLE shell, [In, Optional] WSMAN_COMMAND_HANDLE command, [In, Optional] uint flags, [In, Optional] IntPtr desiredStreamSet, in WSMAN_SHELL_ASYNC async, out SafeWSMAN_OPERATION_HANDLE receiveOperation); /// Reconnects a previously disconnected shell session. To reconnect the shell session's associated commands, use WSManReconnectShellCommand. /// Specifies the handle returned by a call to the WSManCreateShell function. This parameter cannot be NULL. /// This parameter is reserved for future use and must be set to zero. /// /// Defines an asynchronous structure to contain an optional user context and a mandatory callback function. For more information, /// see WSMAN_SHELL_ASYNC. This parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanreconnectshell void WSManReconnectShell( // WSMAN_SHELL_HANDLE shell, DWORD flags, WSMAN_SHELL_ASYNC *async ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManReconnectShell")] public static extern void WSManReconnectShell([In, Out] WSMAN_SHELL_HANDLE shell, uint flags, in WSMAN_SHELL_ASYNC async); /// Reconnects a previously disconnected command. /// /// Specifies the handle returned by a WSManRunShellCommand call or a WSManConnectShellCommand call. This parameter cannot be NULL. /// /// Reserved for future use. Must be set to zero. /// /// Defines an asynchronous structure which will contain an optional user context and a mandatory callback function. See the /// WSMAN_SHELL_ASYNC structure for more information. This parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanreconnectshellcommand void WSManReconnectShellCommand( // WSMAN_COMMAND_HANDLE commandHandle, DWORD flags, WSMAN_SHELL_ASYNC *async ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManReconnectShellCommand")] public static extern void WSManReconnectShellCommand([In, Out] WSMAN_COMMAND_HANDLE commandHandle, [Optional] uint flags, in WSMAN_SHELL_ASYNC async); /// Starts the execution of a command within an existing shell and does not wait for the completion of the command. /// Specifies the shell handle returned by the WSManCreateShell call. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanrunshellcommand void WSManRunShellCommand( // WSMAN_SHELL_HANDLE shell, DWORD flags, PCWSTR commandLine, WSMAN_COMMAND_ARG_SET *args, WSMAN_OPTION_SET *options, // WSMAN_SHELL_ASYNC *async, WSMAN_COMMAND_HANDLE *command ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManRunShellCommand")] public static extern void WSManRunShellCommand(WSMAN_SHELL_HANDLE shell, [Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string? commandLine, in WSMAN_COMMAND_ARG_SET args, in WSMAN_OPTION_SET options, in WSMAN_SHELL_ASYNC async, out WSMAN_COMMAND_HANDLE command); /// Starts the execution of a command within an existing shell and does not wait for the completion of the command. /// Specifies the shell handle returned by the WSManCreateShell call. This parameter cannot be NULL. /// Reserved for future use. Must be zero. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanrunshellcommand void WSManRunShellCommand( // WSMAN_SHELL_HANDLE shell, DWORD flags, PCWSTR commandLine, WSMAN_COMMAND_ARG_SET *args, WSMAN_OPTION_SET *options, // WSMAN_SHELL_ASYNC *async, WSMAN_COMMAND_HANDLE *command ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManRunShellCommand")] public static extern void WSManRunShellCommand(WSMAN_SHELL_HANDLE shell, [Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandLine, [In, Optional] IntPtr args, [In, Optional] IntPtr options, in WSMAN_SHELL_ASYNC async, out WSMAN_COMMAND_HANDLE command); /// /// Provides the same functionality as the WSManRunShellCommand function, with the addition of a command ID option. If the server /// supports the protocol, it will create the command instance using the ID specified by the client. If a command with the specified /// ID already exists, the server will fail to create the command instance. This new functionality is only available when the client /// application passes the WSMAN_FLAG_REQUESTED_API_VERSION_1_1 flag as part of the call to the WSManInitialize function. /// /// Specifies the shell handle returned by the WSManCreateShell call. This parameter cannot be NULL. /// Reserved for future use. Must be 0. /// The client specified command Id. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanrunshellcommandex void WSManRunShellCommandEx( // WSMAN_SHELL_HANDLE shell, DWORD flags, PCWSTR commandId, PCWSTR commandLine, WSMAN_COMMAND_ARG_SET *args, WSMAN_OPTION_SET // *options, WSMAN_SHELL_ASYNC *async, WSMAN_COMMAND_HANDLE *command ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManRunShellCommandEx")] public static extern void WSManRunShellCommandEx([In, Out] WSMAN_SHELL_HANDLE shell, [Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandId, [MarshalAs(UnmanagedType.LPWStr)] string? commandLine, in WSMAN_COMMAND_ARG_SET args, in WSMAN_OPTION_SET options, in WSMAN_SHELL_ASYNC async, out WSMAN_COMMAND_HANDLE command); /// /// Provides the same functionality as the WSManRunShellCommand function, with the addition of a command ID option. If the server /// supports the protocol, it will create the command instance using the ID specified by the client. If a command with the specified /// ID already exists, the server will fail to create the command instance. This new functionality is only available when the client /// application passes the WSMAN_FLAG_REQUESTED_API_VERSION_1_1 flag as part of the call to the WSManInitialize function. /// /// Specifies the shell handle returned by the WSManCreateShell call. This parameter cannot be NULL. /// Reserved for future use. Must be 0. /// The client specified command Id. /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// /// 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. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmanrunshellcommandex void WSManRunShellCommandEx( // WSMAN_SHELL_HANDLE shell, DWORD flags, PCWSTR commandId, PCWSTR commandLine, WSMAN_COMMAND_ARG_SET *args, WSMAN_OPTION_SET // *options, WSMAN_SHELL_ASYNC *async, WSMAN_COMMAND_HANDLE *command ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManRunShellCommandEx")] public static extern void WSManRunShellCommandEx([In, Out] WSMAN_SHELL_HANDLE shell, [Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandId, [MarshalAs(UnmanagedType.LPWStr)] string? commandLine, [In, Optional] IntPtr args, [In, Optional] IntPtr options, in WSMAN_SHELL_ASYNC async, out WSMAN_COMMAND_HANDLE command); /// Pipes the input stream to a running command or to the shell. /// Specifies the shell handle returned by a WSManCreateShell call. This parameter cannot be NULL. /// /// Specifies the command handle returned by a WSManRunShellCommand call. This handle should be closed by calling the /// WSManCloseCommand method. /// /// Reserved for future use. Must be set to zero. /// Specifies the input stream ID. This parameter cannot be NULL. /// /// Uses the WSMAN_DATA structure to specify the stream data to be sent to the command or shell. This structure should be allocated /// by the calling client and must remain allocated until WSManSendShellInput completes. If the end of the stream has been /// reached, the endOfStream parameter should be set to TRUE. /// /// /// Set to TRUE, if the end of the stream has been reached. Otherwise, this parameter is set to FALSE. /// /// /// 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. /// /// /// Defines the operation handle for the send operation. This handle is returned from a successful call of the function and can be /// used to asynchronously cancel the send operation. This handle should be closed by calling the WSManCloseOperation method. This /// parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmansendshellinput void WSManSendShellInput( // WSMAN_SHELL_HANDLE shell, WSMAN_COMMAND_HANDLE command, DWORD flags, PCWSTR streamId, WSMAN_DATA *streamData, BOOL endOfStream, // WSMAN_SHELL_ASYNC *async, WSMAN_OPERATION_HANDLE *sendOperation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManSendShellInput")] public static extern void WSManSendShellInput(WSMAN_SHELL_HANDLE shell, [In, Optional] WSMAN_COMMAND_HANDLE command, [In, Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string streamId, in WSMAN_DATA streamData, [MarshalAs(UnmanagedType.Bool)] bool endOfStream, in WSMAN_SHELL_ASYNC async, out SafeWSMAN_OPERATION_HANDLE sendOperation); /// Sets an extended set of options for the session. /// Specifies the session handle returned by a WSManCreateSession call. This parameter cannot be NULL. /// /// Specifies the option to be set. This parameter must be set to one of the values in the WSManSessionOption enumeration. /// /// A pointer to a WSMAN_DATA structure that defines the option value. /// This method returns zero on success. Otherwise, this method returns an error code. /// /// /// If the WSManSetSessionOption method is called with different values specified for the option parameter, the order of the /// different options is important. The first time WSManSetSessionOption is called, the transport is set for the session. If /// a second call requests a different type of transport, the call will fail. /// /// For example, the second method call will fail if the methods are called in the following order: /// /// /// /// WSManSetSessionOption(WSMAN_OPTION_UNENCRYPTED_MESSAGES) /// /// /// /// /// WSManSetSessionOption(WSMAN_OPTION_ALLOW_NEGOTIATE_IMPLICIT_CREDENTIALS) /// /// /// /// /// The first method call sets the transport to HTTP because the option parameter is set to /// WSMAN_OPTION_UNENCRYPTED_MESSAGES. The second call fails because the option that was passed is applicable for HTTPS and /// the transport was set to HTTP by the first message. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmansetsessionoption DWORD WSManSetSessionOption( // WSMAN_SESSION_HANDLE session, WSManSessionOption option, WSMAN_DATA *data ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManSetSessionOption")] public static extern Win32Error WSManSetSessionOption(WSMAN_SESSION_HANDLE session, WSManSessionOption option, in WSMAN_DATA data); /// Sends a control code to an existing command or to the shell itself. /// Specifies the handle returned by a WSManCreateShell call. This parameter cannot be NULL. /// /// Specifies the command handle returned by a WSManRunShellCommand call. If this value is NULL, the signal code is sent to /// the shell. /// /// Reserved for future use. Must be set to zero. /// /// Specifies the signal code to send to the command or shell. The following codes are common. /// WSMAN_SIGNAL_SHELL_CODE_TERMINATE /// The shell or Command Prompt window was closed. /// WSMAN_SIGNAL_SHELL_CODE_CTRL_C /// The signal for CTRL+C was received, and the process was halted. /// WSMAN_SIGNAL_SHELL_CODE_CTRL_BREAK /// The signal for CTRL+BREAK was received, and the process was halted. /// /// /// 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 WSManCloseOperation method. /// /// /// Defines the operation handle for the signal operation. This handle is returned from a successful call of the function and can be /// used to asynchronously cancel the signal operation. This handle should be closed by calling the WSManCloseOperation method. This /// parameter cannot be NULL. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/wsman/nf-wsman-wsmansignalshell void WSManSignalShell( WSMAN_SHELL_HANDLE // shell, WSMAN_COMMAND_HANDLE command, DWORD flags, PCWSTR code, WSMAN_SHELL_ASYNC *async, WSMAN_OPERATION_HANDLE *signalOperation ); [DllImport(Lib_WsmSvc, SetLastError = false, ExactSpelling = true)] [PInvokeData("wsman.h", MSDNShortId = "NF:wsman.WSManSignalShell")] public static extern void WSManSignalShell(WSMAN_SHELL_HANDLE shell, [In, Optional] WSMAN_COMMAND_HANDLE command, [Optional] uint flags, [MarshalAs(UnmanagedType.LPWStr)] string code, in WSMAN_SHELL_ASYNC async, out WSMAN_OPERATION_HANDLE signalOperation); /// Provides a handle to a Windows Remote Client unique identifier. [StructLayout(LayoutKind.Sequential)] public struct WSMAN_API_HANDLE : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public WSMAN_API_HANDLE(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static WSMAN_API_HANDLE NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(WSMAN_API_HANDLE h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator WSMAN_API_HANDLE(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(WSMAN_API_HANDLE h1, WSMAN_API_HANDLE h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(WSMAN_API_HANDLE h1, WSMAN_API_HANDLE h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is WSMAN_API_HANDLE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Defines the authentication method and the credentials used for server or proxy authentication. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_authentication_credentials typedef struct // _WSMAN_AUTHENTICATION_CREDENTIALS { DWORD authenticationMechanism; union { WSMAN_USERNAME_PASSWORD_CREDS userAccount; PCWSTR // certificateThumbprint; }; } WSMAN_AUTHENTICATION_CREDENTIALS; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_AUTHENTICATION_CREDENTIALS")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_AUTHENTICATION_CREDENTIALS { /// /// Defines the authentication mechanism. This member can be set to zero. If it is set to zero, the WinRM client will choose /// between Kerberos and Negotiate. If it is not set to zero, this member must be one of the values of the /// WSManAuthenticationFlags enumeration. /// public WSManAuthenticationFlags authenticationMechanism; /// Defines the credentials used for authentication. See WSMAN_USERNAME_PASSWORD_CREDS for more information. public WSMAN_USERNAME_PASSWORD_CREDS userAccount; /// Defines the certificate thumbprint. public string? certificateThumbprint { get => userAccount.username; set => userAccount.username = value; } } /// Reports quota information on a per-user basis for authorization plug-ins. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_authz_quota typedef struct _WSMAN_AUTHZ_QUOTA { DWORD // maxAllowedConcurrentShells; DWORD maxAllowedConcurrentOperations; DWORD timeslotSize; DWORD maxAllowedOperationsPerTimeslot; } WSMAN_AUTHZ_QUOTA; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_AUTHZ_QUOTA")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_AUTHZ_QUOTA { /// Specifies the maximum number of concurrent shells that a user is allowed to create. public uint maxAllowedConcurrentShells; /// /// Specifies the maximum number of concurrent operations that a user is allowed to perform. Only top-level operations are /// counted. Simple operations such as get, put, and delete are counted as one operation each. More complex operations are also /// counted as one. For example, the enumeration operation and any associated operations that are related to enumeration are /// counted as one operation. /// public uint maxAllowedConcurrentOperations; /// /// Time-slot length for determining the maximum number of operations per time slot. This value is specified in units of seconds. /// public uint timeslotSize; /// /// Specifies the maximum number of operations allowed per time slot. This value is used to throttle both top-level and /// follow-on operations. /// public uint maxAllowedOperationsPerTimeslot; } /// /// Stores client information for an inbound request that was sent with a client certificate. The individual fields represent the /// fields within the client certificate. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_certificate_details typedef struct // _WSMAN_CERTIFICATE_DETAILS { PCWSTR subject; PCWSTR issuerName; PCWSTR issuerThumbprint; PCWSTR subjectName; } WSMAN_CERTIFICATE_DETAILS; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_CERTIFICATE_DETAILS")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_CERTIFICATE_DETAILS { /// Specifies the subject that is identified by the certificate. [MarshalAs(UnmanagedType.LPWStr)] public string subject; /// Specifies the name of the issuer of the certificate. [MarshalAs(UnmanagedType.LPWStr)] public string issuerName; /// Specifies the thumbprint of the issuer. [MarshalAs(UnmanagedType.LPWStr)] public string issuerThumbprint; /// Specifies the subject name of the issuer. [MarshalAs(UnmanagedType.LPWStr)] public string subjectName; } /// Represents the set of arguments that are passed in to the command line. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_command_arg_set typedef struct _WSMAN_COMMAND_ARG_SET { // DWORD argsCount; PCWSTR *args; } WSMAN_COMMAND_ARG_SET; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_COMMAND_ARG_SET")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_COMMAND_ARG_SET { /// Specifies the number of arguments in the array. public uint argsCount; /// Defines an array of strings that specify the arguments. public IntPtr args; } /// Provides a handle to a remote management command. [StructLayout(LayoutKind.Sequential)] public struct WSMAN_COMMAND_HANDLE : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public WSMAN_COMMAND_HANDLE(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static WSMAN_COMMAND_HANDLE NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(WSMAN_COMMAND_HANDLE h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator WSMAN_COMMAND_HANDLE(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(WSMAN_COMMAND_HANDLE h1, WSMAN_COMMAND_HANDLE h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(WSMAN_COMMAND_HANDLE h1, WSMAN_COMMAND_HANDLE h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is WSMAN_COMMAND_HANDLE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Contains inbound and outbound data used in the Windows Remote Management (WinRM) API. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_data typedef struct _WSMAN_DATA { WSManDataType type; // union { WSMAN_DATA_TEXT text; WSMAN_DATA_BINARY binaryData; DWORD number; }; } WSMAN_DATA; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_DATA")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_DATA { /// Specifies the type of data currently stored in the union. public WSManDataType type; /// public WSMAN_DATA_UNION union; /// [StructLayout(LayoutKind.Explicit)] public struct WSMAN_DATA_UNION { /// [FieldOffset(0)] public WSMAN_DATA_TEXT text; /// [FieldOffset(0)] public WSMAN_DATA_BINARY binaryData; /// [FieldOffset(0)] public uint number; } } /// A WSMAN_DATA structure component that holds binary data for use with various Windows Remote Management functions. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_data_binary typedef struct _WSMAN_DATA_BINARY { DWORD // dataLength; BYTE *data; } WSMAN_DATA_BINARY; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_DATA_BINARY")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_DATA_BINARY { /// Represents the number of BYTEs stored in the data field. public uint dataLength; /// Specifies the storage location for the binary data. public IntPtr data; } /// A WSMAN_DATA structure component that holds textual data for use with various Windows Remote Management functions. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_data_text typedef struct _WSMAN_DATA_TEXT { DWORD // bufferLength; PCWSTR buffer; } WSMAN_DATA_TEXT; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_DATA_TEXT")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_DATA_TEXT { /// Specifies the number of UNICODE characters stored in the buffer. public uint bufferLength; /// Specifies the storage location for the textual data. public StrPtrUni buffer; } /// /// Defines an individual environment variable by using a name and value pair. This structure is used by the WSManCreateShell /// method. The representation of the value variable is shell specific. The client and server must agree on the format of the /// value variable. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_environment_variable typedef struct // _WSMAN_ENVIRONMENT_VARIABLE { PCWSTR name; PCWSTR value; } WSMAN_ENVIRONMENT_VARIABLE; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_ENVIRONMENT_VARIABLE")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_ENVIRONMENT_VARIABLE { /// Defines the environment variable name. This parameter cannot be NULL. [MarshalAs(UnmanagedType.LPWStr)] public string name; /// Defines the environment variable value. NULL or empty string values are permitted. [MarshalAs(UnmanagedType.LPWStr)] public string? value; } /// Defines an array of environment variables. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_environment_variable_set typedef struct // _WSMAN_ENVIRONMENT_VARIABLE_SET { DWORD varsCount; WSMAN_ENVIRONMENT_VARIABLE *vars; } WSMAN_ENVIRONMENT_VARIABLE_SET; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_ENVIRONMENT_VARIABLE_SET")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_ENVIRONMENT_VARIABLE_SET { /// Specifies the number of environment variables contained within the vars array. public uint varsCount; /// Defines an array of environment variables. Each element of the array is of type WSMAN_ENVIRONMENT_VARIABLE. public IntPtr vars; } /// /// Contains error information that is returned by a Windows Remote Management (WinRM) client. The WSMAN_ERROR structure is used by /// all callbacks to return error information and is valid only for the callback. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_error typedef struct _WSMAN_ERROR { DWORD code; PCWSTR // errorDetail; PCWSTR language; PCWSTR machineName; PCWSTR pluginName; } WSMAN_ERROR; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_ERROR")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_ERROR { /// /// Specifies an error code. This error can be a general error code that is defined in winerror.h or a WinRM-specific error code. /// public uint code; /// /// Specifies extended error information that relates to a failed call. This field contains the fault detail text if it is /// present in the fault. If there is no fault detail, this field contains the fault reason text. This field can be set to NULL. /// [MarshalAs(UnmanagedType.LPWStr)] public string? errorDetail; /// /// Specifies the language for the error description. This field can be set to NULL. For more information about the /// language format, see the RFC 3066 specification from the Internet Engineering Task Force at http://www.ietf.org/rfc/rfc3066.txt. /// [MarshalAs(UnmanagedType.LPWStr)] public string? language; /// Specifies the name of the computer. This field can be set to NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? machineName; /// Specifies the name of the plug-in that generated the error. This field can be set to NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? pluginName; } /// /// [ WSMAN_FILTER is reserved for future use.] /// Defines the filtering that is used for an operation. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_filter typedef struct _WSMAN_FILTER { PCWSTR filter; // PCWSTR dialect; } WSMAN_FILTER; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_FILTER")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_FILTER { /// Reserved for future use. This parameter must be NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? filter; /// Reserved for future use. This parameter must be NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? dialect; } /// /// [ WSMAN_FRAGMENT is reserved for future use.] /// Defines the fragment information for an operation. Currently, this structure is reserved for future use. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_fragment typedef struct _WSMAN_FRAGMENT { PCWSTR path; // PCWSTR dialect; } WSMAN_FRAGMENT; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_FRAGMENT")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_FRAGMENT { /// Reserved for future use. This parameter must be NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? path; /// Reserved for future use. This parameter must be NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? dialect; } /// Represents a key and value pair within a selector set and is used to identify a particular resource. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_key typedef struct _WSMAN_KEY { PCWSTR key; PCWSTR value; // } WSMAN_KEY; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_KEY")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_KEY { /// Specifies the key name. [MarshalAs(UnmanagedType.LPWStr)] public string key; /// Defines the value associated with key. [MarshalAs(UnmanagedType.LPWStr)] public string value; } /// Provides a handle to a remote management operation. [StructLayout(LayoutKind.Sequential)] public struct WSMAN_OPERATION_HANDLE : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public WSMAN_OPERATION_HANDLE(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static WSMAN_OPERATION_HANDLE NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(WSMAN_OPERATION_HANDLE h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator WSMAN_OPERATION_HANDLE(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(WSMAN_OPERATION_HANDLE h1, WSMAN_OPERATION_HANDLE h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(WSMAN_OPERATION_HANDLE h1, WSMAN_OPERATION_HANDLE h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is WSMAN_OPERATION_HANDLE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Represents a specific resource endpoint for which the plug-in must perform the request. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_operation_info typedef struct _WSMAN_OPERATION_INFO { // WSMAN_FRAGMENT fragment; WSMAN_FILTER filter; WSMAN_SELECTOR_SET selectorSet; WSMAN_OPTION_SET optionSet; void *reserved; DWORD // version; } WSMAN_OPERATION_INFO; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_OPERATION_INFO")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_OPERATION_INFO { /// /// A WSMAN_FRAGMENT structure that specifies the subset of data to be used for the operation. This parameter is reserved for /// future use and is ignored on receipt. /// public WSMAN_FRAGMENT fragment; /// /// A WSMAN_FILTER structure that specifies the filtering that is used for the operation. This parameter is reserved for future /// use and is ignored on receipt. /// public WSMAN_FILTER filter; /// A WSMAN_SELECTOR_SET structure that identifies the specific resource to use for the request. public WSMAN_SELECTOR_SET selectorSet; /// A WSMAN_OPTION_SET structure that specifies the set of options for the request. public WSMAN_OPTION_SET optionSet; /// public IntPtr reserved; /// public uint version; } /// /// Represents a specific option name and value pair. An option that is not understood and has a mustComply value of /// TRUE should result in the plug-in operation failing the request with an error. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_option typedef struct _WSMAN_OPTION { PCWSTR name; PCWSTR // value; BOOL mustComply; } WSMAN_OPTION; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_OPTION")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_OPTION { /// Specifies the name of the option. [MarshalAs(UnmanagedType.LPWStr)] public string name; /// Specifies the value of the option. [MarshalAs(UnmanagedType.LPWStr)] public string value; /// /// Specifies whether the option must be understood and complied with. If this value is TRUE, the plug-in must understand /// and adhere to the meaning of the option; otherwise, the plug-in must return an error. If this is FALSE, the plug-in /// should ignore the option if it is not understood. /// [MarshalAs(UnmanagedType.Bool)] public bool mustComply; } /// /// Represents a set of options. Additionally, this structure defines a flag that specifies whether all options must be understood. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_option_set typedef struct _WSMAN_OPTION_SET { DWORD // optionsCount; WSMAN_OPTION *options; BOOL optionsMustUnderstand; } WSMAN_OPTION_SET; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_OPTION_SET")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_OPTION_SET { /// Specifies the number of options in the options array. public uint optionsCount; /// Specifies an array of option names and values public IntPtr options; /// If this member is TRUE, the plug-in must return an error if any of the options are not understood. [MarshalAs(UnmanagedType.Bool)] public bool optionsMustUnderstand; } /// /// Specifies information for a plug-in request. A pointer to a WSMAN_PLUGIN_REQUEST structure is passed to all operation /// entry points within the plug-in. All result notification methods use this pointer to match the result with the request. All /// information in the structure will stay valid until the plug-in calls WSManPluginOperationCompleteon the operation. /// /// /// Operations must signal the callback for the operation to indicate it has been shut down. Operations are canceled in a /// hierarchical way to ensure that all follow-on operations are canceled before the top-level operations. A plug-in has two ways of /// handling the cancellation of an operation. First, the plug-in can check the shutdownNotification Boolean value if it /// iterates through a set of results. Second, if the plug-in is more asynchronous in nature, the shutdownNotificationHandle /// can be used when queuing asynchronous notification threads. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_plugin_request typedef struct _WSMAN_PLUGIN_REQUEST { // WSMAN_SENDER_DETAILS *senderDetails; PCWSTR locale; PCWSTR resourceUri; WSMAN_OPERATION_INFO *operationInfo; BOOL // shutdownNotification; HANDLE shutdownNotificationHandle; PCWSTR dataLocale; } WSMAN_PLUGIN_REQUEST; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_PLUGIN_REQUEST")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_PLUGIN_REQUEST { /// /// A pointer to a structure that specifies details about the client that initiated the request. /// public IntPtr senderDetails; /// /// /// Specifies the locale that the user requested results to be in. If the requested locale is not available, the following /// options are available: /// /// /// /// The system locale is used. /// /// /// The request is rejected with an invalid locale error. /// /// /// /// Any call into the plug-in will have the locale on the thread set to the locale that is specified in this member. If the /// plug-in has other threads working on the request, the plug-in will need to set the locale accordingly on each thread that it uses. /// /// [MarshalAs(UnmanagedType.LPWStr)] public string locale; /// Specifies the resource URI for this operation. [MarshalAs(UnmanagedType.LPWStr)] public string resourceUri; /// /// A pointer to a structure that contains extra information about the operation. Some of the /// information in this structure will be NULL because not all of the parameters are relevant to all operations. /// public IntPtr operationInfo; /// If the operation is canceled, the shutdownNotification member is set to TRUE. [MarshalAs(UnmanagedType.Bool)] public bool shutdownNotification; /// If the operation is canceled, shutdownNotification is signaled. public HEVENT shutdownNotificationHandle; /// [MarshalAs(UnmanagedType.LPWStr)] public string dataLocale; } /// Specifies proxy information. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_proxy_info typedef struct _WSMAN_PROXY_INFO { DWORD // accessType; WSMAN_AUTHENTICATION_CREDENTIALS authenticationCredentials; } WSMAN_PROXY_INFO; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_PROXY_INFO")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_PROXY_INFO { /// /// Specifies the access type for the proxy. This member must be set to one of the values defined in the WSManProxyAccessType enumeration. /// public WSManProxyAccessType accessType; /// /// A WSMAN_AUTHENTICATION_CREDENTIALS structure that specifies the credentials and authentication scheme used for proxy access. /// public WSMAN_AUTHENTICATION_CREDENTIALS authenticationCredentials; } /// Represents the output data received from a WSManReceiveShellOutput method. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_receive_data_result typedef struct // _WSMAN_RECEIVE_DATA_RESULT { PCWSTR streamId; WSMAN_DATA streamData; PCWSTR commandState; DWORD exitCode; } WSMAN_RECEIVE_DATA_RESULT; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_RECEIVE_DATA_RESULT")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_RECEIVE_DATA_RESULT { /// Represents the streamId for which streamData is defined. public StrPtrUni streamId; /// /// Represents the data associated with streamId. The data can be stream text, binary content, or XML. For more /// information about the possible data, see WSMAN_DATA. /// public WSMAN_DATA streamData; /// /// Specifies the status of the command. If this member is set to WSMAN_COMMAND_STATE_DONE, the command should be /// immediately closed. /// public StrPtrUni commandState; /// /// Defines the exit code of the command. This value is relevant only if the commandState member is set to WSMAN_COMMAND_STATE_DONE. /// public uint exitCode; } /// Represents the output data received from a WSMan operation. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_response_data typedef union _WSMAN_RESPONSE_DATA { // WSMAN_RECEIVE_DATA_RESULT receiveData; WSMAN_CONNECT_DATA connectData; WSMAN_CREATE_SHELL_DATA createData; } WSMAN_RESPONSE_DATA; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_RESPONSE_DATA")] [StructLayout(LayoutKind.Explicit)] public struct WSMAN_RESPONSE_DATA { /// Represents the output data received from a WSManReceiveShellOutput method. [FieldOffset(0)] public WSMAN_RECEIVE_DATA_RESULT receiveData; /// Represents the output data received from a WSManConnectShell or WSManConnectShellCommand method. [FieldOffset(0)] public WSMAN_DATA connectData; /// [FieldOffset(0)] public WSMAN_DATA createData; } /// Defines a set of keys that represent the identity of a resource. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_selector_set typedef struct _WSMAN_SELECTOR_SET { DWORD // numberKeys; WSMAN_KEY *keys; } WSMAN_SELECTOR_SET; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_SELECTOR_SET")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_SELECTOR_SET { /// Specifies the number of keys (selectors). public uint numberKeys; /// An array of WSMAN_KEY structures that specify key names and values. public IntPtr keys; } /// Specifies the client details for every inbound request. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_sender_details typedef struct _WSMAN_SENDER_DETAILS { // PCWSTR senderName; PCWSTR authenticationMechanism; WSMAN_CERTIFICATE_DETAILS *certificateDetails; HANDLE clientToken; PCWSTR // httpURL; } WSMAN_SENDER_DETAILS; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_SENDER_DETAILS")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_SENDER_DETAILS { /// /// /// Specifies the user name of the client making the request. The content of this parameter varies depending on the type of /// authentication. The value of the senderName is formatted as follows: /// /// /// /// Authentication mechanism /// Value of senderName /// /// /// Windows Authentication /// The domain and user name. /// /// /// Basic Authentication /// The user name specified. /// /// /// Client Certificates /// The subject of the certificate. /// /// /// LiveID /// The LiveID PUID as a string. /// /// /// [MarshalAs(UnmanagedType.LPWStr)] public string senderName; /// /// /// Specifies a string that indicates which authentication mechanism was used by the client. The following values are predefined: /// /// /// /// Basic /// /// /// ClientCertificate /// /// /// /// All other types are queried directly from the security package. For Internet Information Services (IIS) hosting, this string /// is retrieved from the IIS infrastructure. /// /// [MarshalAs(UnmanagedType.LPWStr)] public string authenticationMechanism; /// /// A pointer to a structure that specifies the details of the client's certificate. /// This parameter is valid only if the authenticationMechanismis set to ClientCertificate. /// public IntPtr certificateDetails; /// /// /// Specifies the identity token of the user if a Windows security token is available for a user. This token will be used by the /// thread to impersonate this user for all calls into the plug-in. /// /// Note Authorization plug-ins can change the user context and use a different impersonation token. /// public HTOKEN clientToken; /// Specifies the HTTP URL of the inbound request. [MarshalAs(UnmanagedType.LPWStr)] public string httpURL; } /// Provides a handle to a remote managment session. [StructLayout(LayoutKind.Sequential)] public struct WSMAN_SESSION_HANDLE : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public WSMAN_SESSION_HANDLE(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static WSMAN_SESSION_HANDLE NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(WSMAN_SESSION_HANDLE h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator WSMAN_SESSION_HANDLE(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(WSMAN_SESSION_HANDLE h1, WSMAN_SESSION_HANDLE h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(WSMAN_SESSION_HANDLE h1, WSMAN_SESSION_HANDLE h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is WSMAN_SESSION_HANDLE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// /// Defines an asynchronous structure to be passed to all shell operations. It contains an optional user context and the callback function. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_shell_async typedef struct _WSMAN_SHELL_ASYNC { PVOID // operationContext; WSMAN_SHELL_COMPLETION_FUNCTION completionFunction; } WSMAN_SHELL_ASYNC; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_SHELL_ASYNC")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_SHELL_ASYNC { /// Specifies the optional user context associated with the operation. public IntPtr operationContext; /// Specifies the WSMAN_SHELL_COMPLETION_FUNCTION callback function for the operation. public WSMAN_SHELL_COMPLETION_FUNCTION completionFunction; } /// Specifies the maximum duration, in milliseconds, the shell will stay open after the client has disconnected. /// /// When the maximum duration is exceeded, the shell is automatically deleted. This value overrides the initial idle timeout that is /// set as part of WSMAN_SHELL_STARTUP_INFO structure in WSManCreateShell. /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_shell_disconnect_info typedef struct // _WSMAN_SHELL_DISCONNECT_INFO { DWORD idleTimeoutMs; } WSMAN_SHELL_DISCONNECT_INFO; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_SHELL_DISCONNECT_INFO")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_SHELL_DISCONNECT_INFO { /// /// Specifies the maximum time in milliseconds that the shell will stay open after the client has disconnected. When this /// maximum duration has been exceeded, the shell will be deleted. Specifying this value overrides the initial idle timeout /// value that is set as part of the WSMAN_SHELL_STARTUP_INFO structure in the WSManCreateShell method. /// public uint idleTimeoutMs; } /// Provides a handle to a remote management shell. [StructLayout(LayoutKind.Sequential)] public struct WSMAN_SHELL_HANDLE : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public WSMAN_SHELL_HANDLE(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static WSMAN_SHELL_HANDLE NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(WSMAN_SHELL_HANDLE h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator WSMAN_SHELL_HANDLE(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(WSMAN_SHELL_HANDLE h1, WSMAN_SHELL_HANDLE h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(WSMAN_SHELL_HANDLE h1, WSMAN_SHELL_HANDLE h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is WSMAN_SHELL_HANDLE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// /// /// Defines the shell startup parameters to be used with the WSManCreateShell function. The structure must be allocated by the /// client and passed to the WSManCreateShell function. /// /// /// The configuration passed to the WSManCreateShell function can directly affect the behavior of a command executed within the /// shell. A typical example is the workingDirectory argument that describes the working directory associated with each process, /// which the operating system uses when attempting to locate files specified by using a relative path. /// /// /// In the absence of specific requirements for stream naming, clients and services should attempt to use STDIN for input /// streams, STDOUT for the default output stream, and STDERR for the error or status output stream. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_shell_startup_info_v11 typedef struct // _WSMAN_SHELL_STARTUP_INFO_V11 : _WSMAN_SHELL_STARTUP_INFO_V10 { PCWSTR name; } WSMAN_SHELL_STARTUP_INFO_V11; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_SHELL_STARTUP_INFO_V11")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_SHELL_STARTUP_INFO { /// /// A pointer to a WSMAN_STREAM_ID_SET structure that specifies a set of input streams for the shell. Streams not present in the /// filter can be ignored by the shell implementation. For the Windows Cmd.exe shell, this value should be L"stdin". If the /// value is NULL, the implementation uses an array with L"stdin" as the default value. /// public IntPtr inputStreamSet; /// /// A pointer to a WSMAN_STREAM_ID_SET structure that specifies a set of output streams for the shell. Streams not present in /// the filter can be ignored by the shell implementation. For the Windows cmd.exe shell, this value should be L"stdout stderr". /// If the value is NULL, the implementation uses an array with L"stdout" and L"stderr" as the default value. /// public IntPtr outputStreamSet; /// /// Specifies the maximum duration, in milliseconds, the shell will stay open without any client request. When the maximum /// duration is exceeded, the shell is automatically deleted. Any value from 0 to 0xFFFFFFFF can be set. This duration has a /// maximum value specified by the Idle time-out GPO setting, if enabled, or by the IdleTimeout local configuration. The default /// value of the maximum duration in the GPO/local configuration is 15 minutes. However, a system administrator can change this /// value. To use the maximum value from the GPO/local configuration, the client should specify 0 (zero) in this field. If an /// explicit value between 0 to 0xFFFFFFFF is used, the minimum value between the explicit API value and the value from the /// GPO/local configuration is used. /// public uint idleTimeoutMs; /// /// Specifies the starting directory for a shell. It is used with any execution command. If this member is a NULL value, /// a default directory will be used by the remote machine when executing the command. An empty value is treated by the /// underlying protocol as an omitted value. /// [MarshalAs(UnmanagedType.LPWStr)] public string? workingDirectory; /// /// A pointer to a WSMAN_ENVIRONMENT_VARIABLE_SET structure that specifies an array of variable name and value pairs, which /// describe the starting environment for the shell. The content of these elements is shell specific and can be defined in terms /// of other environment variables. If a NULL value is passed, the default environment is used on the server side. /// public IntPtr variableSet; /// /// Specifies an optional friendly name to be associated with the shell. This parameter is only functional when the client /// passes the flag WSMAN_FLAG_REQUESTED_API_VERSION_1_1 to WSManInitialize. /// [MarshalAs(UnmanagedType.LPWStr)] public string? name; } /// Lists all the streams that are used for either input or output for the shell and commands. // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_stream_id_set typedef struct _WSMAN_STREAM_ID_SET { DWORD // streamIDsCount; PCWSTR *streamIDs; } WSMAN_STREAM_ID_SET; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_STREAM_ID_SET")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_STREAM_ID_SET { /// Defines the number of stream IDs in streamIDs. public uint streamIDsCount; /// Specifies an array of stream IDs. public IntPtr streamIDs; } /// Defines the credentials used for authentication. /// /// /// The client can specify the credentials to use when creating a shell on a computer. The user name should be specified in the form /// DOMAIN\username for a domain account or SERVERNAME\username for a local account on a server computer. /// /// /// If this structure is used, it should have both the user name and password fields specified. It can be used with Basic, Digest, /// Negotiate, or Kerberos authentication. The client must explicitly specify the credentials when either Basic or Digest /// authentication is used. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wsman/ns-wsman-wsman_username_password_creds typedef struct // _WSMAN_USERNAME_PASSWORD_CREDS { PCWSTR username; PCWSTR password; } WSMAN_USERNAME_PASSWORD_CREDS; [PInvokeData("wsman.h", MSDNShortId = "NS:wsman._WSMAN_USERNAME_PASSWORD_CREDS")] [StructLayout(LayoutKind.Sequential)] public struct WSMAN_USERNAME_PASSWORD_CREDS { /// Defines the user name for a local or domain account. It cannot be NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? username; /// Defines the password for a local or domain account. It cannot be NULL. [MarshalAs(UnmanagedType.LPWStr)] public string? password; } /// Provides a for that is disposed using . public class SafeWSMAN_API_HANDLE : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeWSMAN_API_HANDLE(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeWSMAN_API_HANDLE() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator WSMAN_API_HANDLE(SafeWSMAN_API_HANDLE h) => h.handle; /// protected override bool InternalReleaseHandle() => WSManDeinitialize(handle).Succeeded; } /// Provides a for that is disposed using . public class SafeWSMAN_OPERATION_HANDLE : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeWSMAN_OPERATION_HANDLE(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeWSMAN_OPERATION_HANDLE() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator WSMAN_OPERATION_HANDLE(SafeWSMAN_OPERATION_HANDLE h) => h.handle; /// protected override bool InternalReleaseHandle() => WSManCloseOperation(handle).Succeeded; } /// /// Provides a for that is disposed using . /// public class SafeWSMAN_SESSION_HANDLE : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeWSMAN_SESSION_HANDLE(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeWSMAN_SESSION_HANDLE() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator WSMAN_SESSION_HANDLE(SafeWSMAN_SESSION_HANDLE h) => h.handle; /// protected override bool InternalReleaseHandle() => WSManCloseSession(handle).Succeeded; } /// Provides a for that is disposed using . public class SafeWSMAN_SHELL_HANDLE : SafeHANDLE { private WSMAN_SHELL_ASYNC async; /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// The asynchronous information used in the WSManCreateShell method. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeWSMAN_SHELL_HANDLE(IntPtr preexistingHandle, in WSMAN_SHELL_ASYNC async, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) => this.async = async; /// Initializes a new instance of the class. private SafeWSMAN_SHELL_HANDLE() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator WSMAN_SHELL_HANDLE(SafeWSMAN_SHELL_HANDLE h) => h.handle; /// protected override bool InternalReleaseHandle() { if (async.completionFunction is null) return false; WSManCloseShell(handle, 0, async); return true; } } }