Consulting

Results 1 to 8 of 8

Thread: Fetching Outlook User Name

  1. #1
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location

    Fetching Outlook User Name

    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:
    [vba]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 Sub[/vba]This approach has two drawbacks:
    1. it requires the user to identify the particular profile (if he/she has multiple profiles and has told ol to prompt for a profile)
    2. given the security now in ol, the user is also told that sensitive information has been requested and is that ok
    Neither 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
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  2. #2

  3. #3
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by JP2112
    Thanks 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
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  4. #4
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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") ?

  5. #5
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    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?

  6. #6
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by geekgirlau
    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.
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  7. #7
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Did you try this one? Of course it is restricted to NT, which may make it unsuitable.

  8. #8

    Sub Table

    Quote Originally Posted by MWE View Post
    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.
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •