8/2/2024
This commit is contained in:
33
Utils/hardware.hpp
Normal file
33
Utils/hardware.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "vector.h"
|
||||
#include <tuple>
|
||||
#include <cmath>
|
||||
|
||||
std::string GetDiskVolumeSerialNumber()
|
||||
{
|
||||
char volumeName[MAX_PATH + 1] = { 0 };
|
||||
char fileSystemName[MAX_PATH + 1] = { 0 };
|
||||
DWORD serialNumber = 0;
|
||||
DWORD maxComponentLength = 0;
|
||||
DWORD fileSystemFlags = 0;
|
||||
|
||||
if (GetVolumeInformationA("C:\\", volumeName, ARRAYSIZE(volumeName),
|
||||
&serialNumber, &maxComponentLength, &fileSystemFlags,
|
||||
fileSystemName, ARRAYSIZE(fileSystemName)))
|
||||
{
|
||||
// Convert serial number to a string
|
||||
std::string serialNumberStr = std::to_string(serialNumber);
|
||||
|
||||
return serialNumberStr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle error
|
||||
DWORD error = GetLastError();
|
||||
std::cerr << "Failed to get volume information. Error code: " << error << std::endl;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user