diff --git a/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj b/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj index 8424f732..1131119a 100644 --- a/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj +++ b/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj @@ -13,6 +13,6 @@ - + \ No newline at end of file diff --git a/src/Skylark.Wing/Helper/EventSubscriptionManager.cs b/src/Skylark.Wing/Helper/EventSubscriptionManager.cs new file mode 100644 index 00000000..8295cc5b --- /dev/null +++ b/src/Skylark.Wing/Helper/EventSubscriptionManager.cs @@ -0,0 +1,149 @@ +using System; +using System.Runtime.InteropServices; +using DISPPARAMS = System.Runtime.InteropServices.ComTypes.DISPPARAMS; +using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; +using SWIIEL = Skylark.Wing.Interface.IEventListener; +using SWIIESM = Skylark.Wing.Interface.IEventSystem; +using SWIIESN = Skylark.Wing.Interface.IEventSubscription; +using SWNM = Skylark.Wing.Native.Methods; + +namespace Skylark.Wing.Helper +{ + /// + /// EventSubscriptionManager Class - Handles event subscription logic + /// + public class EventSubscriptionManager + { + private readonly SWIIEL _eventListener; + private SWIIESM _eventSystem; + + public EventSubscriptionManager(SWIIEL eventListener) + { + _eventListener = eventListener; + } + + public SWNM.HRESULT Initialize() + { + SWNM.HRESULT hr = SWNM.HRESULT.E_FAIL; + + Guid CLSID_CEventSubscription = new("7542e960-79c7-11d1-88f9-0080c7d771bf"); + + Type eventSubscriptionType = Type.GetTypeFromCLSID(CLSID_CEventSubscription, true); + + object eventSubscription = Activator.CreateInstance(eventSubscriptionType); + + SWIIESN pEventSubscription = (SWIIESN)eventSubscription; + + if (pEventSubscription != null) + { + hr = pEventSubscription.put_EventClassID("{D5978630-5B9F-11D1-8DD2-00AA004ABD5E}"); + + if (hr == SWNM.HRESULT.S_OK) + { + hr = pEventSubscription.put_SubscriptionName("SkylarkEventSubscriptionManager"); + + if (hr == SWNM.HRESULT.S_OK) + { + hr = pEventSubscription.put_PerUser(true); + + if (hr == SWNM.HRESULT.S_OK) + { + IntPtr pSubscriberInterface = Marshal.GetIUnknownForObject(this); + + hr = pEventSubscription.put_SubscriberInterface(pSubscriberInterface); + + Guid CLSID_CEventSystem = new("4E14FBA2-2E22-11D1-9964-00C04FBBB345"); + + Type eventSystemType = Type.GetTypeFromCLSID(CLSID_CEventSystem, true); + + object eventSystem = Activator.CreateInstance(eventSystemType); + + _eventSystem = (SWIIESM)eventSystem; + + IntPtr pInterface = Marshal.GetIUnknownForObject(pEventSubscription); + + hr = _eventSystem.Store("EventSystem.EventSubscription", pInterface); + } + } + } + + Marshal.ReleaseComObject(pEventSubscription); + } + + return hr; + } + + public SWNM.HRESULT Uninitialize() + { + SWNM.HRESULT hr = SWNM.HRESULT.E_FAIL; + + if (_eventSystem != null) + { + // System.UnauthorizedAccessException + // HResult = 0x80070005 + // Message = Accès refusé. (Exception de HRESULT: 0x80070005(E_ACCESSDENIED)) + + hr = _eventSystem.Remove("EventSystem.EventSubscription", "EventClassID={D5978630-5B9F-11D1-8DD2-00AA004ABD5E}", out int errorIndex); + + Marshal.ReleaseComObject(_eventSystem); + } + + return hr; + } + + public int GetTypeInfoCount() + { + throw new NotImplementedException(); + } + + public IntPtr GetTypeInfo(int iTInfo, int lcid) + { + throw new NotImplementedException(); + } + + public SWNM.HRESULT GetIDsOfNames(ref Guid riid, string[] rgszNames, int cNames, int lcid, int[] rgDispId) + { + throw new NotImplementedException(); + } + + public SWNM.HRESULT Invoke(int dispIdMember, ref Guid riid, int lcid, int dwFlags, DISPPARAMS pDispParams, out object pVarResult, EXCEPINFO pExcepInfo, IntPtr[] pArgErr) + { + throw new NotImplementedException(); + } + + public SWNM.HRESULT Logon(string userName) + { + return _eventListener.OnLogon(userName); + } + + public SWNM.HRESULT Logoff(string userName) + { + return _eventListener.OnLogoff(userName); + } + + public SWNM.HRESULT StartShell(string userName) + { + return _eventListener.OnStartShell(userName); + } + + public SWNM.HRESULT DisplayLock(string userName) + { + return _eventListener.OnDisplayLock(userName); + } + + public SWNM.HRESULT DisplayUnlock(string userName) + { + return _eventListener.OnDisplayUnlock(userName); + } + + public SWNM.HRESULT StartScreenSaver(string userName) + { + return _eventListener.OnStartScreenSaver(userName); + } + + public SWNM.HRESULT StopScreenSaver(string userName) + { + return _eventListener.OnStopScreenSaver(userName); + } + } +} \ No newline at end of file diff --git a/src/Skylark.Wing/Interface/IEventListener.cs b/src/Skylark.Wing/Interface/IEventListener.cs new file mode 100644 index 00000000..4453d416 --- /dev/null +++ b/src/Skylark.Wing/Interface/IEventListener.cs @@ -0,0 +1,59 @@ +using SWNM = Skylark.Wing.Native.Methods; + +namespace Skylark.Wing.Interface +{ + /// + /// + /// + public interface IEventListener + { + /// + /// + /// + /// + /// + SWNM.HRESULT OnLogon(string userName); + + /// + /// + /// + /// + /// + SWNM.HRESULT OnLogoff(string userName); + + /// + /// + /// + /// + /// + SWNM.HRESULT OnStartShell(string userName); + + /// + /// + /// + /// + /// + SWNM.HRESULT OnDisplayLock(string userName); + + /// + /// + /// + /// + /// + SWNM.HRESULT OnDisplayUnlock(string userName); + + /// + /// + /// + /// + /// + SWNM.HRESULT OnStartScreenSaver(string userName); + + /// + /// + /// + /// + /// + SWNM.HRESULT OnStopScreenSaver(string userName); + } +} \ No newline at end of file diff --git a/src/Skylark.Wing/Interface/IEventSubscription.cs b/src/Skylark.Wing/Interface/IEventSubscription.cs new file mode 100644 index 00000000..7a406d7e --- /dev/null +++ b/src/Skylark.Wing/Interface/IEventSubscription.cs @@ -0,0 +1,351 @@ +using System; +using System.Runtime.InteropServices; +using DISPPARAMS = System.Runtime.InteropServices.ComTypes.DISPPARAMS; +using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; +using SWNM = Skylark.Wing.Native.Methods; + +namespace Skylark.Wing.Interface +{ + /// + /// + /// + [ComImport] + [Guid("4A6B0E15-2E38-11D1-9965-00C04FBBB345")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IEventSubscription + { + #region + + /// + /// + /// + /// + int GetTypeInfoCount(); + + /// + /// + /// + /// + /// + /// + [return: MarshalAs(UnmanagedType.Interface)] + IntPtr GetTypeInfo([In, MarshalAs(UnmanagedType.U4)] int iTInfo, [In, MarshalAs(UnmanagedType.U4)] int lcid); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT GetIDsOfNames([In] ref Guid riid, [In, MarshalAs(UnmanagedType.LPArray)] string[] rgszNames, [In, MarshalAs(UnmanagedType.U4)] int cNames, [In, MarshalAs(UnmanagedType.U4)] int lcid, [Out, MarshalAs(UnmanagedType.LPArray)] int[] rgDispId); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Invoke(int dispIdMember, [In] ref Guid riid, [In, MarshalAs(UnmanagedType.U4)] int lcid, [In, MarshalAs(UnmanagedType.U4)] int dwFlags, [Out, In] DISPPARAMS pDispParams, [Out] out object pVarResult, [Out, In] EXCEPINFO pExcepInfo, [Out, MarshalAs(UnmanagedType.LPArray)] IntPtr[] pArgErr); + + #endregion + + /// + /// + /// + /// + /// + SWNM.HRESULT get_SubscriptionID(out string pstringSubscriptionID); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_SubscriptionID(string stringSubscriptionID); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_SubscriptionName(out string pstringSubscriptionName); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_SubscriptionName(string stringSubscriptionName); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_PublisherID(out string pstringPublisherID); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_PublisherID(string stringPublisherID); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_EventClassID(out string pstringEventClassID); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_EventClassID(string stringEventClassID); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_MethodName(out string pstringMethodName); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_MethodName(string stringMethodName); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_SubscriberCLSID(out string pstringSubscriberCLSID); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_SubscriberCLSID(string stringSubscriberCLSID); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_SubscriberInterface(out IntPtr ppSubscriberInterface); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_SubscriberInterface(IntPtr pSubscriberInterface); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_PerUser(out bool pfPerUser); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_PerUser(bool fPerUser); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_OwnerSID(out string pstringOwnerSID); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_OwnerSID(string stringOwnerSID); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_Enabled(out bool pfEnabled); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_Enabled(bool fEnabled); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_Description(out string pstringDescription); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_Description(string stringDescription); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_MachineName(out string pstringMachineName); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_MachineName(string stringMachineName); + + /// + /// + /// + /// + /// + /// + //SWNM.HRESULT GetPublisherProperty(string stringPropertyName, out VARIANT propertyValue); + + /// + /// + /// + /// + /// + /// + SWNM.HRESULT GetPublisherProperty(string stringPropertyName, out object propertyValue); + + /// + /// + /// + /// + /// + /// + //SWNM.HRESULT PutPublisherProperty(string stringPropertyName, VARIANT propertyValue); + + /// + /// + /// + /// + /// + /// + SWNM.HRESULT PutPublisherProperty(string stringPropertyName, object propertyValue); + + /// + /// + /// + /// + /// + SWNM.HRESULT RemovePublisherProperty(string stringPropertyName); + + /// + /// + /// + /// + /// + //SWNM.HRESULT GetPublisherPropertyCollection(out IEventObjectCollection collection); + + /// + /// + /// + /// + /// + SWNM.HRESULT GetPublisherPropertyCollection(out IntPtr collection); + + /// + /// + /// + /// + /// + /// + //SWNM.HRESULT GetSubscriberProperty(string stringPropertyName, out VARIANT propertyValue); + + /// + /// + /// + /// + /// + /// + SWNM.HRESULT GetSubscriberProperty(string stringPropertyName, out object propertyValue); + + /// + /// + /// + /// + /// + /// + //SWNM.HRESULT PutSubscriberProperty(string stringPropertyName, VARIANT propertyValue); + + /// + /// + /// + /// + /// + /// + SWNM.HRESULT PutSubscriberProperty(string stringPropertyName, object propertyValue); + + /// + /// + /// + /// + /// + SWNM.HRESULT RemoveSubscriberProperty(string stringPropertyName); + + /// + /// + /// + /// + /// + //SWNM.HRESULT GetSubscriberPropertyCollection(out IEventObjectCollection collection); + + /// + /// + /// + /// + /// + SWNM.HRESULT GetSubscriberPropertyCollection(out IntPtr collection); + + /// + /// + /// + /// + /// + SWNM.HRESULT get_InterfaceID(out string pstringInterfaceID); + + /// + /// + /// + /// + /// + SWNM.HRESULT put_InterfaceID(string stringInterfaceID); + } +} \ No newline at end of file diff --git a/src/Skylark.Wing/Interface/IEventSystem.cs b/src/Skylark.Wing/Interface/IEventSystem.cs new file mode 100644 index 00000000..9ae6e9cf --- /dev/null +++ b/src/Skylark.Wing/Interface/IEventSystem.cs @@ -0,0 +1,120 @@ +using System; +using System.Runtime.InteropServices; +using DISPPARAMS = System.Runtime.InteropServices.ComTypes.DISPPARAMS; +using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; +using SWNM = Skylark.Wing.Native.Methods; + +namespace Skylark.Wing.Interface +{ + /// + /// + /// + [ComImport] + [Guid("4E14FB9F-2E22-11D1-9964-00C04FBBB345")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IEventSystem + { + #region + + /// + /// + /// + /// + int GetTypeInfoCount(); + + /// + /// + /// + /// + /// + /// + [return: MarshalAs(UnmanagedType.Interface)] + IntPtr GetTypeInfo([In, MarshalAs(UnmanagedType.U4)] int iTInfo, [In, MarshalAs(UnmanagedType.U4)] int lcid); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT GetIDsOfNames([In] ref Guid riid, [In, MarshalAs(UnmanagedType.LPArray)] string[] rgszNames, [In, MarshalAs(UnmanagedType.U4)] int cNames, [In, MarshalAs(UnmanagedType.U4)] int lcid, [Out, MarshalAs(UnmanagedType.LPArray)] int[] rgDispId); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Invoke(int dispIdMember, [In] ref Guid riid, [In, MarshalAs(UnmanagedType.U4)] int lcid, [In, MarshalAs(UnmanagedType.U4)] int dwFlags, [Out, In] DISPPARAMS pDispParams, [Out] out object pVarResult, [Out, In] EXCEPINFO pExcepInfo, [Out, MarshalAs(UnmanagedType.LPArray)] IntPtr[] pArgErr); + + #endregion + + /// + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Query(string progID, string queryCriteria, out int errorIndex, out IntPtr ppInterface); + + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Store(string ProgID, IntPtr pInterface); + + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Remove(string progID, string queryCriteria, out int errorIndex); + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT get_EventObjectChangeEventClassID(out string pbstrEventClassID); + + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT QueryS(string progID, string queryCriteria, out IntPtr ppInterface); + + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT RemoveS(string progID, string queryCriteria); + } +} \ No newline at end of file diff --git a/src/Skylark.Wing/Interface/ISensLogon.cs b/src/Skylark.Wing/Interface/ISensLogon.cs new file mode 100644 index 00000000..9fecf6d7 --- /dev/null +++ b/src/Skylark.Wing/Interface/ISensLogon.cs @@ -0,0 +1,119 @@ +using System; +using System.Runtime.InteropServices; +using DISPPARAMS = System.Runtime.InteropServices.ComTypes.DISPPARAMS; +using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; +using SWNM = Skylark.Wing.Native.Methods; + +namespace Skylark.Wing.Interface +{ + /// + /// + /// + [ComImport] + [Guid("d597bab3-5b9f-11d1-8dd2-00aa004abd5e")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface ISensLogon + { + #region + + /// + /// + /// + /// + int GetTypeInfoCount(); + + /// + /// + /// + /// + /// + /// + [return: MarshalAs(UnmanagedType.Interface)] + IntPtr GetTypeInfo([In, MarshalAs(UnmanagedType.U4)] int iTInfo, [In, MarshalAs(UnmanagedType.U4)] int lcid); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT GetIDsOfNames([In] ref Guid riid, [In, MarshalAs(UnmanagedType.LPArray)] string[] rgszNames, [In, MarshalAs(UnmanagedType.U4)] int cNames, [In, MarshalAs(UnmanagedType.U4)] int lcid, [Out, MarshalAs(UnmanagedType.LPArray)] int[] rgDispId); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Invoke(int dispIdMember, [In] ref Guid riid, [In, MarshalAs(UnmanagedType.U4)] int lcid, [In, MarshalAs(UnmanagedType.U4)] int dwFlags, [Out, In] DISPPARAMS pDispParams, [Out] out object pVarResult, [Out, In] EXCEPINFO pExcepInfo, [Out, MarshalAs(UnmanagedType.LPArray)] IntPtr[] pArgErr); + + #endregion + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Logon(string stringUserName); + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT Logoff(string stringUserName); + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT StartShell(string stringUserName); + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT DisplayLock(string stringUserName); + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT DisplayUnlock(string stringUserName); + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT StartScreenSaver(string stringUserName); + + /// + /// + /// + /// + /// + [PreserveSig] + SWNM.HRESULT StopScreenSaver(string stringUserName); + } +} \ No newline at end of file diff --git a/src/Skylark.Wing/Native/Methods.cs b/src/Skylark.Wing/Native/Methods.cs index 90c65116..944772c2 100644 --- a/src/Skylark.Wing/Native/Methods.cs +++ b/src/Skylark.Wing/Native/Methods.cs @@ -465,6 +465,18 @@ public enum NTSTATUS : uint STATUS_SUCCESS = 0x00000000 } + /// + /// COM HRESULT Enum + /// + public enum HRESULT : int + { + S_OK = 0, + S_FALSE = 1, + E_FAIL = unchecked((int)0x80004005), + E_NOTIMPL = unchecked((int)0x80004001), + E_NOINTERFACE = unchecked((int)0x80004002) + } + /// /// Contains operating system version information. The information includes major and /// minor version numbers, a build number, a platform identifier, and information about diff --git a/src/Skylark.Wing/Skylark.Wing.cs b/src/Skylark.Wing/Skylark.Wing.cs index ed646f7d..83a8909b 100644 --- a/src/Skylark.Wing/Skylark.Wing.cs +++ b/src/Skylark.Wing/Skylark.Wing.cs @@ -22,7 +22,7 @@ // Website: www.vegalya.com // Created: 17.Jun.2023 // Changed: 31.Oct.2024 -// Version: 3.1.7.1 +// Version: 3.1.7.2 // // |---------DO-NOT-REMOVE---------| diff --git a/src/Skylark.Wing/Skylark.Wing.csproj b/src/Skylark.Wing/Skylark.Wing.csproj index c8b74260..4f98e7db 100644 --- a/src/Skylark.Wing/Skylark.Wing.csproj +++ b/src/Skylark.Wing/Skylark.Wing.csproj @@ -12,7 +12,7 @@ Resources\Skylark.Wing.ico - 3.1.7.1 + 3.1.7.2 $(Version) true Skylark.Wing