Getting Computer name and User Name

J

Jan G. Thorstensen

Getting Computer name and User Name
-----------------------------------------
Is it possible to get the name of the Computer using vba?
(i.e. debug.print computerName) PS.

How can you get the user name from the loged in user in a network
(without using application.username)?

What I want to know is who is the person using my program and
which PC is he or she using.

Thank you for helping.


Jan
 
B

Bob Phillips

debug.print environ("computername")

and

debug.print environ("username")

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
J

Jan G. Thorstensen

Thank you so much!
That did the trick...

Jan

Bob Phillips said:
debug.print environ("computername")

and

debug.print environ("username")

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
G

Guest

Hi Tom
Is alvin
I have try this but i don't know how to get it to work

Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function ReturnUserName() As String
' returns the NT Domain User Name
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetUserName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen > 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnUserName = UCase(Trim(tString))
End Function

How to i call the function and how do i get the username
i believe the username is in Returnusername?

Alvin


"Tom Ogilvy" skrev:
 
H

Harald Staff

Note that the environ approach won't work with Windows 95 / 98 / ME. Not
sure about OSX.

Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top