The following codes uses a WinAPI-Call to GetVolumeInformationA to read out the volume serial number that the operating system assigns when a hard disk is formatted, like the command VOL. It runs as awaited unter Windows 7 but fails now under Windows 10, where it worked some months ago. However I am not certain wether it is a windows issue. I would be grateful if somebody could test it.
PROGRAM SerialNumber
USE mswin, ONLY : GetVolumeInformation
USE ISO_FORTRAN_ENV, ONLY : COMPILER_VERSION
IMPLICIT NONE
INTEGER(KIND=4) :: VolumeSerialNumber, MaxCompLength, FileSystemFlags, FileSystemNameSize, VolumeNameSize
CHARACTER(LEN=256) :: VolumeName, FileSystemName, PathName='C:'
LOGICAL(KIND=3) :: Res
Res=GetVolumeInformation(PathName, VolumeName, VolumeNameSize, VolumeSerialNumber, &
& MaxCompLength, FileSystemFlags, FileSystemName, FileSystemNameSize)
WRITE(*,'(1X,L1)') Res
WRITE(*,'(1X,A,Z8)') 'Volume Serial Number is ', VolumeSerialNumber
WRITE(*,*) 'Volumename is ', TRIM(VolumeName)
WRITE(*,*) 'Filesystem is ', TRIM(FileSystemName)
WRITE(*,*) 'Compiler is ', COMPILER_VERSION()
END PROGRAM SerialNumber
Output under Windows 7
T Volume Serial Number is 2A7F77E6 Volumename is Filesystem is NTFS Compiler is FTN95 v8.71
Output under Windows 10
F Volume Serial Number is 0 Volumename is Filesystem is 5%jöAd< Compiler is FTN95 v8.71