![]() |
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 |
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 |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 02:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com