Solved

MS Access, VB, Accessing NT User account & ACL

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

776 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