Name/ID of removable Media: how?
Claudio Grondi
claudio.grondi at freenet.de
Tue Apr 19 17:17:08 EDT 2005
Maybe the function below can help?
I suppose WMI returns same values as FSO (File System Object):
def strDriveHexSerialNumberFromFSOintRetVal(intDriveSerialNumberByFSO):
"""Supplied with an integer representing a drive serial number returns the
number in same format as \>dir command does (i.e. ####-####)."""
# The value of axDrive.SerialNumber property (an int or float number) can
be
# negative, so to get always a positive number as listed by e.g. \>dir
# command it is necessary to apply a workaround:
if(intDriveSerialNumberByFSO < 0):
# dec 4294967295 == hex FFFFFFFF, dec 4294967296 == hex 100000000
intDriveSerialNumber = 4294967296L + intDriveSerialNumberByFSO
else:
intDriveSerialNumber = intDriveSerialNumberByFSO
#:if/else
strHexSerialNumber = "%08X"%intDriveSerialNumber
strHexSerialNumber = strHexSerialNumber[:4]+"-"+strHexSerialNumber[4:]
return strHexSerialNumber
#:def strDriveHexSerialNumberFromFSOintRetVal(intDriveSerialNumberByFSO)
In your case
strDriveHexSerialNumberFromFSOintRetVal(-793919769):
gives:
D0AD-BEE7
Claudio
"Ivan Van Laningham" <ivanlan at pauahtun.org> schrieb im Newsbeitrag
news:mailman.2109.1113924702.1799.python-list at python.org...
> Hi All--
> Tim's wmi stuff looked interesting, so I tried it out, and now I have a
> question.
>
>
> -----
> #!/usr/bin/python
>
> import wmi
> import win32api
>
>
> c=wmi.WMI()
> for i in c.Win32_CDROMDrive():
> v=i.VolumeSerialNumber
> print "WMI serial",v,long(v,0x10)
>
> vn,sn,ln,flg,fstype=win32api.GetVolumeInformation("d:\\")
> print "win32api serial",sn,long(sn)
> ----
>
> The output from the above script (drive d contains cd) is:
>
> WMI serial D0ADBEE7 3501047527
>
> win32api serial -793919769 -793919769
>
>
> What's the difference between the two serial numbers? WMI is returning
> a long converted to a hex repr string, while win32api is returning an
> int (type(sn) is <type 'int'>), & converting to hex bears no resemblance
> to what WMI shows. What am I missing?
>
> Metta,
> Ivan
> ----------------------------------------------
> Ivan Van Laningham
> God N Locomotive Works
> http://www.andi-holmes.com/
> http://www.foretec.com/python/workshops/1998-11/proceedings.html
> Army Signal Corps: Cu Chi, Class of '70
> Author: Teach Yourself Python in 24 Hours
More information about the Python-list
mailing list