Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hard disk serial number

Status
Not open for further replies.

Yeap

Programmer
Jul 5, 2004
12
RO
I want to proctect my programm. Is there a function to get the
hard disk's serial number?
 
FUNCTION ReadSerial()
** This function will retrive the HDD serial number! and return it back to the calling function

LOCAL lpRootPathName, ;
lpVolumeNameBuffer, ;
nVolumeNameSize, ;
lpVolumeSerialNumber, ;
lpMaximumComponentLength, ;
lpFileSystemFlags, ;
lpFileSystemNameBuffer, ;
nFileSystemNameSize

lpRootPathName = LTRIM(SYS(5))+"\" && Drive and directory path (e.g. C:\)
lpVolumeNameBuffer = SPACE(256) && lpVolumeName return buffer
nVolumeNameSize = 256 && Size of/lpVolumeNameBuffer
lpVolumeSerialNumber = 0 && lpVolumeSerialNumber buffer
lpMaximumComponentLength = 256
lpFileSystemFlags = 0
lpFileSystemNameBuffer = SPACE(256)
nFileSystemNameSize = 256

DECLARE INTEGER GetVolumeInformation IN Win32API AS GetVolInfo ;
STRING @lpRootPathName, ;
STRING @lpVolumeNameBuffer, ;
INTEGER nVolumeNameSize, ;
INTEGER @lpVolumeSerialNumber, ;
INTEGER @lpMaximumComponentLength, ;
INTEGER @lpFileSystemFlags, ;
STRING @lpFileSystemNameBuffer, ;
INTEGER nFileSystemNameSize

RetVal=GetVolInfo(@lpRootPathName, @lpVolumeNameBuffer, ;
nVolumeNameSize, @lpVolumeSerialNumber, ;
@lpMaximumComponentLength, @lpFileSystemFlags, ;
@lpFileSystemNameBuffer, nFileSystemNameSize)

cSerial = TRANSFORM(lpVolumeSerialNumber,'@0x') && convert it to hex XXXX-XXXX
RETURN (SUBSTR(cSerial,3,4)+'-'+subSTR(cSerial,7,4))

or you can just:
Return lpVolumeSerialNumber (numeric)

Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
Tanks so much for the code. But i have foud one problem :
the volume serial number returned(lpvolumeserialnumber)
was returned negative. I had to make it positive so that
transform would work(it only accepts positive numbers).
The serial number returned was: 7bdd-db0a. How can i verify
this? and if is not the correct serial number what is there
something wrong?
 
i have just veryfied the serial number and it's not good
it's E0C7-5E49
 

I think depending on the method you use to get the serial number, you may get a different answer as it always depends on what is considered to be "a hard disk serial number". I notice that Ali get you a solution to retreive the Volume serial number of a hard disk which may be a different value as the "hard disk serial number" (since hard disks might be FDISKed into 2 or more volumes. I have tested Ali's suggestion, and I get a certain value, and I have used the following two methods and I get 3 different values.

1. Enumerating Disk Drive Properties Using FSO
Code:
On Error *
Clear
lcComputer = "."
loFSO = Createobject("Scripting.FileSystemObject")
Clear
colDrives = loFSO.Drives
For Each loDrive In colDrives
	?"Available space: " + Transform(loDrive.AvailableSpace)
	?"Drive letter: " + loDrive.DriveLetter
	?"Drive type: " + Iif(loDrive.Drivetype=1,"External",;
		IIF(loDrive.Drivetype=2,"Hard disk","CD ROM"))
	?"File system: " + loDrive.FileSystem
	?"Free space: " + Transform(loDrive.FreeSpace)
	?"Is ready: " + Transform(loDrive.IsReady)
	?"Path: " + loDrive.Path
	?"Is this a Root folder: " + Transform(loDrive.RootFolder.IsRootFolder)
	[b]?"Serial number: " + Transform(loDrive.SerialNumber)[/b]
	?"Share name: " + loDrive.ShareName
	?"Total size: " + Transform(loDrive.TotalSize)
	?"Volume name: " + loDrive.VolumeName
Next

2. Enumerating Logical Disk Drive Properties
Code:
lcComputer = "."
CLEAR 
loWMIService = GetObject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colDisks = loWMIService.ExecQuery ;
("Select * from Win32_LogicalDisk")
For each loDisk in colDisks
?"Compressed: " + chr(9) +  TRANSFORM(loDisk.Compressed)
?"Description: " + chr(9) +  loDisk.Description
?"DeviceID: " + chr(9) +  loDisk.DeviceID
?"DriveType: " + chr(9) +  TRANSFORM(loDisk.DriveType)
?"FileSystem: " + chr(9) +  loDisk.FileSystem
?"FreeSpace: " + chr(9) +  loDisk.FreeSpace
?"MediaType: " + chr(9) +  TRANSFORM(loDisk.MediaType)
?"Name: " + chr(9) +  loDisk.Name
?"QuotasDisabled: " + chr(9) +  loDisk.QuotasDisabled
?"QuotasIncomplete: " + chr(9) +  loDisk.QuotasIncomplete
?"QuotasRebuilding: " + chr(9) +  loDisk.QuotasRebuilding
?"Size: " + chr(9) +  loDisk.Size
?"SupportsDiskQuotas: " + chr(9) + ;
TRANSFORM(loDisk.SupportsDiskQuotas)
?"SupportsFileBasedCompression: " + chr(9) + ;
TRANSFORM(loDisk.SupportsFileBasedCompression)
?"SystemName: " + chr(9) +  loDisk.SystemName
?"VolumeDirty: " + chr(9) +  TRANSFORM(loDisk.VolumeDirty)
?"VolumeName: " + chr(9) +  loDisk.VolumeName
[b]?"VolumeSerialNumber: " + chr(9) +  ;
loDisk.VolumeSerialNumber[/b]
Next



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Have you searhed for similar posts to see what issues you may encounter? Here is a sampling just on this VFP forum, so there may be more elsewhere. Keep in mind that if some of the computer's hardware is replaced on the computer, such as a new hard drive or a new NIC card, you may have to recreate your password.

thread184-756938
thread184-749787
thread184-520931
thread184-137380
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top