Thomas-Sparber / wmi

Very simple C++ library to query WMI (even for MinGW)
Other
91 stars 24 forks source link

Allow to select a WMI path for the class #24

Closed Adrianotiger closed 2 years ago

Adrianotiger commented 2 years ago

The project has a fixed path to the WMI classes: root/cimv2

There are many paths to use on the WMI class. See or download https://www.nirsoft.net/utils/simple_wmi_view.html to see them on your local computer.

With this update, the class can define also the path to search on.

So I extended the wmiclasses.hpp with AntivirusProduct and UWF_Filter (for Windows Embedded) as example. UWF_Filter works only if your computer has this feature enabled.

I added also the make file settings for Visual Studio.

As the project is not 100% compatible with the current one (class need to implement a base class to allow the call to getWmiPath()), it is up to you if you want merge it or discard it :)

PS: Thank you for the project! It is a fantastic project, also because WMIC will be removed from Windows: https://www.bleepingcomputer.com/news/microsoft/microsoft-starts-killing-off-wmic-in-windows-will-thwart-attacks/

Thomas-Sparber commented 2 years ago

I really like the idea of supporting different roots! Also I like all the small changes/improvements you made!

What I dont really like is that this would be a breaking change for every user. Also I am not a big fan that all the wmi classes need to extend WmiBase and have virtual functions...

What do you think about extending the functions retrieveWmi and retrieveAllWmi with a root parameter defaulting to root/cimv2? That way we wont have breaking changes, no base class, no virtual functions and still the possibility to choose the wmi root.

Best Regards Thomas

Adrianotiger commented 2 years ago

It is just an example how to add a functionality :) You can reject the pull request and change your code (I changed just some lines). It was more to show another solution.

What do you think about extending the functions retrieveWmi and retrieveAllWmi with a root parameter defaulting to root/cimv2? That way we wont have breaking changes, no base class, no virtual functions and still the possibility to choose the wmi root.

It is exactly what I made at beginning :D But each class has only 1 root. And with this change, the developer need to know the root and the class to use. It is easier for the end user, if he need to just add the class (without need where this class is located in the wmi).

My second solution was to just add getWmiPath (or getWmiRoot), like getWmiClassName. It is a nice solution since the compiler does give an error message if this method is not implemented.

I don't know what is better... Just an interface for all classes? Or a base class with predefined root? Or nothing?

My c++ knowledge can't give you a good solution. Sorry.

Thomas-Sparber commented 2 years ago

OK I understand! And I think you are right!

I will try to make an implementation with SFINAE... I will let you know.

Thomas-Sparber commented 2 years ago

OK so I just commited your code but made some changes to use SFINAE to optionally choose the wmi root.

Please check and let me know what you think

Thomas-Sparber commented 2 years ago

Oh wait - there is a bug... let me fix that quickly...

Thomas-Sparber commented 2 years ago

OK - now it's fixed, you can test :-)

Adrianotiger commented 2 years ago

It works, thanks! I was able to update the code to calls also WMI methods. Since many wmi classes have also methods to call.

I will not make any push request, as my c++ knowledge are really low compared to your one and I don't want humiliate myself further ;)