Solved

How to capture current user name?

Posted on 1998-05-12
4
186 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help me. 3 77
Publisher:   Unknown     VB.exe Application 1 31
Copy a range from 1..n excel sheets to one destination sheet 2 71
Macro problems with Excel file 6 51
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 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