Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi, Can you please provide steps to create a WMI provider. I have to develop a WMI provider to get details of devices connected with my machine. I need details like, can I create WMI provider as visual studio console application? I have red COM is required to build WMI provider. how COM library should be linked with this provider code.How can I test the WMI Provider.

What I have tried:

I am learning about WMI provider.
Posted
Comments
Richard Deeming 4-Jan-24 5:11am    
This is a "quick answers" forum, not a "teach me a complete topic from start to finish" forum.

Start reading the documenation[^]. If you get stuck with specific concepts then I'm sure somebody here will be able to help you. But we can't teach you the whole thing in a tiny little text box!
Dave Kreskowiak 4-Jan-24 9:37am    
First things first. Are you trying to get data on a device through WMI or are you trying to provide data from this device to other WMI inquirers?

1 solution

You should specify on what language you want to implement it.
In .NET it's more easy to make: you should declare class with fields which you planning to pass as an event arguments. The class should have fields only and have class attribute InstrumentationClass set as event.
[InstrumentationClass(InstrumentationType.Event)]
public class MyEvent
{
    public string Text;
}

To raise event you should create instance of your object, set fields and call Instrumentation.Fire
var _event = new MyEvent();
_event.Text = "Some Text";
Instrumentation.Fire(_event);

To specify WMI root use Instrumented assembly attribute:
[assembly: Instrumented("root/default")]

To have installer you can use the default one:
[System.ComponentModel.RunInstaller(true)]
public class WMIProviderInstaller : DefaultManagementProjectInstaller { }

Install the provider before posting the event.

The C++ implementation is more heavy. You should create *.mof file of your provider and also declare the event class and it fields. Setup that mof file into WMI with mof registration tool.
In provider COM object you should implement IWbemEventProvider and IWbemProviderInit. In initialization method you request for the IWbemClassObject of the type you interested from the connected namespace. To raising evens you initiate instance of the IWbemClassObject object by using IWbemClassObject->SpawnInstance and set fields as COM Variants based on fields you declared in the mof file. And the call the IWbemObjectSink->Indicate with initialized event.

For the remote connection you should configure security settings.

For testing you can use your own application or any script language which allow to perform wmi query, or the wbemtest tool.

Regards,
Maxim.
 
Share this answer
 
Comments
Member 16008221 16-Jan-24 7:30am    
Thank you soo much for the response Maxim Kartavenkov. I have to develop this application in C++.I will follow your method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900