Solved

How to capture current user name?

Posted on 1998-05-12
4
188 Views
Last Modified: 2006-11-17
How to capture the current user name on PC......the computer name
0
Comment
Question by:Roach051198
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
zsi earned 50 total points
ID: 1446127
Use the API function WNetGetUser()

I will post a working VB example here in a few...

zsi
0
 
LVL 4

Expert Comment

by:zsi
ID: 1446128
In your [declarations] section:

Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

In your code:
   Dim sName As String
   Dim sUserName As String * 20

   Call WNetGetUser(sName, sUserName, 20)
   MsgBox sUserName


Hope this helps!
zsi
0
 

Author Comment

by:Roach051198
ID: 1446129
Oh no!
A message box pop up:
"Compile error: Constants, fixed-length strings, arrays, and Declare statements not allowed as Public members of object modules"

I have no idea about API. Please help.
0
 
LVL 4

Expert Comment

by:zsi
ID: 1446130
When you put an API declaration (such as that one above) in a form, you must declare it as private, (by putting Private before the keyword Declare).  The function, however, will only be available to that form.

If you want the function to be available to the entire program, you have to move the declaration into a Bas file.  In fact, this is a good thing to do all of the time.

zsi
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question