Code Error On User PC (1 Viewer)

Ashfaque

Student
Local time
Today, 22:05
Joined
Sep 6, 2004
Messages
894
I have below code to read serial number of pc to whom I am delivering my FE

Code:
Function GetSerialNumber(strDrive As String) As Long
    Dim SerialNum As Long
    Dim Res As Long
    Dim Temp1 As String
    Dim Temp2 As String
    Temp1 = String$(255, Chr$(0))
    Temp2 = String$(255, Chr$(0))
    Res = GetVolumeInformation(strDrive, Temp1, _
    Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
    GetSerialNumber = SerialNum
End Function

But it produces error on SerialNum.

DO you think I should add PtrSafe and LongPtr to this code? I tried that way to but nothing happens.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:35
Joined
Oct 29, 2018
Messages
21,468
Where would you add PtrSafe in that code? What was the error message?
 

Ranman256

Well-known member
Local time
Today, 12:35
Joined
Apr 9, 2015
Messages
4,337
do you have:
Code:
#If Win64 Then 
Private Declare  PtrSafe Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

#else
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
#End If
 

Isaac

Lifelong Learner
Local time
Today, 09:35
Joined
Mar 14, 2017
Messages
8,777
You have declared SerialNum as a long. Then you use it as a parameter in something else. But you haven't assigned anything to it yet! This makes no sense
 

Ashfaque

Student
Local time
Today, 22:05
Joined
Sep 6, 2004
Messages
894
do you have:
Code:
#If Win64 Then
Private Declare  PtrSafe Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

#else
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
#End If
Sorry for my late reply.

Where the above code you want me to place? At the beginning? Means after Option Explicit
 

Users who are viewing this thread

Top Bottom