Visual Basic Code of the Week (COTW)
Issue #122
Online Version at (paid subscribers only)
All content and source code is Copyright (c) 2000 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.

Issue topic: Retrieving the Windows 95/98/NT Username

Earn REAL money surfing the web!

If you would like to make some extra cash for surfing the web, jump to


In this Issue

In this issue we discuss how to retrieve the username used to login to Windows.

If you have any questions about using this module, let us know at


This module makes it easy to get the username used to login to Windows. This routine is most useful to avoid having to prompt your users with additional login information in your applications. You can use the built-in operating system security to provide authentication. This is most effective in Windows NT where security can be very high. One example of this is how Microsoft Outlook works.


Public Function LoginName() As String

Returns the username used to login to Windows. If an error occurs it will be raised to the calling routine.

Sample Usage

Simply shows a message box with the current username.

    MsgBox LoginName()

Source Code

To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address:

This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Get paid to surf the web!

If you would like to get paid for surfing the web, jump to

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945