Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Windows LOGON NAME - special case - account name different from folder name

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Windows LOGON NAME - special case - account name different from folder name

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)



"riso" wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Windows LOGON NAME - special case - account name different from folder name

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

On Feb 11, 11:53 pm, "Chip Pearson" wrote:
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, seehttp://www.cpearson.com/excel/SpecialFolders.htm
.

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Windows LOGON NAME - special case - account name different from folder name

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to logon to brokerage account aligatrjoe Excel Discussion (Misc queries) 3 January 14th 08 07:47 PM
special case of sumif delali Excel Worksheet Functions 4 March 24th 06 06:41 PM
special case of sumproduct delali Excel Worksheet Functions 2 March 24th 06 06:18 PM
Use Windows Network logon as password Spencer Hutton[_3_] Excel Programming 2 October 13th 04 01:17 PM
Getting Windows user (Account) from a VBA routine Jacques Brun Excel Programming 7 June 11th 04 11:35 PM


All times are GMT +1. The time now is 10:51 AM.

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

About Us

"It's about Microsoft Excel"