gpt4 book ai didi

c# - 在 .NET 中接收 SENS 事件

转载 作者:太空宇宙 更新时间:2023-11-03 11:28:12 25 4
gpt4 key购买 nike

我想在屏幕保护程序打开/关闭时接收 SENS 事件。我的代码基于 this文章:

private static readonly string GUID = "{" + typeof(ScreensaverHandler).GUID.ToString() + "}";

[ComImport, Guid("4E14FBA2-2E22-11D1-9964-00C04FBBB345")]
private class EventSystem { }

[ComImport, Guid("7542E960-79C7-11D1-88F9-0080C7D771BF")]
private class EventSubcription { }

[ComImport, Guid("AB944620-79C6-11d1-88F9-0080C7D771BF")]
private class EventPublisher { }

[ComImport, Guid("cdbec9c0-7a68-11d1-88f9-0080c7d771bf")]
private class EventClass { }

public ScreensaverHandler() {
IEventSystem es = (IEventSystem) new EventSystem();
IEventSubscription sub = (IEventSubscription) new EventSubcription();
sub.Description = "description";
sub.SubscriptionName = "subscriptionname";
sub.SubscriptionID = GUID;
sub.InterfaceID = GetInterfaceGuid(typeof(SensEvents.ISensLogon));
sub.SubscriberInterface = this; // implements SensEvents.ISensLogon
es.Store("EventSystem.EventSubscription", sub);
}

private static string GetInterfaceGuid(Type type) {
object[] attributes = type.GetCustomAttributes(typeof(GuidAttribute), true);
return "{" + ((GuidAttribute)attributes[0]).Value + "}";
}

问题是 es.Store 抛出 System.UnauthorizedAccessException 并且 Access is denied。 (HRESULT 异常:0x80070005 (E_ACCESSDENIED))

最佳答案

您可能遇到了 this Microsoft security bulletin 的副作用.您可能需要放宽对事件系统 dll 的安全限制。

如果您还没有,我会先以管理员身份尝试此操作。我刚刚以完全管理员身份在 Win Server 2008 上测试了您的代码,没有任何问题。

此外,还有另一篇关于 .Net 中事件系统的非常好的文章 CodeProject .

关于c# - 在 .NET 中接收 SENS 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com