Find a drive serial number for a given drive letter

  • Thread starter Thread starter _DD
  • Start date Start date
D

_DD

Any way to correlate the serial number of a drive with which letter
it's assigned to? This would be a nice utility for systems that have
lots of drives.
 
_DD said:
Any way to correlate the serial number of a drive with which letter
it's assigned to? This would be a nice utility for systems that have
lots of drives.
If you have Python installed (www.python.org) and the Win32 extensions
(http://www.python.net/crew/mhammond/win32/), I have a script that will do
what you want. It just checks for the existence of drives "a" through "z"
and uses GetVolumeInformation to retriev the volume serial number. Here is
some sample output:

----------
C:\python volumeinfo.py

Serial numbers for all drives on COMPUTER1:

Serial # for drive C: is B81A AFC1
Serial # for drive D: is D82C ED51
Serial # for drive E: is 007E F9D1
Serial # for drive F: is 5C98 2BE2

4 volumes found on COMPUTER1
 
If you have Python installed (www.python.org) and the Win32 extensions
(http://www.python.net/crew/mhammond/win32/), I have a script that will do
what you want. It just checks for the existence of drives "a" through "z"
and uses GetVolumeInformation to retriev the volume serial number. Here is
some sample output:

----------
C:\python volumeinfo.py

Serial numbers for all drives on COMPUTER1:

Serial # for drive C: is B81A AFC1
Serial # for drive D: is D82C ED51
Serial # for drive E: is 007E F9D1
Serial # for drive F: is 5C98 2BE2

4 volumes found on COMPUTER1

Thanks, Louis. I should have specified...I was looking for the
drive's 'hardware' serial number. The above looks like the serial
that's assigned as the drive is formatted.

I think I wrote a program to do the latter at one time, though not in
Python. I took a very cursory look at Python, and to be honest, the
syntax did not appeal to me at the time. I guess it's from years of
programming with curl-braces. Is it worth learning if one already has
a background in structured programming?

If so, and if it's no problem, please post your code and I'll take a
look on the way to learning some Python.

Thanks!
 
_DD said:
Thanks, Louis. I should have specified...I was looking for the
drive's 'hardware' serial number. The above looks like the serial
that's assigned as the drive is formatted.

I think I wrote a program to do the latter at one time, though not in
Python. I took a very cursory look at Python, and to be honest, the
syntax did not appeal to me at the time. I guess it's from years of
programming with curl-braces. Is it worth learning if one already has
a background in structured programming?

If so, and if it's no problem, please post your code and I'll take a
look on the way to learning some Python.

Thanks!
With the exception of "Hello world!" in C and Java, Python is the only
language I know. (Unless you count Basic.) The one thing I have found is
that you can whip up a quick utility in no time. I am not a programmer, but
even I can get some work done in a hurry. You might take a look at the
tutorial links at python.org. Once you get past the fact that indentation is
significant, you'll find it quite easy to learn. By the way, I think those
funny looking, randomly placed curly braces are what steered me toward
Python. The indentation or Python forces the structure of your program to
be consistent and makes it easy to read other people's code. Just my
opinion.
Louis

------------------------------------------------------------
import win32api
print

try:
cName = win32api.GetComputerName()
except:
cName = 'Computer Name Unknown'

print 'Serial numbers for all drives on %s:' %\
(cName)
print

count=0
for i in range(26):
dLetter = chr(i + 97) + ':\\'
try:
x = win32api.GetVolumeInformation(dLetter)
volser = int(x[1])
if volser < 0:
volser = 4294967296 - abs(volser)
hexser = hex(volser).strip('L').upper()[2:]
while len(hexser) < 8:
hexser = '0' + hexser
print 'Serial # for drive %s is %4s %4s' %\
(dLetter[:2].upper(), hexser[0:-4],\
hexser[-4:])
count+=1
except:
pass

print
print '%s volume(s) found on %s' % (count, cName)
------------------------------------------------------------
 
With the exception of "Hello world!" in C and Java, Python is the only
language I know. (Unless you count Basic.) The one thing I have found is
that you can whip up a quick utility in no time. I am not a programmer, but
even I can get some work done in a hurry. You might take a look at the
tutorial links at python.org. Once you get past the fact that indentation is
significant, you'll find it quite easy to learn.

There was once a language called Occam that was white-space dependent.
It was designed for a CPU called the Transputer. A very elegant
language.

Thanks for posting your code!
 
Back
Top