라이선스를 만들기 위해 하드 디스크의 볼륨 키를 가져오는 함수를 만들었는데 공유 해본다.
VB
Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" ( _
ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
ByRef lpVolumeSerialNumber As Long, _
ByRef lpMaximumComponentLength As Long, _
ByRef lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long _
) As Long
Public Function ProcGetVolKey(sDrive As String) As String
On Error GoTo err
Dim nVS As Long
If GetVolumeInformation(sDrive & ":\", vbNullString, 0&, nVS, ByVal 0&, ByVal 0&, vbNullString, 0&) Then
ProcGetVolKey = Left$(Hex$(nVS), 4) & "-" & Mid$(Hex$(nVS), 5, 4)
Else
ProcGetVolKey = "0000-0000"
End If
Exit Function
err:
ProcGetVolKey = "0000-0000"
End Function