[Tutor] HD/DVD/CD
Terry Carroll
carroll at tjc.com
Wed Jan 4 02:35:30 CET 2006
On Tue, 3 Jan 2006, Ron Speerstra wrote:
> my question: howtoo read the HD/CD/DVD serial-numbers with Python.
I can take you part-way there, at least under Windows. Hopefully
someone can finish the job.
I'm assuming you want the same serial # that shows up when you do a
DIR on the CD, e.g.:
>dir d:
Volume in drive D is 050512_1752
Volume Serial Number is 8A73-780D
Here's some code:
>>> import win32api
>>> CD_Info = win32api.GetVolumeInformation("D:/")
>>> serno = CD_Info[1]
>>> serno
-1972144115
>>> "%X" % serno
'-758C87F3'
>>> "%X" % -serno
'758C87F3'
This is as far as I can get. the hex string, in this case 758C87F3 is the
two's complement of the serial number that shows up when I do a "dir d:":
>dir d:
Volume in drive D is 050512_1752
Volume Serial Number is 8A73-780D
Note that:
758C 87F3
+ 8A73 780D
=========
1 0000 0000
Put another way, if you flip every bit in the 758C87F3 string and add one,
you'll get the 8A73780D serial no.
I hope someone more artful than I can show a quick and easy way to convert
either '758C87F3' or -1972144115 to the '8A73780D' that is your goal.
I'm betting there's something simple I'm missing.
(By the way, it occurs to me; I guess you could just do the "dir" and
capture the serial number in the output; but that's inelegant and
wasteful.)
More information about the Tutor
mailing list