?
Solved

MS Access, VB, Accessing NT User account & ACL

Posted on 2003-12-12
2
Medium Priority
?
1,048 Views
Last Modified: 2007-12-19
Hello,

I'm fairly new to programming VB in MS Access.

I was wondering if/how I can access info. regarding the NT User Account of the person accessing the database?? (ie, what is their login name, what groups are they a member of, etc).

I need this for some security mechanisms I'm working on within access.

Any assistance would be greatly appreciated.

Thanks!
SoN][c

PS Environment would be Active Directory (2000 or 2003), and clients would be Windows 2000 Pro or XP Pro.
0
Comment
Question by:soniic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:bossjohnc
ID: 9928962
Hi,

Take a look at some of Dev Ashish's NT account access APIs - here's one that gets the domain...

http://www.mvps.org/access/api/api0040.htm

If you search using "NT Account" as the criteria (on his site) then it should bring up a few more.

0
 
LVL 39

Accepted Solution

by:
stevbe earned 375 total points
ID: 9929952
here is a couple

Option Explicit

Declare Function GetComputerNameEx Lib "kernel32.dll" Alias "GetComputerNameExA" (ByVal NameFormat As Long, ByVal Buffer As String, Size As Long) As Long
Declare Function GetComputerNameAPI Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal Buffer As String, Size As Long) As Long
Declare Function GetComputerObjectName Lib "secur32.dll" Alias "GetComputerObjectNameA" (ByVal NameFormat As Long, ByVal Buffer As String, Size As Long) As Long
Declare Function GetTickCount Lib "kernel32.dll" () As Long
Declare Function GetUserNameAPI Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function CoImpersonateClient Lib "ole32.dll" () As Long
Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" (ByVal UserName As String, ByVal Domain As String, ByVal Password As String, ByVal LogonType As Long, ByVal LogonProvider As Long, Token As Any) As Long
Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal Token As Long) As Long
Declare Function CloseHandle Lib "kernel32.dll" (ByVal Token As Long) As Long
Declare Function CoRevertToSelf Lib "ole32.dll" () As Long
Declare Function RevertToSelf Lib "advapi32.dll" () As Boolean
Declare Function timeGetTime Lib "winmm.dll" () As Long

'/ COMPUTER_NAME_FORMAT enumeration
Public Const ComputerNameNetBIOS = 0
Public Const ComputerNameDnsHostname = 1
Public Const ComputerNameDnsDomain = 2
Public Const ComputerNameDnsFullyQualified = 3
Public Const ComputerNamePhysicalNetBIOS = 4
Public Const ComputerNamePhysicalDnsHostname = 5
Public Const ComputerNamePhysicalDnsDomain = 6
Public Const ComputerNamePhysicalDnsFullyQualified = 7
Public Const ComputerNameMax = 8

'/ EXTENDED_NAME_FORMAT enumeration
Public Const NameUnknown = 0
Public Const NameFullyQualifiedDN = 1
Public Const NameSamCompatible = 2
Public Const NameDisplay = 3
Public Const NameUniqueId = 6
Public Const NameCanonical = 7
Public Const NameUserPrincipal = 8
Public Const NameCanonicalEx = 9
Public Const NameServicePrincipal = 10

'/ LogonUser enumerations
Public Const LOGON32_LOGON_INTERACTIVE = 2
Public Const LOGON32_LOGON_NETWORK = 3
Public Const LOGON32_LOGON_BATCH = 4
Public Const LOGON32_LOGON_SERVICE = 5

Public Const LOGON32_PROVIDER_DEFAULT = 0
Public Const LOGON32_PROVIDER_WINNT35 = 1
Public Const LOGON32_PROVIDER_WINNT40 = 2
Public Const LOGON32_PROVIDER_WINNT50 = 3

Public Function GetDomainName() As String
    Dim lLength As Long
    Dim lRet As Long
   
    GetDomainName = String$(255, vbNullChar)
    lLength = 255
    lRet = GetComputerNameEx(ComputerNameDnsDomain, GetDomainName, lLength)
    If lRet = 0 Then
        '/ A return of 0 indicates failure ...
        GetDomainName = ""
    Else
        '/ A non-zero return indicates success.  Strip off trailing null characters ...
        GetDomainName = Left$(GetDomainName, lLength)
    End If
   
End Function

Public Function GetFQDN() As String
    Dim lLength As Long
    Dim lRet As Long
   
    GetFQDN = String$(255, vbNullChar)
    lLength = 255
    lRet = GetComputerObjectName(NameFullyQualifiedDN, GetFQDN, lLength)
    If lRet = 0 Then
        '/ A return of 0 indicates failure ...
        GetFQDN = ""
    Else
        '/ A non-zero return indicates success.  Find the first instance of "DC="
        '/ and take everything to the right ...
        GetFQDN = Left$(GetFQDN, lLength - 1)
        GetFQDN = Mid$(GetFQDN, InStr(1, GetFQDN, "DC="), lLength)
    End If
   
End Function

Public Function GetDNSHostName() As String
    Dim lLength As Long
    Dim lRet As Long
   
    GetDNSHostName = String$(255, vbNullChar)
    lLength = 255
    lRet = GetComputerNameEx(ComputerNameDnsHostname, GetDNSHostName, lLength)
    If lRet = 0 Then
        '/ A return of 0 indicates failure ...
        GetDNSHostName = ""
    Else
        '/ A non-zero return indicates success.  Strip off trailing null characters ...
        GetDNSHostName = Left$(GetDNSHostName, lLength)
    End If
   
End Function

Public Function GetComputerName() As String
    Dim lLength As Long
    Dim lRet As Long
   
    GetComputerName = String$(255, vbNullChar)
    lLength = 255
    lRet = GetComputerNameAPI(GetComputerName, lLength)
    If lRet = 0 Then
        '/ A return of 0 indicates failure ...
        GetComputerName = ""
    Else
        '/ A non-zero return indicates success.  Strip off trailing null characters ...
        GetComputerName = Left$(GetComputerName, lLength)
    End If
   
End Function

Public Function GetUserName() As String
    Dim lRet As Long
    Dim lLength As Long
   
    GetUserName = String$(255, vbNullChar)
    lLength = 255
    lRet = GetUserNameAPI(GetUserName, lLength)
    If lRet = 0 Then
        '/ A return of 0 indicates failure ...
        GetUserName = ""
    Else
        '/ A non-zero return indicates success.  Strip off trailing null characters ...
        GetUserName = Left$(GetUserName, lLength - 1)
    End If
   
End Function

Public Function LogonAsUser(ByVal UserAlias As String, _
                            ByVal Domain As String, _
                            ByVal Password As String, _
                            ByVal LogonType As Long, _
                            ByVal LogonProvider As Long, _
                            Token As Long) _
                    As Boolean

    Dim lRet As Long

    lRet = LogonUser(UserAlias, Domain, Password, LogonType, LogonProvider, Token)
    If lRet = 0 Then
        LogonAsUser = False
    Else
        LogonAsUser = True
    End If

End Function

Steve
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question