Calling of GetVolumeInformation returns empty serial number

Durumdara durumdara at gmail.com
Tue Nov 7 02:58:27 EST 2017


Hi!
Windows 10, Python 3.6.
I want to get the serial number of the drives (without external modules
like Win32 or WMI).
It is needed for identification of removable devices (like USB external
drives).
Somewhere I saw this code:
def GetVolumeID(Drive):
 import ctypes
 kernel32 = ctypes.windll.kernel32
 volumeNameBuffer = ctypes.create_unicode_buffer(1024)
 fileSystemNameBuffer = ctypes.create_unicode_buffer(1024)
 serial_number = None
 max_component_length = None
 file_system_flags = None
 rc = kernel32.GetVolumeInformationW(
 ctypes.c_wchar_p(Drive),
 volumeNameBuffer,
 ctypes.sizeof(volumeNameBuffer),
 serial_number,
 max_component_length,
 file_system_flags,
 fileSystemNameBuffer,
 ctypes.sizeof(fileSystemNameBuffer)
 )
 return serial_number;
print(GetVolumeID('c:\\'))
This function is working with other values (volumeNameBuffer), but for
serial it returns None.
The serial number is empty.
How to I pass this parameter to I get the value?
The doc said it's LPDWORD (pointer to DWORD):
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
_Out_opt_ LPDWORD lpVolumeSerialNumber,
Thank you for any advance in this theme!
Best wishes
 dd


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /