using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class Shell32 { /// Represents the state of a Windows app package. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-package_execution_state typedef enum // PACKAGE_EXECUTION_STATE { PES_UNKNOWN, PES_RUNNING, PES_SUSPENDING, PES_SUSPENDED, PES_TERMINATED } ; [PInvokeData("shobjidl_core.h", MSDNShortId = "NE:shobjidl_core.PACKAGE_EXECUTION_STATE")] public enum PACKAGE_EXECUTION_STATE { /// The package is in an unknown state. PES_UNKNOWN, /// The package is running. PES_RUNNING, /// The package is being suspended. PES_SUSPENDING, /// The package is suspended. PES_SUSPENDED, /// The package was terminated. PES_TERMINATED, } /// Enables debugger developers to control the life cycle of a Windows Store app, such as suspending or resuming. /// /// Any debug options set remain in effect until they are cleared or this interface is released. /// /// For debug settings to take effect on Internet Explorer in the new Windows UI, use "DefaultBrowser_NOPUBLISHERID" as the /// packageFullName parameter for IPackageDebugSettings methods. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ipackagedebugsettings [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IPackageDebugSettings")] [ComImport, Guid("F27C3930-8029-4AD1-94E3-3DBA417810C1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(PackageDebugSettings))] public interface IPackageDebugSettings { /// Enables debug mode for the processes of the specified package. /// The package full name. /// The command line to use to launch processes from this package. This parameter is optional. /// Any environment strings to pass to processes. This parameter is optional. /// /// Enabling debug mode has the following effects: /// /// /// Optionally enables debugger attach on activation. /// /// /// Disables activation timeouts. /// /// /// Disables automatic process suspension. /// /// /// Disables automatic process termination. /// /// /// Disables automatic process resumption. /// /// /// To restore normal operation, call the DisableDebugging method. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-enabledebugging // HRESULT EnableDebugging( LPCWSTR packageFullName, LPCWSTR debuggerCommandLine, PZZWSTR environment ); void EnableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string debuggerCommandLine, [In, Optional] IntPtr environment); /// Disables debug mode for the processes of the specified package. /// The package full name. /// This method has no effect if the EnableDebugging method was not previously called for this package. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-disabledebugging // HRESULT DisableDebugging( LPCWSTR packageFullName ); void DisableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Suspends the processes of the package if they are currently running. /// /// Type: LPCWSTR /// The package full name. /// /// /// Each process receives the Suspending event. It can be useful for developers to step through how their apps respond to /// this event. /// // https://docs.microsoft.com/en-us/windows/win32/winrt/ipackagedebugsettings-suspend HRESULT Suspend( [in] LPCWSTR // packageFullName ); void Suspend([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Resumes the processes of the package if they are currently suspended. /// The package full name. /// /// Each process receives the Resuming event, which is useful for stepping through your apps as they respond to this event. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-resume HRESULT // Resume( LPCWSTR packageFullName ); void Resume([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Terminates all processes for the specified package. /// The package full name. /// /// This method does not suspend the processes first. To test suspension followed by termination, call the Suspend method before /// calling TerminateAllProcesses. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-terminateallprocesses // HRESULT TerminateAllProcesses( LPCWSTR packageFullName ); void TerminateAllProcesses([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Sets the session identifier. /// The session identifier. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-settargetsessionid // HRESULT SetTargetSessionId( ULONG sessionId ); void SetTargetSessionId(uint sessionId); /// Gets the background tasks that are provided by the specified package. /// The package full name to query for background tasks. /// The count of taskIds and taskNames entries. /// /// An array of background task identifiers. You can use these identifiers in the ActivateBackgroundTask method to activate /// specified tasks. /// /// An array of task names that corresponds with background taskIds. /// /// Both parameters taskIds and taskNames have the same ordering of tasks. If you need to know the user-readable task name /// associated with taskId[0], refer to taskNames[0]. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-enumeratebackgroundtasks // HRESULT EnumerateBackgroundTasks( LPCWSTR packageFullName, ULONG *taskCount, LPCGUID *taskIds, LPCWSTR **taskNames ); void EnumerateBackgroundTasks([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, out uint taskCount, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] out Guid[] taskIds, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] out string[] taskNames); /// Activates the specified background task. /// The identifier of the background task to activate. /// Use the ActivateBackgroundTask method to test the code that handles your background tasks. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-activatebackgroundtask // HRESULT ActivateBackgroundTask( LPCGUID taskId ); void ActivateBackgroundTask(in Guid taskId); /// /// Suspends and terminates the non-background portion of the apps associated with the specified package and cancels the /// background tasks associated with the package. /// /// The package full name. /// /// Use the StartServicing method to simulate what happens when a package is updated to a newer version. New background /// task activations are buffered (delayed) until you call the StopServicing method. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-startservicing // HRESULT StartServicing( LPCWSTR packageFullName ); void StartServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Completes the previous servicing operation that was started by a call to the StartServicing method. /// The package full name. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-stopservicing HRESULT // StopServicing( LPCWSTR packageFullName ); void StopServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Causes background tasks for the specified package to activate in the specified user session. /// The package full name. /// The identifier of the session which background tasks are redirected to. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-startsessionredirection // HRESULT StartSessionRedirection( LPCWSTR packageFullName, ULONG sessionId ); void StartSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, uint sessionId); /// Stops redirection of background tasks for the specified package. /// The package full name. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-stopsessionredirection // HRESULT StopSessionRedirection( LPCWSTR packageFullName ); void StopSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Gets the state of the package execution. /// Full name of the package. /// State of the package execution. PACKAGE_EXECUTION_STATE GetPackageExecutionState([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Register for package state-change notifications. /// The package full name. /// /// Package state-change notifications are delivered by the OnStateChanged function on pPackageExecutionStateChangeNotification. /// /// /// A unique registration identifier for the current listener. Use this identifier to unregister for package state-change /// notifications by using the UnregisterForPackageStateChanges method. /// /// Notifications are raised when the package enters the running, suspending, and suspended states. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-registerforpackagestatechanges // HRESULT RegisterForPackageStateChanges( LPCWSTR packageFullName, IPackageExecutionStateChangeNotification // *pPackageExecutionStateChangeNotification, DWORD *pdwCookie ); void RegisterForPackageStateChanges([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, IPackageExecutionStateChangeNotification pPackageExecutionStateChangeNotification, out uint pdwCookie); /// Stops receiving package state-change notifications associated with a previous call to RegisterForPackageStateChanges. /// /// The notification to cancel. This identifier is returned by a previous call to the RegisterForPackageStateChanges method. /// /// /// Call the UnregisterForPackageStateChanges to stop receiving package state-change notifications associated with a /// previous call to the RegisterForPackageStateChanges method. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-unregisterforpackagestatechanges // HRESULT UnregisterForPackageStateChanges( DWORD dwCookie ); void UnregisterForPackageStateChanges(uint dwCookie); } /// Undocumented. /// [PInvokeData("shobjidl_core.h")] [ComImport, Guid("6E3194BB-AB82-4D22-93F5-FABDA40E7B16"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IPackageDebugSettings2 : IPackageDebugSettings { /// Enables debug mode for the processes of the specified package. /// The package full name. /// The command line to use to launch processes from this package. This parameter is optional. /// Any environment strings to pass to processes. This parameter is optional. /// /// Enabling debug mode has the following effects: /// /// /// Optionally enables debugger attach on activation. /// /// /// Disables activation timeouts. /// /// /// Disables automatic process suspension. /// /// /// Disables automatic process termination. /// /// /// Disables automatic process resumption. /// /// /// To restore normal operation, call the DisableDebugging method. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-enabledebugging // HRESULT EnableDebugging( LPCWSTR packageFullName, LPCWSTR debuggerCommandLine, PZZWSTR environment ); new void EnableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string debuggerCommandLine, [In, Optional] IntPtr environment); /// Disables debug mode for the processes of the specified package. /// The package full name. /// This method has no effect if the EnableDebugging method was not previously called for this package. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-disabledebugging // HRESULT DisableDebugging( LPCWSTR packageFullName ); new void DisableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Suspends the processes of the package if they are currently running. /// /// Type: LPCWSTR /// The package full name. /// /// /// Each process receives the Suspending event. It can be useful for developers to step through how their apps respond to /// this event. /// // https://docs.microsoft.com/en-us/windows/win32/winrt/ipackagedebugsettings-suspend HRESULT Suspend( [in] LPCWSTR // packageFullName ); new void Suspend([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Resumes the processes of the package if they are currently suspended. /// The package full name. /// /// Each process receives the Resuming event, which is useful for stepping through your apps as they respond to this event. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-resume HRESULT // Resume( LPCWSTR packageFullName ); new void Resume([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Terminates all processes for the specified package. /// The package full name. /// /// This method does not suspend the processes first. To test suspension followed by termination, call the Suspend method before /// calling TerminateAllProcesses. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-terminateallprocesses // HRESULT TerminateAllProcesses( LPCWSTR packageFullName ); new void TerminateAllProcesses([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Sets the session identifier. /// The session identifier. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-settargetsessionid // HRESULT SetTargetSessionId( ULONG sessionId ); new void SetTargetSessionId(uint sessionId); /// Gets the background tasks that are provided by the specified package. /// The package full name to query for background tasks. /// The count of taskIds and taskNames entries. /// /// An array of background task identifiers. You can use these identifiers in the ActivateBackgroundTask method to activate /// specified tasks. /// /// An array of task names that corresponds with background taskIds. /// /// Both parameters taskIds and taskNames have the same ordering of tasks. If you need to know the user-readable task name /// associated with taskId[0], refer to taskNames[0]. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-enumeratebackgroundtasks // HRESULT EnumerateBackgroundTasks( LPCWSTR packageFullName, ULONG *taskCount, LPCGUID *taskIds, LPCWSTR **taskNames ); new void EnumerateBackgroundTasks([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, out uint taskCount, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] out Guid[] taskIds, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] out string[] taskNames); /// Activates the specified background task. /// The identifier of the background task to activate. /// Use the ActivateBackgroundTask method to test the code that handles your background tasks. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-activatebackgroundtask // HRESULT ActivateBackgroundTask( LPCGUID taskId ); new void ActivateBackgroundTask(in Guid taskId); /// /// Suspends and terminates the non-background portion of the apps associated with the specified package and cancels the /// background tasks associated with the package. /// /// The package full name. /// /// Use the StartServicing method to simulate what happens when a package is updated to a newer version. New background /// task activations are buffered (delayed) until you call the StopServicing method. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-startservicing // HRESULT StartServicing( LPCWSTR packageFullName ); new void StartServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Completes the previous servicing operation that was started by a call to the StartServicing method. /// The package full name. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-stopservicing HRESULT // StopServicing( LPCWSTR packageFullName ); new void StopServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Causes background tasks for the specified package to activate in the specified user session. /// The package full name. /// The identifier of the session which background tasks are redirected to. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-startsessionredirection // HRESULT StartSessionRedirection( LPCWSTR packageFullName, ULONG sessionId ); new void StartSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, uint sessionId); /// Stops redirection of background tasks for the specified package. /// The package full name. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-stopsessionredirection // HRESULT StopSessionRedirection( LPCWSTR packageFullName ); new void StopSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Gets the state of the package execution. /// Full name of the package. /// State of the package execution. new PACKAGE_EXECUTION_STATE GetPackageExecutionState([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); /// Register for package state-change notifications. /// The package full name. /// /// Package state-change notifications are delivered by the OnStateChanged function on pPackageExecutionStateChangeNotification. /// /// /// A unique registration identifier for the current listener. Use this identifier to unregister for package state-change /// notifications by using the UnregisterForPackageStateChanges method. /// /// Notifications are raised when the package enters the running, suspending, and suspended states. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-registerforpackagestatechanges // HRESULT RegisterForPackageStateChanges( LPCWSTR packageFullName, IPackageExecutionStateChangeNotification // *pPackageExecutionStateChangeNotification, DWORD *pdwCookie ); new void RegisterForPackageStateChanges([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, IPackageExecutionStateChangeNotification pPackageExecutionStateChangeNotification, out uint pdwCookie); /// Stops receiving package state-change notifications associated with a previous call to RegisterForPackageStateChanges. /// /// The notification to cancel. This identifier is returned by a previous call to the RegisterForPackageStateChanges method. /// /// /// Call the UnregisterForPackageStateChanges to stop receiving package state-change notifications associated with a /// previous call to the RegisterForPackageStateChanges method. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-unregisterforpackagestatechanges // HRESULT UnregisterForPackageStateChanges( DWORD dwCookie ); new void UnregisterForPackageStateChanges(uint dwCookie); /// Enumerates the apps. /// The package full name to query for apps. /// The count of and entries. /// The application user model ids. /// The application display names. void EnumerateApps([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, out uint appCount, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] out string[] appUserModelIds, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] out string[] appDisplayNames); } /// Enables receiving package state-change notifications during Windows Store app debugging. /// /// /// Implement the IPackageExecutionStateChangeNotification interface when you need to receive package state-change /// notifications during Windows Store app debugging. /// /// Call the method to register for package state-change notifications. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ipackageexecutionstatechangenotification [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IPackageExecutionStateChangeNotification")] [ComImport, Guid("1BB12A62-2AD8-432B-8CCF-0C2C52AFCD5B"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IPackageExecutionStateChangeNotification { /// Called when package state changes during Windows Store app debugging. /// The package full name. /// The new state that the package changed to. /// Return S_OK when you implement the OnStateChanged method. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackageexecutionstatechangenotification-onstatechanged // HRESULT OnStateChanged( LPCWSTR pszPackageFullName, PACKAGE_EXECUTION_STATE pesNewState ); [PreserveSig] HRESULT OnStateChanged([MarshalAs(UnmanagedType.LPWStr)] string pszPackageFullName, PACKAGE_EXECUTION_STATE pesNewState); } /// CoClass for IPackageDebugSettings [PInvokeData("shobjidl.h")] [ComImport, Guid("B1AEC16F-2383-4852-B0E9-8F0B1DC66B4D"), ClassInterface(ClassInterfaceType.None)] public class PackageDebugSettings { } } }