Detect hard diskk serial number.  
Author Message
Jarron





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

Dear Expert,

Can I know how to detect the hard disk serial number or code using foxpro

Thanks a lots.



Visual FoxPro1  
 
 
CetinBasoz





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

If you mean the one that format creates:

Declare SHORT GetVolumeInformation In Win32API;





  Integer nFileSystemNameSize
Local lncomplen, lnsysflags, lnserialno, ;
  lcvolname, lcsysname,lnvolsize, lnnamesize

Store 0 To lncomplen, lnsysflags, lnserialno
Store Space(260) To lcvolname, lcsysname
Store Len(m.lcvolname) To m.lnvolsize, m.lnnamesize
lcRoot = 'c:\'



m.lnserialno, ;


 
 
stuartdunkeld





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

Hi

You can do this using WMI (an internal database of objects maintained by Windows)

This code returns the serial # of my local hard disk(s)

oWMI = getobject("winmgmts:")
oDisks = oWMI.InstancesOf("Win32_PhysicalMedia")
for each oDisk in oDisks
    "serial # " + oDisk.SerialNumber
next

The syntax will be slightly different for VFP6 or earlier, and this could be run remotely: see here for more info.

--stuartd

 
 
Jarron





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

Thanks a lots.
 
 
djun_kang





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

how to get the hard disk serial no where my app is installed. How can i know which hard disk
 
 
CetinBasoz





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

Check application.servername.
 
 
djun_kang





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

What Imean is how how to tell wmi to just to return one harddisk which is the hard disk that has my app in it

wmi return all hard disk installed in the computer. I dont know which of the hardisk is the harddisk i want .


 
 
CetinBasoz





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

Oh I thought you could do it WMI already and don't know how to get driveletter.

Create Cursor myDisks (DriveLetter c(1),SerialNumber c(50),Model c(50),DeviceID c(50))

wmiServices = Getobject("winmgmts:{impersonationLevel=Impersonate}!//.")
wmiDiskDrives = wmiServices.ExecQuery("SELECT Model,DeviceID FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives
lcDeviceID = Trim(Strtran(wmiDiskDrive.DeviceID,'\','\\'))
wmiDiskPartitions = wmiServices.ExecQuery(;
'ASSOCIATORS OF {Win32_DiskDrive.DeviceID="' +;
m.lcDeviceID + '"} WHERE '+ ;
'AssocClass = Win32_DiskDriveToDiskPartition')

For Each wmiDiskPartition In wmiDiskPartitions
wmiLogicalDisks = wmiServices.ExecQuery( ;
'ASSOCIATORS OF {Win32_DiskPartition.DeviceID="'+;
wmiDiskPartition.DeviceID + '"} WHERE '+;
'AssocClass = Win32_LogicalDiskToPartition')

For Each wmiLogicalDisk In wmiLogicalDisks
wmiDisks = wmiServices.ExecQuery(;
'SELECT * FROM Win32_PhysicalMedia where Tag="'+m.lcDeviceID+'"')
For Each wmiDisk In wmiDisks
Insert Into myDisks ;
(DriveLetter,SerialNumber,Model,DeviceID) ;
values ;
(wmiLogicalDisk.DeviceID,;
wmiDisk.SerialNumber,;
wmiDiskDrive.Model,;
wmiDiskDrive.DeviceID)
Endfor
Endfor
Endfor
Endfor
Browse


 
 
Ali Budiyono





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

Dear Sir,

I found this little code very useful, but it only works on 1st Harddisk (Primary Master).

Anyway, thanks a lot.

I have also changed your code a little bit to meet the need in my program.

Here is the code:

FUNCTION HDSN && Hard Disk Serial Number
xWMI = getobject("winmgmts:")
xDisks = xWMI.InstancesOf("Win32_PhysicalMedia")

FOR each xDisk in xDisks
HDSN=xDisk.SerialNumber
EXIT
NEXT

HDSN=ALLTRIM(HDSN)

IF HDSN='XXXXXXXXXXXXX' &&& If HDSN matches
RETURN &&& return to the caling program and continue
ENDI

QUIT &&&& HDSN doesn't match


 
 
Ali Budiyono





PostPosted: Visual FoxPro General, Detect hard diskk serial number. Top

This code only works on WinXP,

what about the code in WinMe or Win98

Please, let me know .....