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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read hard drive serial. Is posible for API in foxpro

Status
Not open for further replies.

sop

MIS
Aug 2, 2001
4
MX
I need to read the Hard Disk serial and save in a database automatically.

Any suggestions?

Thanks,

Frank
 
Unless I miss the main point of your question, regardless of the disk hardware interface (IDE, Serial, SCSI, etc.), as long as your drive is mapped within your workstation (example: F:, M:, K:, etc.) and accessible to other workstation applications, then your Foxpro application can read files from it and write data back to it also.

Remember that with the versions of Foxpro discussed in this forum (version 1 through 2.6) you will need to use the older 8.3 character representation of the directories and file names.

Example:
Instead of:
M:\MyDirectory\This SubDirectory\MyDatabase.DBF
Use
M:\MyDire~1\ThisSu~1\MyData~1.DBF

If you are asking about a different issue, please give us more detail so that we can better help you.

Good Luck,
JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
I can't remember how to redirect output from a DIR command, so I'll do it with a .BAT file:

!MyBat.bat

In MyBat.BAT:
DIR c:\99999999.999>c:\sn.txt

'99999999.999' or some other file name you don't think will be there.

Then in serial.prg:

Code:
USE MyTable
nHandle = FOPEN('C:\sn.txt')
IF nHandle < 0
   WAIT WINDOW 'Error opening file' TIMEOUT 1
   RETURN
ENDIF

DO WHILE !FEOF(nHandle)
   nStr = FGETS(nHandle)
   IF 'Serial Number' $ nStr
      STORE RIGHT(ALLTRIM(nStr), 9) TO cSN
      EXIT
   ENDIF
ENDDO
m.serial = cSN 
INSERT INTO serial FROM MEMVAR 
CLOSE ALL
Dave S.
[cheers]
 
A better and safer way of doing this without shelling out!

(This is for vfp7.0) I don'tk now if it works on older versions..

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))+&quot;\&quot; && 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))
Please let me know if this helped you :)

Tekno
Wireless Toyz
Ypsilanti, Michigan
 
TeknoSDS,

Up to version what, VFP 6 I think, you have to use FOXTOOLS.FLL to call any API or other .DLL stuff. Also, Fox 2.x is still 16 bit.
So your routine won't work.
Dave S.
[cheers]
 
Dave (Dsumzzz)
Thank you, I did not know that!

Another way you can do it is:

Func ReadSerial()
Run VOL > SER.SER && name of the file
nHandle = Fopen(&quot;SER.SER&quot;)
If Ferror() != 0
Return ''
Endif
Fseek(nHandle,-11,2)
SERIAL = FREAD(nHandle,9)
Fclose(nHandle)
Ferase(&quot;SER.SER&quot;)
Return Serial
Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top