what is different between wmi and API

1.6k views Asked by At

i work with c++ programming, I use an example for understanding main of my question.

Suppose, we want get current username in windows operation system, we can use follow code :

#include <windows.h>
#include <Lmcons.h>

char username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserName(username, &username_len);

also, we can use wmi by follow the instruction explained on here and use Win32_ComputerSystem.UserName .

so, I hope you have fully understood, what's different between wmi and using api or any other way?

tank you for your response.

4

There are 4 answers

2
Jack D On BEST ANSWER

disadvantage :

  • Speed (mainly disadvantage)
  • if user turn off wmi service, wmi doesn't work.

advantage :

  • Wraps the native API
  • richer data, if you use wmi, you can get rich data
  • standardized, all the 'entities' are represented in a standardized way

These are the most important issues for using wmi.

0
Antonio Petricca On

The GetUserName API is merely a call to the function exported by the Advapi32.dll wich belongs to base kernel functions.

Using Win32_ComputerSystem class you are going to query Windows Management Instrumentation which is a complex and comprehensive infrastructure services which deals with most of the administrative tasks on Windows.

Posting a query to WMI involves much more resources and execution time so, if your goal is simply getting the user name, I suggest you to rely on the GetUserName API.

0
anup kataria On

Windows Management Instrumentation (WMI) is a set of specifications from Microsoft for consolidating the management of devices and applications in a network from Windows computing systems.

It is Microsoft implementation of Web-Based Enterprise Management. WMI - Services are installed on Windows OS, but the service can be turned off. So if user disabled the service you wont get any information about the system. It is just for reporting purpose.

Whereas the APIs are ways thru which the Microsoft provides the access to the information to local Application and some how you can also manipulate the information provided.

0
AiverReaver On

WMI is query Based and its run very slow where as API are much faster to run . Ex :- if you wanna check some System specification in your application before startup you should better use APIs . This will make you app Start faster.

WMI has advantage over api call WMI information is richer and easy to read where as to get that kind of same result we have to make several api calls .