How do I capture a network LogonID?

  • Thread starter Thread starter Robert Bailey
  • Start date Start date
R

Robert Bailey

I need to add the network LogonID to data within an Access table for
recording purposes. How do I capture that LogonID? Is there a system field
that contains it?
 
I always cringe when people suggest using the USERNAME environment variable,
given how easy it is to reset.

Try the following. Open a command dialog (a "DOS box") and type

Set USERNAME=xxx

at the command prompt then hit enter.

Now, from within the same DOS box, open your database. (All you need do is
drag the file from Windows Explorer onto the DOS box and hit enter.) You'll
find that Environ("Username") returns xxx, not your user id. Now, it's true
that the value of the environment is only changed for sessions launched from
that DOS box, but still, given how easy it is to use the API, why not do it
properly?
 
So essentially.. it doesn't work if somebody intentionally makes it not work.
I'm not really sure how strong of an argument against using it that really
is, short of using it as a security control.

And, of course, the obvious reason to use it is because it's quick, simple
and easy. But to be complete..

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Function UserNameWindows() As String

Dim lngLen As Long
Dim strBuffer As String

Const dhcMaxUserName = 255

strBuffer = Space(dhcMaxUserName)
lngLen = dhcMaxUserName
If CBool(GetUserName(strBuffer, lngLen)) Then
UserNameWindows = Left$(strBuffer, lngLen - 1)
Else
UserNameWindows = ""
End If
End Function
 
I didn't include the code because Arvin had already given them a link to it
in his answer.

To me, there's no point storing data if you can't trust it. I'd rather have
no data than incorrect data.
 
The only reason for storing a username is to be able to retrieve it, usually
for reasons related to security. For instance, you may want the user only to
be able to see the records that they entered. Now if I can change "Lance" to
"Arvin" and see your records, it doesn't say much for the integrity of the
data. Using the API ensures that the person logging in at least knows how to
log in as someone else. That is another problem, of course, but nothing to
do with the data's integrity.
 

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

Back
Top