-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSample.cpp
71 lines (63 loc) · 2.15 KB
/
Sample.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// CrDiskInfoLib: Sample.cpp
// Copyright (c) 2014, Egtra
//
// This code is released under the MIT license.
// See LICENSE.txt
#include "stdafx.h"
#include <iostream>
#include <locale>
#include <algorithm>
#include <tchar.h>
#include "DiskInfoLib.h"
void PrintDiskInfo(const DiskInfo& diskInfo)
{
std::wcout << "----------------\n";
std::wcout << L"SerialNumber: " << diskInfo.SerialNumber << L'\n';
std::wcout << L"FirmwareRev: " << diskInfo.FirmwareRev << L'\n';
std::wcout << L"Model: " << diskInfo.Model << L'\n';
std::wcout << L"ModelWmi: " << diskInfo.ModelWmi << L'\n';
std::wcout << L"ModelSerial: " << diskInfo.ModelSerial << L'\n';
std::wcout << L"MaxTransferMode: " << diskInfo.MaxTransferMode << L'\n';
std::wcout << L"CurrentTransferMode: " << diskInfo.CurrentTransferMode << L'\n';
std::wcout << L"MajorVersion: " << diskInfo.MajorVersion << L'\n';
std::wcout << L"MinorVersion: " << diskInfo.MinorVersion << L'\n';
std::wcout << L"Interface: " << diskInfo.Interface << L'\n';
std::wcout << L"Enclosure: " << diskInfo.Enclosure << L'\n';
std::wcout << L"SsdVendorString: " << diskInfo.SsdVendorString << L'\n';
std::wcout << L"DeviceNominalFormFactor: " << diskInfo.DeviceNominalFormFactor << L'\n';
std::wcout << L"PnpDeviceId: " << diskInfo.PnpDeviceId << L'\n';
}
int _tmain()
{
std::wcout.imbue(std::locale(""));
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (FAILED(hr))
{
std::cerr << "CoInitializeEx failed: " << std::hex << hr << std::endl;
return 1;
}
hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
if (FAILED(hr))
{
std::cerr << "CoInitializeSecurity failed: " << std::hex << hr << std::endl;
return 1;
}
// for WMI error
SetErrorMode(SEM_FAILCRITICALERRORS);
try
{
std::vector<DiskInfo> diskInfo = CrDiskInfoLib::GetDiskInfo();
std::for_each(diskInfo.begin(), diskInfo.end(), PrintDiskInfo);
}
catch (const std::exception& e)
{
std::cerr << "std::exception: " << e.what() << std::endl;
return 1;
}
catch (...)
{
std::cerr << "Unknown exception" << std::endl;
return 1;
}
CoUninitialize();
}