- Step 1:
- Step 2:
- Step 3:
Find the WMI information you need on the official website (or communicate with the hardware developer about the interface and Parameter definitions you need. If you are negotiating the WMI interface with the hardware developer, see Step 2 directly);
For example, I need to get display information
I will first search by Biying which WMI is required, and then find the corresponding WMI requirements details under Microsoft docs.
For example, I know that I need wmimonitorconnectionparams to get the display information. Then I search for wmimonitorconnectionparams in the docs document. The address is as follows:
WmiMonitorConnectionParams class – Win32 apps | Microsoft Docs
Let’s see that the value of namespace in the figure below is root \ WMI
We know that his book belongs to the namespace namespace. At the same time, we find properties on the website. We see an InstanceName and a videooutputtechnology, which are string type and uint32 type respectively.
At present, we only need so much information, and then we start to quickly verify the returned information of the interface on the machine that needs to be verified. If there is a problem.
There is no need to write code to quickly verify whether the interface is available.
(avoid other problems caused by personal code, which takes a lot of time, and the communication and debugging cost of this combination of software and hardware is high)
Use the win + R key to enable the input of wbemtest Exe press enter, which is the WMI tool of the system.
This is our tool to quickly verify WMI.
(1) Click Connect.
(2) In the pop-up box, enter the namespace we just found on the Internet: root \ WMI. Because we are not remotely connected to other computers, the connection remains the default. Click the connection in the upper right corner.
(3) Different WMI message query methods are different, such as active query and passive acceptance. The main difference is between re selection query and notification query. We can’t use more complex operations here at present, because we mainly want to verify WMI.
This time we click query, because we actively query the display information. This is not an event. In the pop-up query dialog box, enter:
SELECT InstanceName, VideoOutputTechnology FROM WmiMonitorConnectionParams
Click apply. The following figure shows that the interface can be accessed normally. If an error is prompted, there is a problem with the input. Or there is a problem with the input WMI. You need to debug or communicate with the corresponding personnel. If the hardware sends you WMI, confirm that the hardware on this machine is debugged and can send WMI messages normally.
To achieve this effect, WMI is equivalent to testing pull-through. Is it particularly convenient and fast to quickly verify WMI? Can greatly improve communication efficiency. Next is the code link.
Generate code using WMI tools:
WMI code creator is a WMI code generation tool provided by Microsoft to generate corresponding WMI access code. Can choose
Download software from this website:
Download WMI Code Creator v1.0 from Official Microsoft Download Center
We click code language to switch to C #.
(1) Namespace: select root \ WMI (- ——- note case!!! ——–)
(2) Then select classes or enter the wmimonitorconnectionparams we found.
(3) Check the content we want to query under result. We need to check all three.
(4) The code will appear on the right again. In that case. We can normally migrate the code to our project.
(5) This function of accessing WMI is mainly encapsulated in system Management namespace. The rest can be expanded and pulled by themselves. Have their own access to get worth it. And WMI to accept events. The main idea is to first query or define the WMI interface you want to use, and then query or negotiate the defined parameters. Then you can encapsulate the code here.
The above is c# the details of more efficient WMI access through wbemtest and WMI code cretor. For more information about c# efficient WMI access, please pay attention to other developeppaer related articles!