Solved

MS Access, VB, Accessing NT User account & ACL

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
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…

791 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