How can do I get Network User ID in the MSAccess?

G

Guest

Is there any function or command to get the network UserID (not the database
user id) within a database form? I remember using it in earlier versions of
Access but can not seems to find it in the 2003. Any help will be greatly
appreciated.
 
G

Guest

Try creating a module, name it CurrentUser and paste te following into the
module:

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function


Then you can use something like this in your control:

="Record last modified on " & [DateModified] & " by " & fOSUserName()
 
G

Guest

Ooops...you will also want to add this to your module at the top:

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

--
Randy Street
Rancho Cucamonga, CA


Randy said:
Try creating a module, name it CurrentUser and paste te following into the
module:

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function


Then you can use something like this in your control:

="Record last modified on " & [DateModified] & " by " & fOSUserName()

--
Randy Street
Rancho Cucamonga, CA


Damone said:
Is there any function or command to get the network UserID (not the database
user id) within a database form? I remember using it in earlier versions of
Access but can not seems to find it in the 2003. Any help will be greatly
appreciated.
 
T

Tony Toews [MVP]

dhabtem1 said:
you might want to try:
Environ("USERNAME")

or

Environ("COMPUTERNAME")

Trouble is that can be spoofed.

The risk appears to only happen if you open the command prompt, change
the environment variable and then execute the msaccess.exe from that
command prompt. A daunting task for 99.99% of the users

Changing the environment variable in the command prompt does not
affect other programs that you start from Windows. But only from
that particular command prompt.

However that 00.01% of the users that know about this could also be
the malicious users who want to blame data problems on other people.

Hmmm, being the sneaky bugger that I am I'd put a check in to compare
the value of the environment variable against the API call. If
different without an exceedingly good reason that'd be grounds to
terminate the employee.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
G

Guest

To follow up on the above, knowing that we can get the userID from a windows
server, can it be possible to get the same info from a different server like
Novell for example ?
How can I found out from code in Access which is the network environnement a
client is using, is there some function already existing for this this kind
of userid retreival or can this be done only from a windows network
environnement?
 
P

Pat Hartman

You might also be able to use the environment variables:

MyID = Environ("UserName")
MyComputer = Environ("ComputerName")

I have found these to be reliable but that may be because I work mostly for
large clients who have staff that keep the hardware/software configurations
up to date.
 
T

Tony Toews [MVP]

Pat Hartman said:
You might also be able to use the environment variables:

MyID = Environ("UserName")
MyComputer = Environ("ComputerName")

Pat

Didn't you read my comments about how that can be spoofed?

Tony

--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
P

Pat Hartman

I know you can change them but I don't see that as a big risk with most
users, especially in large companies where the PCs tend to be locked down.
Also, most of my back ends are SQL server, Oracle, or DB2 and so even
changing the user name won't get you into the back end because you still
need the password. I will be sure to add a stronger caveat should I
recommend this method again. Thanks:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top