Network User and Computer Name - December 1999

Some time ago I wrote a routine to return the network user name. I noticed that this is a common question on the Devx news group. So I revisited the code, updated it, and put the code in a class module. So this becomes the tip-of-the-month.

2000/12/06 - I updated the class module recently to also supply the computer name. That code is now available when you download the updated module.

2002/06/06 - Support added for VB.Net. The code uses native VB.Net architecture. No API's.

The Demo Program

I wrote a VB6 demo program to show how the class module works. The demo program:

Network User Name - VB 6 Version
VB 6 Version

Network User Name - VB.Net Version
VB.Net Version

Using the Class Module

Dim objNetUserName As New clsNetUserName    'define a reference to the class
Text1.Text = objNetUserName.NetworkUserName 'get user name
Text2.Text = objNetUserName.ComputerName    'get computer name

Include in Your Code

Include class module 'clsNetUserName.cls' in your application for VB 6, or 'clsNetUserName.vb' for VB.Net.

The Demo Uses Module modConnectToWebSite or Class BGWebConnect

The VB 6 demo program uses 'modConnectToWebSite.bas' to display this page. For details on the use of that module click here. The VB.Net version uses 'BGWebConnect.vb' for the same purpose.

Download VB Code

Click here to download the VB 6 Source Code [5k].
here to download the VB.Net Source Code [12k].

Previous Tip   Tip Index   Next Tip


Updated 2002/10/15