hello,
is it possible to determine the windows(XP) log in name ?
hello,
is it possible to determine the windows(XP) log in name ?
[vba]
MsgBox Environ("UserName")
[/vba]
MsgBox Environ("USERNAME")I get the user name.
However I changed the user name in control panel/users to another name.
How can I get the name that is now displayed and not thhe origional user name ?
Is this possible ?
I am not about to change my username like that to test this, but you could try it
[vba]
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long
Function UserNameWindows()
Dim lngLen As Long
Dim strBuffer As String
Const dhcMaxUserName = 255
strBuffer = Space(dhcMaxUserName)
lngLen = dhcMaxUserName
If CBool(GetUserName(strBuffer, lngLen)) Then
UserNameWindows = Left$(strBuffer, lngLen - 1)
Else
UserNameWindows = ""
End If
End Function
[/vba]
Same result
How about this article from the KB?
Function to return various Environment Names
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
That suggests to me that the OS doesn't know about it even, and won't until next login, by which time the Environ option will work.Originally Posted by johnny44
This seems to do it...
Application.UserName
That is not the Windows (XP) login name as you originally said, it is internal to Excel and can be changed by the user at any time.Originally Posted by johnny44
Exactly.. the entry:
http://vbaexpress.com/kb/getarticle.php?kb_id=768
That shows the different methods available, and what it is pulling. Since they pull from the windows login, they won't change until the user logs off and logs back on. The Application.Username is the office name, and as Bob says the user can change that easily by many ways.
Matt
Well noted...
So how could I get the user XP log in name that shows on the XP login Screen ?
the reg key seems to be this one :
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Johnny
What happens when you log off and log in again? I'd bet it's updated to the new name then? If it is, how often do you expect this to happen?Originally Posted by johnny44
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
I dont want to create new XP users, So I changed the names on the various xp stations to reflect the current name of the user.
So if a profile was created as "john" and the the name is changed via control panel/user accounts/change account/change my name to "wilma"
I would need to capture the wilma value from my xp stations.
So far I can only get the john even though it has been changed to wilma.
I think I read that the only way is to re create the account. But I figured if XP shows wilma there must be a way to get that same value...
Well, here is another attempt (not holding my breath if the API version doesn't work).
[vba]
Private Declare Function GetEnvironmentVariable Lib "kernel32" _
Alias "GetEnvironmentVariableA" _
(ByVal lpName As String, _
ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Sub xx()
MsgBox GetEnvironmentVar("UserName")
End Sub
Function GetEnvironmentVar(Name As String) As String
GetEnvironmentVar = String(255, 0)
GetEnvironmentVariable Name, GetEnvironmentVar, Len(GetEnvironmentVar)
GetEnvironmentVar = TrimNull(GetEnvironmentVar)
End Function
Private Function TrimNull(item As String)
Dim iPos As Long
iPos = InStr(item, vbNullChar)
TrimNull = IIf(iPos > 0, Left$(item, iPos - 1), item)
End Function
[/vba]
Sory...did not work...still gave ne the "origional" name of account
I think the only way is to get from registrie ?
Can you just confirm? You definately logged out and back in under the new name, correct?Originally Posted by johnny44
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Yes I re booted and I the sub still returns the "Origional" name
I find that hard to believe. That is akin to saying that logon as another user will give you the original user, which is impossible (I think ).Originally Posted by johnny44
Bloody hell. I just tried it (just login, not re-boot), and he is right, it still returns my original name. What is going on?