Created
January 4, 2023 20:20
-
-
Save duketwo/74a933f35366ae1f56192e9973f88eff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
int main() | |
{ | |
// The drive letter of the hard drive you want to get the serial number for | |
wchar_t drive[] = L"C:\\"; | |
// Buffer to receive the volume serial number | |
DWORD serial_number; | |
// Buffer to receive the volume label | |
wchar_t volume_name[MAX_PATH + 1] = { 0 }; | |
// Size of the volume label buffer | |
DWORD volume_name_size = MAX_PATH + 1; | |
// File system flags | |
DWORD file_system_flags; | |
// File system name buffer | |
wchar_t file_system_name[MAX_PATH + 1] = { 0 }; | |
// Size of the file system name buffer | |
DWORD file_system_name_size = MAX_PATH + 1; | |
// Get the volume information | |
BOOL success = GetVolumeInformationW( | |
drive, | |
volume_name, | |
volume_name_size, | |
&serial_number, | |
NULL, | |
&file_system_flags, | |
file_system_name, | |
file_system_name_size | |
); | |
if (success) | |
{ | |
wprintf(L"Volume serial number: %d\n", serial_number); | |
wprintf(L"Volume label: %s\n", volume_name); | |
wprintf(L"File system name: %s\n", file_system_name); | |
} | |
else | |
{ | |
wprintf(L"GetVolumeInformation failed with error code %d\n", GetLastError()); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment