Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture W2K current USERID & Group & pass into a table 1

Status
Not open for further replies.

dctii

IS-IT--Management
Nov 18, 2002
4
HU
Colleagues:
Using Access 2000, I need to capture the Windows 2000 userid (such as from whoami.exe) and group memberships in a form field and post it to a table when a record is edited.
How do I do this?
(I seem to remember this as a part of the concept of System Calls in Access 95, but can find no ref to it in Access 2000 or XP/2002.)
Thanks!
 
environ("UserName") will display the userid. To determine if a user belongs to a group, check out this thread thread702-477258

 
I use the following functions to make API calls to determine the "username", the identification of the computer name from which they logged in on. This would be the name that they used to login to their computer. The results of these functions can either be used to write this info to a table or used in a lookup to determine which group they belong to.

There are probably several different methods of doing this but this is the method that I use.
********* CODE BELOW *********

Option Explicit

Private Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As _
String, nSize As Long) As Long
Private Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetComputerName() As String
On Error GoTo ErrorHandler
Dim Username As String * 255
Call GetComputerNameA(Username, 255)
GetComputerName = Left$(Username, InStr(Username, Chr$(0)) - 1)

Exit Function
ErrorHandler:
'Call ErrMsg

End Function

Public Function GetCurrentUserName() As String
On Error GoTo ErrorHandler
Dim lpBuff As String * 25
Dim ret As Long, Username As String
ret = GetUserName(lpBuff, 25)
Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
GetCurrentUserName = Username & ""

Exit Function
ErrorHandler:
'Call ErrMsg
End Function
 
Thanks FancyPrairie, and JesseBalk.
The API calls solved two of my three problems. I now have the Username/UserID and the Machine Name. I am still lacking the Windows 2000 Server group memberships (which I want to use to grant particular users of my database access to appropriate functions within the database.)
Your tips led me on a search for this info in other APIs, and I found nothing. However, whoami.exe, a free download from MS, can output these memberships, and I should be able to parse the output for the existence of the appropriate group name.
I am avoiding using Access' internal security elements, as I don't want extra work that duplicates the security already in the operating system.
Thanks again for your timely and accurate help!
dctii
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top