locked
Get domainname with VBA RRS feed

  • Question

  • I want to check if a computer actually falls within a given domain (of a server). I think this is possible with the Drive object and the DriveType property. I don't have a server and therefore I can't test. Plus I'm not fully aware of servers and domain names.

    Situation:
    The Access BackEnd is placed on a server. On any computer that is associated with that server, an FrontEnd is placed and by the user by means of my own procedures linked to the BackEnd. At that time, the path to the BackEnd is known. So this is the normal state of affairs. No problem.

    The domain name I want to ask in advance to the customer and store it in the BackEnd so that it can be verified later.

    At the moment the FrontEnd is linked with the BackEnd, I want to verify if the computer with the FrontEnd belongs to the stored domain name (with other words: is a member within the domain name).

    Question:
    How do I get the domain name of the computer with the FrontEnd? I believe that this can be done by making use of the Drive object. The DriveType property has the constant Remote (# 3). If I have the answer to this question, I can use this to compare the previously stored domain name (Which the customer has provided for me).

    Thanks, Peter.

    Wednesday, February 24, 2016 1:13 PM

Answers

  • Hi, Peter van Loosbroek

    According to your description, please correct me if I have any misunderstandings on your question, you could try this:

    Sub DemoDomainName()
        Set wshNetwork = CreateObject("WScript.Network")
        strUserDomain = wshNetwork.UserDomain
        strCompName = wshNetwork.computername
        Debug.Print "User Domain: " & strUserDomain & vbNewLine & "Computer Name: " & strCompName
    End Sub

    For more information, click here to refer about WshNetwork Object

    Thursday, February 25, 2016 2:11 AM

All replies

  • Some code is in the download package at the bottom of this article: http://www.accesssecurityblog.com/post/2011/02/05/Securing-Access-databases-using-Active-Directory.aspx


    -Tom. Microsoft Access MVP

    Wednesday, February 24, 2016 1:46 PM
  • Hi Tom,

    Thanks for your response. Downloaded AD_sample.mdb. Your refering is to code which get the domain name. I'll study AD_sample.mdbwhere to found out and come back. I asume this is apart from Access security system for groups, because that is not my intention.

    Wednesday, February 24, 2016 3:56 PM
  • Hi, Peter van Loosbroek

    According to your description, please correct me if I have any misunderstandings on your question, you could try this:

    Sub DemoDomainName()
        Set wshNetwork = CreateObject("WScript.Network")
        strUserDomain = wshNetwork.UserDomain
        strCompName = wshNetwork.computername
        Debug.Print "User Domain: " & strUserDomain & vbNewLine & "Computer Name: " & strCompName
    End Sub

    For more information, click here to refer about WshNetwork Object

    Thursday, February 25, 2016 2:11 AM
  • Thanks David, this is where I was looking for.
    Thursday, February 25, 2016 9:51 AM