>How can I get the volume serial number for my hard drive through VFP like I do when I type 'LABEL' in DOS? Thanks for any help
Hi Michael,
I got most of this source from somewhere - can't remember from where - probably UT.
The following source is the GetVolInfo method in my class VolInfo
There are 4 properties cDrive, cVolName, cVolSerNo & lResult.
load cDrive with the drive letter you want to query and call the GetVolInfo method. cVolName and cVolSerNo will return the Volume Name and Serial Number. As I recall, I had a problem getting volume details from a network drive but it worked fine for local drives. lResult (default value .F.) will result the succes or otherwise of the API call.
Hope this helps.
Liam
Local lpRootPathName, ;
lpVolumeNameBuffer, ;
nVolumeNameSize, ;
lpVolumeSerialNumber, ;
lpMaximumComponentLength, ;
lpFileSystemFlags, ;
lpFileSystemNameBuffer, ;
nFileSystemNameSize
If Empty(This.cDrive) Then
This.cDrive = "C:\"
Else
This.cDrive = Upper(This.cDrive)
If !Between(Substr(This.cDrive,1,1), "A", "Z") Then
This.cDrive = "C:\"
Endif
If Substr(This.cDrive, 2) != ":\" Then
This.cDrive = Substr(This.cDrive, 1, 1) + ":\"
Endif
Endif
lpRootPathName = This.cDrive && Drive and directory path
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)
If RetVal !=1 Then
Return
Endif
This.cVolName = LEFT(ALLTRIM(lpVolumeNameBuffer),LEN(ALLTRIM(lpVolumeNameBuffer))-1)
This.cVolSerNo = ALLTRIM(STR(lpVolumeSerialNumber))
This.lResult = .T.
Liam O'Hagan
MCP VFP Desktop Apps