Search code examples
c++c++11wmiwmi-service

what is different between wmi and API


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.


Solution

  • 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.