ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Username (https://www.excelbanter.com/excel-programming/311434-username.html)

Alvin Hansen[_2_]

Username
 
Hi!!
I use this
name = Environ("username")
Its work allright on a standalone PC but when i try on a PC there loog on to
a server then username is the name there been used when Windoes was install
first time. And not the "real" user

Hope someone can help

Best regards alvin


Bob Phillips[_6_]

Username
 
Alvin,

Try this

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

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left(sName, cChars - 1)
End If
End Function


--

HTH

RP

"Alvin Hansen" wrote in message
...
Hi!!
I use this
name = Environ("username")
Its work allright on a standalone PC but when i try on a PC there loog on

to
a server then username is the name there been used when Windoes was

install
first time. And not the "real" user

Hope someone can help

Best regards alvin




Jako[_86_]

Username
 

I was given this code ages ago and works fine:

Option Explicit


' Windows API Initialisation for the Log in Name

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

Function OSUserName() As String
Dim Buffer As String * 256
Dim BuffLen As Long
BuffLen = 256
If GetUserName(Buffer, BuffLen) Then _
OSUserName = Left(Buffer, BuffLen - 1)
End Function

Hope this is of help!

--
Jak
-----------------------------------------------------------------------
Jako's Profile: http://www.excelforum.com/member.php...nfo&userid=871
View this thread: http://www.excelforum.com/showthread.php?threadid=26345


Michel Pierron

Username
 
Hi Alvin,
Quite symply:
MsgBox CreateObject("Wscript.Network").UserName

MP

"Alvin Hansen" a écrit dans le
message de ...
Hi!!
I use this
name = Environ("username")
Its work allright on a standalone PC but when i try on a PC there loog on

to
a server then username is the name there been used when Windoes was

install
first time. And not the "real" user

Hope someone can help

Best regards alvin





All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com