Is there a way to get the serialNumber of a harddisk in a field
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You can use the FileSystemObject:

Private Sub Command3_Click()
   Dim fso As New FileSystemObject, drv As Drive, s As String
   Set drv = fso.GetDrive(fso.GetDriveName("c:"))
   s = "Drive " & UCase("c:") & " - "
   s = s & drv.VolumeName & vbCrLf
   s = s & drv.SerialNumber & vbCrLf
   s = s & "Total Space: " & FormatNumber(drv.TotalSize / 1024, 0)
   s = s & " Kb" & vbCrLf
   s = s & "Free Space: " & FormatNumber(drv.FreeSpace / 1024, 0)
   s = s & " Kb" & vbCrLf
   MsgBox s
End Sub

  What version of Access is this for BTW?

fmewAuthor Commented:
I heard that if you could retrieve the serialnumber, then by a first time installation of an access application, this can be stored in the application.
So then, you can not copy the installation from that harddisk to an other harddisk. You would need the installation diskette
I have no idea how to do that, and I suppose one needs Office Developer Edition, which we do not have hear.

Sounds like you want to get a copy of Modern Software's TrialX.  It is a security program which does many things, one of which is to brand each copy of your app to the computer it is loaded on.  It will use the hard disk serial number, the cpu serial number, NIC serial number, plus anything else it can find that is a fixed part of the computer.  If the program is removed from that computer, the security software recognizes it and puts the user into trail mode for the number of days you set.  If they don't get back to you and get an unlock code, the program will shut down after the trial period.

You don't need the ODE to do any of this as long as the user has Access.  All the ODE does is register itself, keep anyone from seeing your code, and loading a copy of MSAccess.exe if the machine does not have a copy.

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

I tried the code above from JDettman, and my mchine refuses to recognize FileSystemObject.  Says, "User-Defined type not defined" . . .

But using an API, I got this to work:

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

Function SerNum(drv As String) As Long

    ' <-- Error handler.

    Dim VolNam         As String * 12   ' 11 characters + a terminating null.
    Dim vName          As String
    Dim VolNamSz       As Long
    Dim VolSerNum      As Long
    Dim VolMaxCompLen  As Long
    Dim SysFlgs        As Long
    Dim FilSysNamBuf   As String * 50   ' This is probably a bit excessive . . .
    Dim FileSystemName As String
    Dim FilSysNamBufSz As Long
    Dim Rtrn           As Long

    VolNamSz = 12           ' Tell the API the size
    FilSysNamBufSz = 50     ' of these 2 buffers.

    Rtrn = GetVolumeInformation(drv, _
                                VolNam, _
                                VolNamSz, _
                                VolSerNum, _
                                VolMaxCompLen, _
                                SysFlgs, _
                                FilSysNamBuf, _
    ' The buffers are padded right now.  This retrieves the info.
    vName = Left$(VolNam, InStr(VolNam, Chr$(0)) - 1)
    FileSystemName = Left$(FilSysNamBuf, InStr(FilSysNamBuf, Chr$(0)) - 1)
    ' Testing, testing, testing...
    Debug.Print "Drive "; drv; ":"
    Debug.Print "    Volume Name:   "; vName
    Debug.Print "    Serial Number: "; VolSerNum
    Debug.Print "    Maximum Component Length: "; VolMaxCompLen
    Debug.Print "    File System Name: "; FileSystemName
    SerNum = Rtrn
    ' Putting SerNum = VolSerNum here
    ' would allow you to use this
    ' Function in a textbox.ControlSource.

End Function

The nice thing about something like this API over the suggestion to use "Modern Software's TrialX" is that if the user buys a new computer, and puts their old hard drive into it, the software will still work, plus -- it's free!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fmewAuthor Commented:
Hang on BrianWren

I have to find a moment to try this
Wont forget it

Some people are fond of APIs.  I'm not particularly.  I'd rather pay a small amount of money for a great quality tool rather than spend the money and time to build my own.

TrialX, with their latest professional version, will allow you to either reset the code for this to accept the new hard drive or use a fuzzy lock which depends on a percentage of components not be changed at one time.  If the rest of the serial numbers are still the same, you can replace a CPU or hard drive without it complaining.  It will still work but will nag the user to get a new registration unlock.

If you are trying to lock the software to a hard drive and the hard drive is changed, then with the API, it will not work at all.

I think that all we are trying to do is to be sure that someone doesn't clone the product and sell or give it to their friends.  I don't mind if my users do.  It is free advertizing for me.  The person who got the cloned product will get to see how great it is for 30 days and then they have to get ahold of me to pay and register to continue using it.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:

  Sorry, I should have mentioned that the file system object is only available if you have certain software installed (I have Visual Studio and VB 6.0).  FileSystemObject is found in Scrrun.dll, which comes with certain packages.  This is covered in MSKB article Q186118 HOWTO: Use FileSystemObject with Visual Basic.

 I see the BrianWen proposed the GetVolumeInformation.  That will work, but be aware that GetVolumeInformation will not return the serial number of remote volumes and also has problems with UNC path names at times.

  A workaround is to open a file on the remote volume and use GetFileInformationByHandle() to get the volume serial number.  The code to do all this is in MSKB article Q234741.

  You can get this article via E-Mail by sending a message to mshelp@microsoft.com and putting the article number (Q#####) as the subject.


This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed.  Also a question is posted there specific to these changes that apply to the experts here.  Also, I am including the link to our All Topics, since many new ones have recently been added.

Thank you,
Moderator @ Experts Exchange
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.