Solved

MS Access, VB, Accessing NT User account & ACL

Posted on 2003-12-12
2
994 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
2 Comments
 
LVL 3

Expert Comment

by:bossjohnc
Comment Utility
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 125 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now