Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get the Name and Phone Number of the Current Windows User in a .NET Application

53 views
Skip to first unread message

Alex

unread,
Jul 10, 2007, 1:49:25 PM7/10/07
to
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]

unread,
Jul 10, 2007, 2:08:02 PM7/10/07
to
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
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#

Nicholas Paldino [.NET/C# MVP]

unread,
Jul 10, 2007, 2:16:53 PM7/10/07
to
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.


--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Alex" <bohe...@gmail.com> wrote in message
news:1184089765.0...@r34g2000hsd.googlegroups.com...

Sheng Jiang[MVP]

unread,
Jul 10, 2007, 3:03:06 PM7/10/07
to
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"...
--
Sheng Jiang
Microsoft MVP in VC++

"Alex" <bohe...@gmail.com> wrote in message
news:1184089765.0...@r34g2000hsd.googlegroups.com...

Alex

unread,
Jul 10, 2007, 3:11:44 PM7/10/07
to
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,
>
> 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.
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - m...@spam.guard.caspershouse.com
>

> "Alex" <bohema...@gmail.com> wrote in message


>
> news:1184089765.0...@r34g2000hsd.googlegroups.com...
>
>
>
> > 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- Hide quoted text -
>
> - Show quoted text -


Alex

unread,
Jul 10, 2007, 3:16:25 PM7/10/07
to
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
> users log on as "Administrator"...
> --
> Sheng Jiang

> Microsoft MVP in VC++"Alex" <bohema...@gmail.com> wrote in message


>
> news:1184089765.0...@r34g2000hsd.googlegroups.com...
>
>
>
> > 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.
>

Nicholas Paldino [.NET/C# MVP]

unread,
Jul 10, 2007, 3:17:18 PM7/10/07
to
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).


--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Alex" <bohe...@gmail.com> wrote in message
news:1184094704.9...@p39g2000hse.googlegroups.com...

Alex

unread,
Jul 10, 2007, 3:25:20 PM7/10/07
to
Thanks. Nick ...

Alex

On Jul 10, 3:17 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> 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).
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - m...@spam.guard.caspershouse.com
>

> >> - Show quoted text -- Hide quoted text -

Sheng Jiang[MVP]

unread,
Jul 10, 2007, 4:05:07 PM7/10/07
to
try NetUserGetInfo

http://pinvoke.net/default.aspx/netapi32/NetUserGetInfo.html


--
Sheng Jiang
Microsoft MVP in VC++

"Alex" <bohe...@gmail.com> wrote in message

news:1184094985....@n2g2000hse.googlegroups.com...

Alex

unread,
Jul 11, 2007, 9:25:10 AM7/11/07
to
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

0 new messages