# Release: Version 1.0
This commit is contained in:
parent
4b58d13a75
commit
acdab989c6
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <vector>
|
||||||
#include <Wbemidl.h>
|
#include <Wbemidl.h>
|
||||||
#pragma comment(lib, "wbemuuid.lib")
|
#pragma comment(lib, "wbemuuid.lib")
|
||||||
#include "query.cpp"
|
#include "query.cpp"
|
||||||
@ -7,8 +8,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
Sleep(1000);
|
||||||
// Najde ldisky a zobrazi jejich SW serial no.
|
// Najde ldisky a zobrazi jejich SW serial no.
|
||||||
const char* drive_names[] = {"A:\\", "B:\\", "C:\\", "D:\\", "E:\\", "F:\\", "G:\\", "H:\\", "I:\\", "J:\\", "K:\\", "L:\\", "M:\\", "N:\\", "O:\\", "P:\\", "Q:\\", "R:\\", "S:\\", "T:\\", "U:\\", "V:\\", "W:\\", "X:\\", "Y:\\", "Z:\\"};
|
const char* drive_names[] = {"A:\\", "B:\\", "C:\\", "D:\\", "E:\\", "F:\\", "G:\\", "H:\\", "I:\\", "J:\\", "K:\\", "L:\\", "M:\\", "N:\\", "O:\\", "P:\\", "Q:\\", "R:\\", "S:\\", "T:\\", "U:\\", "V:\\", "W:\\", "X:\\", "Y:\\", "Z:\\"};
|
||||||
|
|
||||||
DWORD drives = GetLogicalDrives();
|
DWORD drives = GetLogicalDrives();
|
||||||
@ -31,36 +32,123 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
// Najde hardware serial no a vyrobce vsech komponentu
|
// Najde hardware serial no a vyrobce vsech komponentu
|
||||||
cout << "--Win32_Processor--" << endl << "ProcessorID: " << GetHWIDs("Win32_Processor", L"ProcessorID") << endl;
|
cout << "--Win32_Processor--" << endl;
|
||||||
cout << "UniqueID: " << GetHWIDs("Win32_Processor", L"UniqueID") << endl;
|
GetHWIDs("Win32_Processor", L"UniqueID");
|
||||||
cout << "PNPDeviceID: " << GetHWIDs("Win32_Processor", L"PNPDeviceID") << endl;
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
cout << "Manufacturer: " << GetHWIDs("Win32_Processor", L"Manufacturer") << endl << endl;
|
cout << "[" << dec << i + 1 << "]\tUniqueID: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_Processor", L"PNPDeviceID");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tPNPDeviceID: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_Processor", L"Manufacturer");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tManufacturer: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "--Win32_OnBoardDevice--" << endl << "SerialNumber: " << hex << GetHWIDs("Win32_OnBoardDevice", L"SerialNumber") << endl;
|
cout << "--Win32_OnBoardDevice--" << endl;
|
||||||
cout << "Manufacturer: " << GetHWIDs("Win32_OnBoardDevice", L"Manufacturer") << endl << endl;
|
GetHWIDs("Win32_OnBoardDevice", L"SerialNumber");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tSerialNumber: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_OnBoardDevice", L"Manufacturer");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tManufacturer: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "--Win32_BaseBoard--" << endl << "SerialNumber: " << GetHWIDs("Win32_BaseBoard", L"SerialNumber") << endl;
|
cout << "--Win32_BaseBoard--" << endl;
|
||||||
cout << "Manufacturer: " << GetHWIDs("Win32_BaseBoard", L"Manufacturer") << endl << endl;
|
GetHWIDs("Win32_BaseBoard", L"SerialNumber");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tSerialNumber: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_BaseBoard", L"Manufacturer");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tManufacturer: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "--Win32_BIOS--" << endl << "SerialNumber: " << GetHWIDs("Win32_BIOS", L"SerialNumber") << endl;
|
cout << "--Win32_BIOS--" << endl;
|
||||||
cout << "Manufacturer: " << GetHWIDs("Win32_BIOS", L"Manufacturer") << endl << endl;
|
GetHWIDs("Win32_BIOS", L"SerialNumber");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tSerialNumber: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_BIOS", L"Manufacturer");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tManufacturer: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "--Win32_NetworkAdapter--" << endl << "MACAddress: " << GetHWIDs("Win32_NetworkAdapter", L"MACAddress") << endl;
|
cout << "--Win32_NetworkAdapter--" << endl;
|
||||||
cout << "PNPDeviceID: " << GetHWIDs("Win32_NetworkAdapter", L"PNPDeviceID") << endl;
|
GetHWIDs("Win32_NetworkAdapter", L"MACAddress");
|
||||||
cout << "Manufacturer: " << GetHWIDs("Win32_NetworkAdapter", L"Manufacturer") << endl << endl;
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i+1 << "]\tMACAddress: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_NetworkAdapter", L"Manufacturer");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i+1 << "]\tManufacturer: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "--Win32_DiskDrive--" << endl << "SerialNumber: " << GetHWIDs("Win32_DiskDrive", L"SerialNumber") << endl;
|
cout << "--Win32_DiskDrive--" << endl;
|
||||||
cout << "PNPDeviceID: " << GetHWIDs("Win32_DiskDrive", L"PNPDeviceID") << endl;
|
GetHWIDs("Win32_DiskDrive", L"SerialNumber");
|
||||||
cout << "Manufacturer: " << GetHWIDs("Win32_DiskDrive", L"Manufacturer") << endl << endl;
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tSerialNumber: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_DiskDrive", L"PNPDeviceID");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tPNPDeviceID: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_DiskDrive", L"Manufacturer");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tManufacturer: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "--Win32_VideoController--" << endl << "PNPDeviceID: " << GetHWIDs("Win32_VideoController", L"PNPDeviceID") << endl;
|
cout << "--Win32_VideoController--" << endl;
|
||||||
cout << "Name: " << GetHWIDs("Win32_VideoController", L"Name") << endl << endl;
|
GetHWIDs("Win32_VideoController", L"PNPDeviceID");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tPNPDeviceID: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_VideoController", L"Name");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tName: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "--Win32_ComputerSystemProduct--" << endl << "UUID: " << GetHWIDs("Win32_ComputerSystemProduct", L"UUID") << endl;
|
cout << "--Win32_ComputerSystemProduct--" << endl;
|
||||||
cout << "IdentifyingNumber: " << GetHWIDs("Win32_ComputerSystemProduct", L"IdentifyingNumber") << endl << endl << endl;
|
GetHWIDs("Win32_ComputerSystemProduct", L"UUID");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tUUID: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
GetHWIDs("Win32_ComputerSystemProduct", L"IdentifyingNumber");
|
||||||
|
for (ULONG i = 0; i < arrcount; i++) {
|
||||||
|
cout << "[" << dec << i + 1 << "]\tIdentifyingNumber: " << arr[i] << endl;
|
||||||
|
}
|
||||||
|
EmptyRtVars();
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
cout << "Press any key to close this window.." << endl;
|
|
||||||
|
cout << endl << "Press enter to close this window.." << endl;
|
||||||
cin.ignore();
|
cin.ignore();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -1,10 +1,23 @@
|
|||||||
std::string GetHWIDs(std::string table, LPCWSTR column) {
|
// Promene pro vysledek
|
||||||
|
std::vector<std::string> arr;
|
||||||
|
ULONG arrcount;
|
||||||
|
|
||||||
|
// Funkce pro vynulovani promenych pro vysledek, proc nepouzivm objekty hhahahahhah pomoc
|
||||||
|
int EmptyRtVars(void) {
|
||||||
|
arr.clear();
|
||||||
|
arrcount = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/api/wbemcli/nn-wbemcli-ienumwbemclassobject
|
||||||
|
int GetHWIDs(std::string table, LPCWSTR column) {
|
||||||
std::string retvalue = "";
|
std::string retvalue = "";
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
return retvalue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWbemLocator* pIWbemLocator = NULL;
|
IWbemLocator* pIWbemLocator = NULL;
|
||||||
@ -12,7 +25,7 @@ std::string GetHWIDs(std::string table, LPCWSTR column) {
|
|||||||
__uuidof(IWbemLocator), (LPVOID*)&pIWbemLocator);
|
__uuidof(IWbemLocator), (LPVOID*)&pIWbemLocator);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return retvalue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BSTR bstrServer = SysAllocString(L"\\\\.\\root\\cimv2");
|
BSTR bstrServer = SysAllocString(L"\\\\.\\root\\cimv2");
|
||||||
@ -22,43 +35,68 @@ std::string GetHWIDs(std::string table, LPCWSTR column) {
|
|||||||
pIWbemLocator->Release();
|
pIWbemLocator->Release();
|
||||||
SysFreeString(bstrServer);
|
SysFreeString(bstrServer);
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return retvalue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
|
hr = CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
|
||||||
NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_DEFAULT);
|
NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_DEFAULT);
|
||||||
|
|
||||||
BSTR bstrWQL = SysAllocString(L"WQL");
|
BSTR bstrWQL = SysAllocString(L"WQL");
|
||||||
//mrdka zasrana POMOC datatypy s vyterem prdele
|
|
||||||
|
// Poskladani WQL Query z parametru funkce a prevod datatypu
|
||||||
std::string wqlquery = "select * from " + table;
|
std::string wqlquery = "select * from " + table;
|
||||||
std::wstring wide_string = std::wstring(wqlquery.begin(), wqlquery.end());
|
std::wstring wide_string = std::wstring(wqlquery.begin(), wqlquery.end());
|
||||||
const wchar_t* result = wide_string.c_str();
|
const wchar_t* result = wide_string.c_str();
|
||||||
|
|
||||||
BSTR bstrPath = SysAllocString(result);
|
BSTR bstrPath = SysAllocString(result);
|
||||||
IEnumWbemClassObject* pEnum;
|
IEnumWbemClassObject* pEnum;
|
||||||
hr = pIWbemServices->ExecQuery(bstrWQL, bstrPath, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
|
hr = pIWbemServices->ExecQuery(bstrWQL, bstrPath, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
|
||||||
|
|
||||||
|
// Enumerace objektu/radku
|
||||||
ULONG uReturned;
|
ULONG uReturned;
|
||||||
VARIANT var;
|
VARIANT var;
|
||||||
IWbemClassObject* pObj = NULL;
|
IWbemClassObject* pObj[100];
|
||||||
if (!FAILED(hr)) {
|
if (!FAILED(hr)) {
|
||||||
hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &uReturned);
|
hr = pEnum->Next(WBEM_INFINITE, 100, pObj, &uReturned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ziskani hodnot vlastnosti/sloupce
|
||||||
if (!FAILED(hr) && uReturned) {
|
if (!FAILED(hr) && uReturned) {
|
||||||
hr = pObj->Get(column, 0, &var, NULL, NULL);
|
for (ULONG n = 0; n < uReturned; n++) {
|
||||||
if (SUCCEEDED(hr)) {
|
hr = pObj[n]->Get(column, 0, &var, NULL, NULL);
|
||||||
char str[MAX_PATH];
|
if (SUCCEEDED(hr)) {
|
||||||
WideCharToMultiByte(CP_ACP, 0, var.bstrVal, -1, str, sizeof(str), NULL, NULL);
|
char str[MAX_PATH];
|
||||||
retvalue = str;
|
WideCharToMultiByte(CP_ACP, 0, var.bstrVal, -1, str, sizeof(str), NULL, NULL);
|
||||||
|
retvalue = str;
|
||||||
|
|
||||||
|
if (V_VT(&var) == VT_BSTR) {
|
||||||
|
arr.push_back(retvalue);
|
||||||
|
pObj[n]->Release();
|
||||||
|
//return uReturned;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
arr.push_back("Empty");
|
||||||
|
pObj[n]->Release();
|
||||||
|
//return uReturned;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1; // Nepodarilo se ziskat hodnoty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return 1; // Nepodarilo se enumerovat objekty/radky
|
||||||
|
}
|
||||||
|
|
||||||
pEnum->Release();
|
arrcount = uReturned;
|
||||||
SysFreeString(bstrPath);
|
|
||||||
SysFreeString(bstrWQL);
|
//pEnum->Release();
|
||||||
pIWbemServices->Release();
|
//SysFreeString(bstrPath);
|
||||||
pIWbemLocator->Release();
|
//SysFreeString(bstrWQL);
|
||||||
SysFreeString(bstrServer);
|
//pIWbemServices->Release();
|
||||||
CoUninitialize();
|
//pIWbemLocator->Release();
|
||||||
return retvalue;
|
//SysFreeString(bstrServer);
|
||||||
|
//CoUninitialize();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user