Solved

MS Access, VB, Accessing NT User account & ACL

Posted on 2003-12-12
2
1,008 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
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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

861 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

22 Experts available now in Live!

Get 1:1 Help Now