Results 1 to 9 of 9
  1. #1
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36

    VBA Security Question

    Hi all,



    Is it possible the have access vba lookup the hdd serial or model number and record it to a table?

    I want to start by loading a form on startup, when the form loads it should find and display the hdd serial number or model number then automatically record it to the table, so that everytime the form loads it checks that the hdd serial or model number matchs the recorded one in the table.

    I have done a bit of research on this and can not seem to find the answer.

    any help would be appreciated.
    some code to do this would be great.
    Thanks in advance

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,930
    google environ.

    Can't remember exactly what it is but something like

    environ("machine") or environ("computername")

    not sure about hdd serial number - it may not be unique

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    From https://groups.google.com/forum/#!to...ks/mY3kkus2gfE

    Post by Michel Walsh (Vanderghast, Access MVP) on 9/19/2000 & 9/30/2000

    Need to set a reference to "Microsoft WMI Scripting 1.1 Library" (1.2 in Access 2010)
    Code:
    Public Function GetVolumeSerialNumber(Drive As String) As String
        Dim objs As WbemScripting.SWbemObjectSet
        Dim obj As WbemScripting.SWbemObject
    
        Set objs = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3 AND Name='" & Drive & "'")
        For Each obj In objs
            GetVolumeSerialNumber = obj.VolumeSerialNumber
            Exit For
        Next obj
    End Function
    Usage would be like:
    Code:
    Sub test()
        Dim tmp As Variant
    
        tmp = GetVolumeSerialNumber("C:")
        Debug.Print tmp
    End Sub
    Note the colon......

  4. #4
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    thanks for the reply ssanfu and Ajax,

    I will look at both ideas and test them, will keep you posted on outcome

  5. #5
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    Thanks ssanfu,

    your code you supplied worked, it displays the HDD Serial in a textbox that is on my form.

    What I would like that textbox to do, is to then automatically send that number to a table, with a text field called Serial, and the table is called tblHDD.
    then every time the database opens it checks the form textbox number with the number stored in the table and if the numbers do not match the an error msg is displayed. Example: " This Computer is Not Authorised to use this Software "
    and if this happens then the database will close.

    Hope you understand what I mean.

    Thanks again for your help so far

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK, modify your code so when the main form opens, it checks the table to see if there is a record in the table. If not, add the serial number and continue on.
    If a record exists, get the saved SN, get the SN of the hard drive and compare them. If not the same, display a message box and exit access.

  7. #7
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    Thanks for your reply ssanfu,

    would you have some example code to get it to do this, as I am not quite sure how to approach this way of doing things.

    Thanks again

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    No, sorry, I don't. Its not hard - how would you do it manually?
    Writing down the steps you would do manually is called pseudo code. The next step would be to start converting the pseudo code to VBA.

    I gave you most of the pseudo code. And you know what you want to do. Program away!!

    - the main form opens,
    - get the saved SN. (How?? open a recordset?? / use DLookup()??)
    - If no SN, add the serial number and continue on.

    - Else If a SN record exists,
    - get the SN of the hard drive and
    - compare them.
    - If not the same, display a message box and exit access
    - else continue on.


    Good luck.....

  9. #9
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    thanks again for your reply ssanfu,

    I am working on using the dlookup now, to look at the number, keep getting an error but I will work it out.

    Thanks again

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Database Security Question
    By princess12 in forum Access
    Replies: 12
    Last Post: 04-04-2015, 06:57 AM
  2. Access Security Question
    By Squint in forum Access
    Replies: 3
    Last Post: 01-23-2014, 10:41 AM
  3. Basic security question
    By Tari in forum Security
    Replies: 1
    Last Post: 03-20-2011, 05:02 PM
  4. Security question
    By maxx3 in forum Security
    Replies: 2
    Last Post: 01-14-2010, 05:27 PM
  5. User level security question
    By genesis in forum Security
    Replies: 1
    Last Post: 07-08-2009, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums