?
Solved

How to capture current user name?

Posted on 1998-05-12
4
Medium Priority
?
191 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 200 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

770 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