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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to read what user is logged into the computer??? 3

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
Is it possible to read the username of the person logged into the computer (we use win2000), & then append it to a field within a table? Ideally we need to track who edited any given record, but we don't want to have to log into Windows & then into Access. For this reason it would be really useful if we can just read who is logged into the computer & append that to the table..

Any suggestions??? James Goodman
j.goodman00@btinternet.com
 
Environ("UserName")

Joe Miller
joe.miller@flotech.net
 
Does win 2K REQUIRE a username login? I did not get there (yet?), so I do not know if this is a new 'feature' in win 2K, but at least as of win '98 there is no requirement that a login even be provided, or that one actually uses it even when the profiles are enabled. 'environ("UserName")' just returns an empty string if there was no login to the current session for most win vers.

Also, there is an excellent (pat on back, pat on back, pat on back, pat on back) faq on acccumulating the user activities in a transaction log for Ms. Access (faq181-291), however it wowuld require some modifications to use with a name derived from some other source.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
You can set Win2k to require a login if you wish, & to the best of my knowledge it does not allow a null to login. It can be setup so that it automatically logs in as a specific user, but again this user must already be declared & created by the system administrator....

I would imagine it is basically the same as NT, just with a slightly more user-friendly interface... James Goodman
j.goodman00@btinternet.com
 
Win2K requires a person/account to "log-in." But you can set it to log in for you automatically so it "appears" like Win9x. So there will always be a return by using this function. In Win9x, a username is not required so Environ() can fail. To return something.

Joe Miller
joe.miller@flotech.net
 
Since the environmental variable can be spoofed very easily (by overwriting it in a CMD window, then launching the code), this is what I always use:

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

Function UserName() As String
Dim lpBuffer As String * 255
Dim lRet As Long
lRet = GetUserName(lpBuffer, 255)
UserName = Left$(lpBuffer, InStr(1, lpBuffer, Chr(0))-1)
End Function

THen, in a form's beforeupdate, I'll set a field on the record to UserName().

Hope this helps.

Drew Hershkowitz
 
Joe,
How could I call this function across a network? I tried the code and it just gave me the local user account.
Thanks
Scott ::)
 
Drew's function will return that, did you try his code? Environ only works for the local account (which in Win2K, WinNT are usually the same as the network account).
Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top