Hi there,
I need to know how to get the hard disk serial number, in windows.
Thank you in advance.
I googled "hard disk serial number python" and came up with something that did this:
import win32api
print win32api.GetVolumeInformation("C:\\")
It prints out a number of things like the file system and name, im not sure if it has the serial number but thats what other people on the python mailing list thought that it might be. So give it a shot. For this you need the Mark Hammond modules for windows. That includes the win32api
http://starship.python.net/crew/mhammond/win32/Downloads.html
Hope that helps. If not have a bit of a google yourself. :) Just to check
To follow up on the paulthom12345 information:
"""
win32api.GetVolumeInformation(path)
returns tuple containing ...
string - name of volume/disk/drive
long - serial number of volume/disk/drive
long - maximum component length of a file name
long - flags specific to the file system
string - file system name
"""
import win32api
path = "C:/"
info = win32api.GetVolumeInformation(path)
print( "disk serial number = %d" % info[1] )
"""
my output on Vista machine -->
disk serial number = 1022625589
"""
This is a quick little hack I made for windows that works on my vista computer, no third party modules needed ;-)
import os
data = os.popen('vol '+'c:', 'r').read()
data = data.split()
return data[len(data)-1:]
I looked around quick on the web and on linux you might be able to cook up something like that using the shell command "hdparm".
GL.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.