Get the Name and Phone Number of the Current Windows User in a .NET
Application
I am writing a simple .NET (C#) application. It needs to "automatic"
get the Name (last, first) and phone number of the current Windows
user.
I guess the name can be retrieved from the environment -- After I
click the Start button of Windows, my name is on the very first line
of the popup menu. So, this information is provided by the Windows
environment.
My question is how I get this environment information in a C#
application.
I also need to get the phone number of the current Windows user. I
can safely assume:
(1) Outlook is installed.
(2) The phone number of the current Windows user is in the Outlook
profile.
Is there a way to obtain the phone number of the current Windows
user? We canNOT assume that Outlook is running when my application is
running.
Your input is highly appreciated.
Thanks.
Alex
Peter Ritchie [C# MVP] - 10 Jul 2007 19:08 GMT
You might try the microsoft.public.officedev ng[1]. There's more people
hanging out there that are familar with developing with Outlook.
[1]
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.officedev&
lang=en&cr=US

Signature
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
> Get the Name and Phone Number of the Current Windows User in a .NET
> Application
[quoted text clipped - 26 lines]
>
> Alex
Nicholas Paldino [.NET/C# MVP] - 10 Jul 2007 19:16 GMT
Alex,
This is going to be near impossible. First, the full name of a user is
not always stored with the user account. You can get that from the Outlook
profile most likely (or any Office app, through interop), but the phone
number is by no means guaranteed.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Get the Name and Phone Number of the Current Windows User in a .NET
> Application
[quoted text clipped - 26 lines]
>
> Alex
Alex - 10 Jul 2007 20:11 GMT
Thanks, Nick for the input.
The people who uses my application have already had their Windows and
Outlook properly set up.
On Jul 10, 2:16 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Alex,
>
[quoted text clipped - 39 lines]
>
> - Show quoted text -
Nicholas Paldino [.NET/C# MVP] - 10 Jul 2007 20:17 GMT
Alex,
If that's the case, then you should be able to access the information in
Outlook through the Outlook object model (using the primary interop
assemblies for Outlook).

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Thanks, Nick for the input.
>
[quoted text clipped - 48 lines]
>>
>> - Show quoted text -
Alex - 10 Jul 2007 20:25 GMT
Thanks. Nick ...
Alex
On Jul 10, 3:17 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Alex,
>
[quoted text clipped - 64 lines]
>
> - Show quoted text -
Sheng Jiang[MVP] - 10 Jul 2007 20:03 GMT
You can get the current user name by using Environment.UserName
The logon name may differ from the legal name of the user. For example, many
users log on as "Administrator"...

Signature
Sheng Jiang
Microsoft MVP in VC++
> Get the Name and Phone Number of the Current Windows User in a .NET
> Application
[quoted text clipped - 26 lines]
>
> Alex
Alex - 10 Jul 2007 20:16 GMT
Sheng,
Thanks for the input. Let's say my logon name is AlexLogOnName, but
when I click the Start Button of my Windows, my name -- LastName, Alex
-- is shown in the popup menu. I guess my Windows is properly set up
with user's logon name and user's real name (Last, first). Any input
on how windows differentiate logon and real name (last, first)?
On Jul 10, 3:03 pm, "Sheng Jiang[MVP]"
<sheng_ji...@hotmail.com.discuss> wrote:
> You can get the current user name by using Environment.UserName
> The logon name may differ from the legal name of the user. For example, many
[quoted text clipped - 34 lines]
>
> - Show quoted text -
Sheng Jiang[MVP] - 10 Jul 2007 21:05 GMT
try NetUserGetInfo
http://pinvoke.net/default.aspx/netapi32/NetUserGetInfo.html

Signature
Sheng Jiang
Microsoft MVP in VC++
> Sheng,
>
[quoted text clipped - 44 lines]
> >
> > - Show quoted text -
Alex - 11 Jul 2007 14:25 GMT
First, thank you for all your help
Some update:
1. I can easily get users Windows login name which is the SAME as
Outlook email Alias, by using Environment.UserName
2. After add Outlook Object references, I can do something like:
Outlook._Application olApp = new
Outlook.ApplicationClass();
Outlook.NameSpace oNS = olApp.GetNamespace("MAPI");
Outlook.AddressList oAL = oNS.AddressLists["Global Address
List"];
Outlook.AddressEntries oAEs = oAL.AddressEntries;
In this way, I can get the AddressEntries. My question is can I
search the AddressEntries for the user login name I found by using
Environment.UserName? I did not find a method for search/find
> Get the Name and Phone Number of the Current Windows User in a .NET
> Application
[quoted text clipped - 26 lines]
>
> Alex