用C#编写WMI永久事件使用者 [英] Writing a WMI Permanent Event Consumer in C#

查看:246
本文介绍了用C#编写WMI永久事件使用者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我想用C#创建一个自定义的永久事件使用者.自
System.Management还不支持此操作,我必须使用Com interop
为我的.net事件使用者引用IWBemUnboundObjectSink,并且
我的事件使用者的IWbemProviderInit + IWbemEventConsumerProvider
提供者. (我已在msdn上阅读此文档:
http://msdn.microsoft.com/zh-CN/library/aa393014%28VS.85%29.aspx)
我可以"ComImport"所需的接口并实现它们,但是当我将程序集注册为Com对象时,这些接口不会显示在类型库中.
这是代码:

[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
[TypeLibTypeAttribute(TypeLibTypeFlags.FRestricted)]
[GuidAttribute("E246107B-B06E-11D0-AD61-00C04FD8FDFF")]
[ComImport]
公共接口IWbemUnboundObjectSink
{
[PreserveSig]
int IndicateToConsumer(
[输入] [MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pLogicalConsumer,
[In] Int32 lNumObjects,
[输入] [MarshalAs(UnmanagedType.Interface)] ref IWbemClassObject_DoNotMarshal apObjects);
}

[Guid("C6659361-1625-4746-931C-36014B14667A")]
[ProgId("Payvision.PermanentEventConsumer"))
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
公共类PermanentEventConsumer:IWbemUnboundObjectSink
{
const int WBEM_S_NO_ERROR = 0;

公共PermanentEventConsumer()
{
}

public int IndicateToConsumer(
IWbemClassObject_DoNotMarshal pLogicalConsumer,
int lNumObjects,
ref IWbemClassObject_DoNotMarshal apObjects)
{
Microsoft.VisualBasic.Interaction.Beep();
返回WBEM_S_NO_ERROR;
}
}

I want to create a custom permanent event consumer in C#. Since
System.Management does not support this yet, I have to use Com interop
to reference IWBemUnboundObjectSink for my .net event consumer, and
IWbemProviderInit + IWbemEventConsumerProvider for my event consumer
provider. (I have read this doc on msdn:
http://msdn.microsoft.com/en-us/library/aa393014%28VS.85%29.aspx)
I could "ComImport" the needed interfaces and implement them, but when I register my assembly as a Com object, these interfaces do not show up in the type library.
Here is the code:

[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
[TypeLibTypeAttribute(TypeLibTypeFlags.FRestricted)]
[GuidAttribute("E246107B-B06E-11D0-AD61-00C04FD8FDFF")]
[ComImport]
public interface IWbemUnboundObjectSink
{
[PreserveSig]
int IndicateToConsumer(
[In][MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pLogicalConsumer,
[In] Int32 lNumObjects,
[In][MarshalAs(UnmanagedType.Interface)] ref IWbemClassObject_DoNotMarshal apObjects);
}

[Guid("C6659361-1625-4746-931C-36014B14667A")]
[ProgId("Payvision.PermanentEventConsumer")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class PermanentEventConsumer : IWbemUnboundObjectSink
{
const int WBEM_S_NO_ERROR = 0;

public PermanentEventConsumer()
{
}

public int IndicateToConsumer(
IWbemClassObject_DoNotMarshal pLogicalConsumer,
int lNumObjects,
ref IWbemClassObject_DoNotMarshal apObjects)
{
Microsoft.VisualBasic.Interaction.Beep();
return WBEM_S_NO_ERROR;
}
}

(我只粘贴了2个课程中的1个)

(I only pasted 1 of the 2 classes)

任何帮助将不胜感激.谢谢

Any help would be much appreciated. Thanks

推荐答案

 

 

Hi,

 

感谢您的问题,我们正在研究这种情况,可能需要一些时间才能回复您.

Thank you for your question, we're doing research on this case, it might take some time before we get back to you.

 

此问题很紧急,请通过以下网址联系支持部门 http://support.microsoft.com .

If this issue is urgent, please contact support at http://support.microsoft.com.


这篇关于用C#编写WMI永久事件使用者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆