Commit d2da3411 authored by captainwong's avatar captainwong

wmi

parent b657c6e8
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#pragma once
/**
* 主要参考了 https://blog.csdn.net/breaksoftware/article/category/9269057
*/
#include <Windows.h>
#include <comdef.h>
#include <WbemIdl.h>
#include <atlbase.h>
#include <atlcom.h>
#include <comdef.h>
#include <string>
#include <functional>
#pragma comment (lib, "comsuppw.lib")
#pragma comment (lib, "wbemuuid.lib")
#if !defined(UNICODE) && !defined(_UNICODE)
#error wmi only works with unicode!
#endif
#define JLIB_CHECK_HR(hr) if (FAILED(hr)) break;
#define JLIB_CHECK_HR2(hr, errorFunc) if (FAILED(hr)) { if (errorFunc) { errorFunc(hr, _com_error(hr).ErrorMessage()); } break; }
#define JLIB_CHECK_WMI_HR(hr) if ((hr) != WBEM_S_NO_ERROR) break;
......
......@@ -5,10 +5,6 @@ VisualStudioVersion = 16.0.29209.62
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testDeviceUniqueIdentifierHeaderOnly", "testDeviceUniqueIdentifierHeaderOnly\testDeviceUniqueIdentifierHeaderOnly.vcxproj", "{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testDeviceUniqueIdentifier", "testDeviceUniqueIdentifier\testDeviceUniqueIdentifier.vcxproj", "{CA7812A3-9E48-4A94-B39A-32EED587E38A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_win32", "test_win32\test_win32.vcxproj", "{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_qt", "test_qt\test_qt.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}"
......@@ -54,9 +50,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "win32", "win32", "{B5D9E71E-2BFE-4D04-A66A-4CB0A103CD77}"
ProjectSection(SolutionItems) = preProject
..\jlib\win32\clipboard.h = ..\jlib\win32\clipboard.h
..\jlib\win32\DeviceUniqueIdentifier.cpp = ..\jlib\win32\DeviceUniqueIdentifier.cpp
..\jlib\win32\DeviceUniqueIdentifier.h = ..\jlib\win32\DeviceUniqueIdentifier.h
..\jlib\win32\deviceuniqueidentifierheaderonly.h = ..\jlib\win32\deviceuniqueidentifierheaderonly.h
..\jlib\win32\deviceuniqueidentifier.h = ..\jlib\win32\deviceuniqueidentifier.h
..\jlib\win32\file_op.h = ..\jlib\win32\file_op.h
..\jlib\win32\memory_micros.h = ..\jlib\win32\memory_micros.h
..\jlib\win32\MyWSAError.h = ..\jlib\win32\MyWSAError.h
......@@ -223,6 +217,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_clipboard", "test_clip
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_wmi", "test_wmi\test_wmi.vcxproj", "{79A2C0A6-B8BB-406F-A732-C6300A611EC8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testDeviceUniqueIdentifier", "testDeviceUniqueIdentifier\testDeviceUniqueIdentifier.vcxproj", "{CA7812A3-9E48-4A94-B39A-32EED587E38A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
......@@ -239,22 +235,6 @@ Global
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}.Release|x64.Build.0 = Release|x64
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}.Release|x86.ActiveCfg = Release|Win32
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}.Release|x86.Build.0 = Release|Win32
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Debug|x64.ActiveCfg = Debug|x64
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Debug|x64.Build.0 = Debug|x64
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Debug|x86.ActiveCfg = Debug|Win32
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Debug|x86.Build.0 = Debug|Win32
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Release|x64.ActiveCfg = Release|x64
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Release|x64.Build.0 = Release|x64
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Release|x86.ActiveCfg = Release|Win32
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}.Release|x86.Build.0 = Release|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x64.ActiveCfg = Debug|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x64.Build.0 = Debug|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x86.ActiveCfg = Debug|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x86.Build.0 = Debug|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x64.ActiveCfg = Release|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x64.Build.0 = Release|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x86.ActiveCfg = Release|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x86.Build.0 = Release|Win32
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Debug|x64.ActiveCfg = Debug|x64
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Debug|x64.Build.0 = Debug|x64
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Debug|x86.ActiveCfg = Debug|Win32
......@@ -341,14 +321,20 @@ Global
{79A2C0A6-B8BB-406F-A732-C6300A611EC8}.Release|x64.Build.0 = Release|x64
{79A2C0A6-B8BB-406F-A732-C6300A611EC8}.Release|x86.ActiveCfg = Release|Win32
{79A2C0A6-B8BB-406F-A732-C6300A611EC8}.Release|x86.Build.0 = Release|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x64.ActiveCfg = Debug|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x64.Build.0 = Debug|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x86.ActiveCfg = Debug|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Debug|x86.Build.0 = Debug|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x64.ActiveCfg = Release|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x64.Build.0 = Release|x64
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x86.ActiveCfg = Release|Win32
{CA7812A3-9E48-4A94-B39A-32EED587E38A}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5} = {21DC893D-AB0B-48E1-9E23-069A025218D9}
{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{CA7812A3-9E48-4A94-B39A-32EED587E38A} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{B12702AD-ABFB-343A-A199-8E24837244A3} = {21DC893D-AB0B-48E1-9E23-069A025218D9}
{8A39D7AF-50AF-43BD-8CC6-DA20B6349F03} = {21DC893D-AB0B-48E1-9E23-069A025218D9}
......@@ -380,6 +366,7 @@ Global
{16CAD8DD-EF99-4A38-B5AA-BF86FC7A07AB} = {F118E1C9-F461-4CAA-A0F1-75F5A5C8ADF3}
{904EC99B-A012-4134-AE6F-E21635FB602F} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{79A2C0A6-B8BB-406F-A732-C6300A611EC8} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{CA7812A3-9E48-4A94-B39A-32EED587E38A} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8EBEA58-739C-4DED-99C0-239779F57D5D}
......
#include <jlib/win32/DeviceUniqueIdentifier.h>
#include <stdio.h>
#include <algorithm>
#include <locale>
int main()
{
std::locale::global(std::locale(""));
using namespace jlib::DeviceUniqueIdentifier;
std::vector<std::wstring> results;
/*query(RecommendedQueryTypes, results);
auto str = join_result(results, L"\n");
std::wcout << str << std::endl;*/
results.clear();
query(AllQueryTypes, results);
std::wstring str;
std::vector<std::wstring> types = {
L"MAC_ADDR 网卡MAC地址",
L"MAC_ADDR_REAL 网卡原生MAC地址",
L"HARDDISK_SERIAL 主硬盘序列号",
L"MOTHERBOARD_UUID 主板序列号",
L"MOTHERBOARD_MODEL 主板型号",
L"CPU_ID 处理器序列号",
L"BIOS_SERIAL BIOS序列号",
L"WINDOWS_PRODUCT_ID Windows产品ID",
L"WINDOWS_MACHINE_GUID Windows机器码",
};
for (size_t i = 0; i < std::min(types.size(), results.size()); i++) {
printf("%ls:\n%ls\n\n", types[i].c_str(), results[i].c_str());
}
//auto str = join_result(results, L"\n");
//std::wcout << std::endl << str << std::endl;
system("pause");
}
\ No newline at end of file
#include <jlib/win32/DeviceUniqueIdentifierHeaderOnly.h>
#include <jlib/win32/DeviceUniqueIdentifier.h>
#include <stdio.h>
#include <algorithm>
#include <locale.h>
......
......@@ -29,14 +29,14 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
......@@ -120,11 +120,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\jlib\win32\DeviceUniqueIdentifier.cpp" />
<ClCompile Include="test.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\jlib\win32\DeviceUniqueIdentifier.h" />
<ClCompile Include="testDeviceUniqueIdentifier.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -15,16 +15,8 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\jlib\win32\DeviceUniqueIdentifier.cpp">
<ClCompile Include="testDeviceUniqueIdentifier.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\jlib\win32\DeviceUniqueIdentifier.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{1E6D1113-2EDE-4E7E-BF17-A3663101C3AE}</ProjectGuid>
<RootNamespace>testDeviceUniqueIdentifierHeaderOnly</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(DEVLIBS)/Global;$(BOOST);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(DEVLIBS)/jlib;$(BOOST);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST);$(DEVLIBS)\jlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="testDeviceUniqueIdentifierHeaderOnly.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="testDeviceUniqueIdentifierHeaderOnly.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment