PDA

View Full Version : Fetching Outlook User Name



MWE
10-20-2009, 02:37 PM
I am trying to figure out some way to determine the current user's real name while, say, Excel is executing. Application.UserName provides a clue but it is most likely some abbreviation of the user's real name, e.g., jdoe instead of John Doe. The only place that the user's real name might be found is his user name in Outlook. Fetching the user name from another application is pretty easy, for example:
Sub Test_GetEmail_UserName()

Dim olAppl As Outlook.Application
Dim olNameSpace As Outlook.Namespace


Set olAppl = CreateObject("Outlook.Application")
Set olNameSpace = olAppl.GetNamespace("MAPI")
MsgBox olNameSpace.CurrentUser

olAppl.Quit
Set olNameSpace = Nothing
Set olAppl = Nothing

End SubThis approach has two drawbacks:
it requires the user to identify the particular profile (if he/she has multiple profiles and has told ol to prompt for a profile)
given the security now in ol, the user is also told that sensitive information has been requested and is that okNeither is a big deal, but I would like something that is more invisible. I can get around the 2nd problem with redemption, but that requires (I assume) that redemption be loaded on any user's machine.

Any ideas?

Thanks

JP2112
10-22-2009, 07:13 AM
No need to use Outlook. Check out

http://www.dailydoseofexcel.com/archives/2004/06/17/get-the-username-in-vba/
http://www.mvps.org/access/api/api0066.htm

MWE
10-22-2009, 08:27 AM
No need to use Outlook. Check out

http://www.dailydoseofexcel.com/archives/2004/06/17/get-the-username-in-vba/
http://www.mvps.org/access/api/api0066.htmThanks for the reply.

I ran the code for both links and got the same answer, my system level user name (as I expected) and, thus, neither approach gets the users "real name". The system level user name is often the same as Application.UserName

Think back to when you installed Windows. Did you enter your real name anywhere? I certainly did not. I used the same first initial & last name for both system and applications -- as I am sure 90% of people do.

If you have a different take on what those links provide, please get back to me.

Thanks

JP2112
10-22-2009, 09:04 AM
I actually do enter my real name when I install Windows.

I understand your concern, but if you don't type your "real name" anywhere that can be read programmatically, that's not a problem that programming can solve.

My major concern is the huge overhead you incur by invoking the Outlook object model, just to get the computer user's name (which would be present with or without Outlook). Also it requires that Outlook be installed on the end user's machine.

I'm surprised that the API method from the first link I sent you didn't provide the result you needed. Application.Username is unreliable, since you can change it easily. Did you try parsing Environ("userprofile") for the username, or Environ("username") ?

geekgirlau
10-25-2009, 07:06 PM
I generally use the API method, although this doesn't always result in a name. For example, in my current contract login names consist of a single character to identify the site, followed by a randomly generated number. So you can determine a unique identifier for the user, without actually capturing their name.

Can I ask why you want the name?

MWE
10-26-2009, 08:36 PM
I generally use the API method, although this doesn't always result in a name. For example, in my current contract login names consist of a single character to identify the site, followed by a randomly generated number. So you can determine a unique identifier for the user, without actually capturing their name.

Can I ask why you want the name? There is no one answer to your question. I have wanted the user's "real" name on a number of different applications and a unique name (or something) on others. I fiddled with various approaches and often used email address as the one unique identifier. Back before ol was security nuts, and since most users run single profiles, fetching an email address was pretty easy.. It is now more a matter of personal curiosity and that funny drive to finally find a way.:devil2:

geekgirlau
10-26-2009, 10:12 PM
Did you try this (http://www.mvps.org/access/api/api0066.htm) one? Of course it is restricted to NT, which may make it unsuitable.

julesbeats
10-08-2015, 05:15 AM
There is no one answer to your question. I have wanted the user's "real" name on a number of different applications and a unique name (or something) on others. I fiddled with various approaches and often used email address as the one unique identifier. Back before ol was security nuts, and since most users run single profiles, fetching an email address was pretty easy.. It is now more a matter of personal curiosity and that funny drive to finally find a way.:devil2:

Do you know the "real names" as a whole, or are you trying to determine what the "real name" is depending on user ID? The easiest way is create a sub-table with 3 fields: USER_ID, LNAME, FNAME.

Then use the table as a matrix to display whichever name you wish to see. You can also concatenate the LNAME and FNAME if you want them to appear in a single cell on return.