views:

340

answers:

1

How do you write an in-process WMI provider as part of Windows Service written in .NET?

I've written a provider that uses the de-coupled hosting model as a standalone application, but can't figure out how to get a Windows Service that uses the Hosting Model = ManagementHostingModel.NetworkService to work.

This is the kind of provider I'm using:

    [ManagementEntity]
public class Stuff
{
    private readonly string _id;

    public Stuff( string id )
    {
        _id = id;
    }

    [ManagementKey]
    public string Id
    {
        get { return _id; }
    }

    [ManagementProbe]
    public DateTime Time
    {
        get { return DateTime.UtcNow; }
    }

    [ManagementEnumerator]
    public static IEnumerable Enumerate()
    {
        for ( int i = 0; i < 5; i++ )
        {
            yield return new Stuff( i.ToString() );
        }
    }
}

Which I register using:

InstrumentationManager.RegisterType(typeof (Stuff));

Every time I try and access the WMI classes when trying to read the property values, I just get some weird exceptions thrown.

It seems like there must be something really simple I'm overlooking.

+4  A: 

The only bit I was missing was that in-process providers must be installed in the GAC. See this article for more details.

David Gardiner