forked from vic4key/Vutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample.WMI.h
More file actions
51 lines (40 loc) · 1.14 KB
/
Sample.WMI.h
File metadata and controls
51 lines (40 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "Sample.h"
#if defined(VU_WMI_ENABLED)
#include <map>
#include <comdef.h>
#include <wbemidl.h>
#endif // VU_WMI_ENABLED
DEF_SAMPLE(WMIProvider)
{
#if defined(VU_WMI_ENABLED)
// Example 1
// Get-WmiObject -Class MSFT_PhysicalDisk -Namespace ROOT\Microsoft\Windows\Storage | Select FriendlyName
vu::CWMIProvider WMI;
WMI.Begin(_T("ROOT\\Microsoft\\Windows\\Storage"));
{
WMI.Query(_T("SELECT * FROM MSFT_PhysicalDisk"), [](IWbemClassObject& object) -> bool
{
VARIANT s;
object.Get(L"FriendlyName", 0, &s, 0, 0);
std::wcout << s.bstrVal << std::endl;
return true;
});
}
WMI.End();
// Example 2
// Get Type of Disks
std::map<vu::eDiskType, std::tstring> types;
types[vu::eDiskType::Unspecified] = _T("Unspecified");
types[vu::eDiskType::HDD] = _T("HDD");
types[vu::eDiskType::SSD] = _T("SSD");
types[vu::eDiskType::SCM] = _T("SCM");
std::tstring drives = _T("CDEFG?");
for (const auto drive : drives)
{
auto type = vu::GetDiskType(drive);
std::tcout << drive << _T(" -> ") << types[type] << std::endl;
}
#endif // VU_WMI_ENABLED
return vu::VU_OK;
}