Solved

How to capture current user name?

Posted on 1998-05-12
4
149 Views
Last Modified: 2006-11-17
How to capture the current user name on PC......the computer name
0
Comment
Question by:Roach051198
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
zsi earned 50 total points
Comment Utility
Use the API function WNetGetUser()

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

zsi
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now