#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Who Am I?

Could someone please tell me how I can find out what my network login name
is in VBA?

I do it all the time in .net, but there's no 'Import' in vba and I haven't a
clue what to reference to be able to get the current user's network name
(not the application username).

I thought I almost had it with:

Set orootDSE = GetObject("LDAP://rootDSE")
MsgBox orootDSE.get("currentuid")

but 'currentuid' isn't correct.

Thanks,

Exasperated


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Who Am I?

Ross,

You can use a function like the following:

Function MyUserName() As String
MyUserName = Environ("UserName")
End Function

I have seen on rare occassion the Environ return an empty string. The
following code is a wee bit more complex but will always work.

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

Function MyUserNameAPI() As String
Dim UName As String
Dim L As Long
Dim R As Long
L = 255
UName = String$(L, vbNullChar)
R = GetUserName(UName, L)
MyUserNameAPI = Left(UName, L - 1)
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Ross Culver" wrote in message
...
Could someone please tell me how I can find out what my network login name
is in VBA?

I do it all the time in .net, but there's no 'Import' in vba and I haven't
a clue what to reference to be able to get the current user's network name
(not the application username).

I thought I almost had it with:

Set orootDSE = GetObject("LDAP://rootDSE")
MsgBox orootDSE.get("currentuid")

but 'currentuid' isn't correct.

Thanks,

Exasperated


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Who Am I?

On Oct 9, 5:43 pm, "Ross Culver" wrote:
Could someone please tell me how I can find out what my network login name
is in VBA?

I do it all the time in .net, but there's no 'Import' in vba and I haven't a
clue what to reference to be able to get the current user's network name
(not the application username).

I thought I almost had it with:

Set orootDSE = GetObject("LDAP://rootDSE")
MsgBox orootDSE.get("currentuid")

but 'currentuid' isn't correct.

Thanks,

Exasperated


Try:
Environ("username")

or:
http://www.exceltip.com/st/Function_...Excel/452.html

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Who Am I?

See if this works.

_____________________________

Set objNetwork = CreateObject("WScript.Network")
strUser = objNetwork.UserName
MsgBox strUser
______________________________

Steve



"Ross Culver" wrote in message
...
Could someone please tell me how I can find out what my network login name
is in VBA?

I do it all the time in .net, but there's no 'Import' in vba and I haven't
a clue what to reference to be able to get the current user's network name
(not the application username).

I thought I almost had it with:

Set orootDSE = GetObject("LDAP://rootDSE")
MsgBox orootDSE.get("currentuid")

but 'currentuid' isn't correct.

Thanks,

Exasperated



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Who Am I?

Thank you! This really shouldn't be so difficult!

Thanks again.


"Chip Pearson" wrote in message
...
Ross,

You can use a function like the following:

Function MyUserName() As String
MyUserName = Environ("UserName")
End Function

I have seen on rare occassion the Environ return an empty string. The
following code is a wee bit more complex but will always work.

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

Function MyUserNameAPI() As String
Dim UName As String
Dim L As Long
Dim R As Long
L = 255
UName = String$(L, vbNullChar)
R = GetUserName(UName, L)
MyUserNameAPI = Left(UName, L - 1)
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Ross Culver" wrote in message
...
Could someone please tell me how I can find out what my network login
name is in VBA?

I do it all the time in .net, but there's no 'Import' in vba and I
haven't a clue what to reference to be able to get the current user's
network name (not the application username).

I thought I almost had it with:

Set orootDSE = GetObject("LDAP://rootDSE")
MsgBox orootDSE.get("currentuid")

but 'currentuid' isn't correct.

Thanks,

Exasperated






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Who Am I?

You can use WMI as following

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")

Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
Wscript.Echo "Logged-on user: " & objComputer.UserName
Next

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"