capturing NT UserName

snapdrag0n420
snapdrag0n420 used Ask the Experts™
on
How can I capture the NT (or 2000) UserName (logon) in a VB application.  I need to be able to do this without the user knowing it is being done.  Just need a string variable to hold it.  Should be easy, but I can't find it in my reference books.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can use the Environ function:

Dim StrUser as String

strUser = Environ("UserName")

or it might be

Environ("LogonName")

don't have VB installed here, so I can't tst it to be sure

Arthur Wood

Commented:
Environ("UserName") is the one you want.
If you want to find out about more user info, see the code here:
http://216.26.168.92/vbsquare/api/ntvb/index2.html

Commented:
Other API functions for retrieving the user name is at http://www.allapi.net/apilist/GetUserName.shtml

Thanks

Ryan

Author

Commented:
Sorry about the delay, I just figured out how to give points for comments.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial