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!

API method or instruction

Status
Not open for further replies.

madhatter2002

Programmer
Nov 6, 2002
73
PH
Does anybody know how to get the Hard disk serial number using VFP???
 
How about this:
( Notice that this returns a number representing the serial number of the drive, But the DIR command shows it in HEX, hyphenated between two WORDs )
Code:
FUNCTION GetSerialNumber
LPARAMETERS pcDrive
DECLARE SHORT GetVolumeInformation IN kernel32; 
    STRING    lpRootPathName,; 
    STRING  @ lpVolumeNameBuffer,; 
    INTEGER   nVolumeNameSize,; 
    INTEGER @ lpVolumeSerialNumber,; 
    INTEGER @ lpMaximumComponentLength,; 
    INTEGER @ lpFlags,; 
    STRING  @ lpFileSystemNameBuffer,; 
    INTEGER   nFileSystemNameSize 

*!*	BOOL GetVolumeInformation(
*!*	  LPCTSTR lpRootPathName,           // root directory
*!*	  LPTSTR lpVolumeNameBuffer,        // volume name buffer
*!*	  DWORD nVolumeNameSize,            // length of name buffer
*!*	  LPDWORD lpVolumeSerialNumber,     // volume serial number
*!*	  LPDWORD lpMaximumComponentLength, // maximum file name length
*!*	  LPDWORD lpFileSystemFlags,        // file system options
*!*	  LPTSTR lpFileSystemNameBuffer,    // file system name buffer
*!*	  DWORD nFileSystemNameSize         // length of file system name buffer
*!*	)
LOCAL lcDrive, lcVolName,lnSerialNum,lnComp,lnFlags,lcFileSystemName
lcDrive     = iif(vartype(pcDrive)='C',pcDrive,Set('DEFAULT'))
do case
  case len(lcDrive)=1
    lcDrive = lcDrive + ':\'
  case len(lcDrive)=2
    lcDrive = lcDrive + '\'
endcase  
lcVolName   = space(100)
lnSerialNum = 0
lnComp      = 0 
lnFlags     = 0
lcFileSystemName = space(100)

IF 0=GetVolumeInformation( lcDrive, @lcVolName, 100, ;
        @lnSerialNum, @lnComp, @lnFlags, @lcFileSystemName, 100 )
  lnSerialNum = 0xFFFFFFFF
endif
return lnSerialNum
ENDFUNC
 
Thanks wgcs,

would either of you have something for the win95/98 os that can also work with other versions of windows??
 
What's a "different thing"? It is the same number shown to me when I go to that drive and type "DIR"... only the DIR command shows it at the top in Hex and a Hyphen, for example, my C: drive DIR listing shows:

Code:
 Volume in drive C has no label.
 Volume Serial Number is 3912-8833

 Directory of C:
02/23/2000  09:48a      <DIR>          WINNT
02/23/2000  09:51a      <DIR>          Documents and Settings
etc...

and GetSerialNumber(&quot;C:&quot;) returns 957515827, which, if you use any hexadecimal-capable calculator, is represented in hex as &quot;39128833&quot; ... add the hyphen, and it's identical. The drive serial number is just a DWORD numeric value.

As for Win98, the MSDN documentation on the GetVolumeInformation function says:

Code:
  Windows NT/2000 or later: Requires Windows NT 3.1 or later.
  Windows 95/98/Me: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
 
Just a side note. ?0x39128833 returns 957515827, so you can use:

STORE STR(0x39128833) TO nSerial
?nSerial

Dave S.
[cheers]
 
Just to add to this discussion, I discovered a freeware .DLL a while back, that will give you the &quot;real&quot; physical disk serial number - not the easily changed logical disk serial number. I've posted it and a sample usage .PRG at our local user group web site -
Note: If you go to there seems to be a similar DLL (but different - a later version?) to the one I was using - it has &quot;nag&quot; messages if you don't register it. You just have to read a bit of Chinese (or at least between the lines! :) ).

Rick
 
Here's another way to get the serial number I stumbled across:

fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
nSerial = fso.GetDrive(fso.GetDriveName('C:')).SerialNumber
?nSerial
Dave S.
[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top