Windows LOGON NAME - special case - account name different from folder name

R

riso

Hi all excel gurus,

On my computer the LOGON NAME as it is showed in 'Start' or on the
login screen is different from the name of folder the data are stored.
My account name is 'Riso' but all windows related data are stored in
folder "C:\Documents and Settings\Riso_2". This state was obtained by
renaming account names and creating accounts with names that were used
before.

Actually, there are accounts:
Genius that is stored in C:\Documents and Settings\Riso
Riso that is stored in C:\Documents and Settings\Riso_2
John that is stored in C:\Documents and Settings\John

In welcome_user macro I want to show names Genius, Riso and John (in
order) when Genius, Riso or John (in order) opens the particular file.
In the code there is a line MsgBox "Hello " & xxxxxxxxxx.

If I use
Environ("UserName") or
wshnet.UserName or
logonNameVar
instead of xxxxxxxxxxxxx I recieve Riso, Riso_2 and John (in order)

(To make the list full) When I use Application.UserName I recieve
completelly different (and unrelated) info...no surprise.

For details see the attached illustrative sample code.

Well, It seems that UserName property contains the folder or original
name of the account instead of current name.

Is there any way how to get the actual name of the account?

Thank you in advance for any hint or ultimative answer that it is not
possible.

and thank you all for reading

------------
some info to sample code:
copy it to module and run macro show_boxes
all ways how to reach windows logon name are taken from posts in
microsoft.public.excel.programming group
====================illustrative SAMPLE CODE=====
Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Sub show_boxes()

Dim wshnet As Object
Set wshnet = CreateObject("WScript.Network")
MsgBox "The name of user is (WScript): " & wshnet.UserName

MsgBox "The name of user is (appl username): " & Application.UserName

MsgBox "The name of user is (environ username): " &
Environ("UserName")

Dim S As String
Dim L As Long
Dim R As Long
Dim logonNameVar As String
S = String$(255, " ")
L = Len(S)
R = GetUserName(S, L)
logonNameVar = Left(S, L - 1)
MsgBox "The name of user is (get user name): " & logonNameVar

End Sub
 
C

Chip Pearson

To get the name of the User Profile directory for the current user, in which
are stored folders like "My Documents", "DeskTop", "Start Menu" etc, use

Environ("UserProfile")

This will return something like

C:\Documents and Settings\Administrator.DELL8250.001

To get the name of a particular folder (e.g., "My Docments") within the
UserProfile directory, see http://www.cpearson.com/excel/SpecialFolders.htm
..



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
R

riso

Thanks a lot for your effort. But I do not look for particular
directory/folder name, but for user name.

In case

the directory is "Riso_2" (I meant that everything is stored in C:
\Documents and Settings\Riso_2" etc.) and
user name is Genius

the command

Environ("UserProfile")

returns

Riso_2 (not Genius!)


I want to have a command that returns "Genius", not the original name
of that account which is the same as the folder name "Riso_2".

thanks
 
R

riso

Errata Errata Errata Errata Errata Errata Errata Errata

Sorry, wrong comand used in a previous post. I meant to use the
command the command Environ("UserName") not the command
Environ("UserProfile").

Errata Errata Errata Errata Errata Errata Errata Errata
 

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