By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,702 Members | 1,496 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,702 IT Pros & Developers. It's quick & easy.

How do I get the user name in my VB.NET program?

P: n/a
I have written and Outlook Addin using VB.NET. How can I get the username of
the person logged in to the PC that the Addin is running on? Thanks.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lanem,

You can use WMI, however in my opinion is this snippet simpler for your
question using the Environment variable

\\\\needs 1 listbox on a form
Dim environmentVariables As IDictionary _
= Environment.GetEnvironmentVariables()
Dim de As DictionaryEntry
ListBox1.Items.Clear()
For Each de In environmentVariables
Me.ListBox1.Items.Add(de.Key.ToString & _
"=" & de.Value.ToString)
Next de
////
You see that a list from things in de.Key and de.Value. One of them is
username, however it is more interesting to look to all so I did not select
that.

Cor
Nov 21 '05 #2

P: n/a
In article <uU**************@TK2MSFTNGP10.phx.gbl>, Cor Ligthert wrote:
Lanem,

You can use WMI, however in my opinion is this snippet simpler for your
question using the Environment variable

\\\\needs 1 listbox on a form
Dim environmentVariables As IDictionary _
= Environment.GetEnvironmentVariables()
Dim de As DictionaryEntry
ListBox1.Items.Clear()
For Each de In environmentVariables
Me.ListBox1.Items.Add(de.Key.ToString & _
"=" & de.Value.ToString)
Next de
////
You see that a list from things in de.Key and de.Value. One of them is
username, however it is more interesting to look to all so I did not select
that.

Cor


Cor... Why not just use System.Environment.UserName?

Console.WriteLine (Environment.UserName)

--
Tom Shelton [MVP]
Nov 21 '05 #3

P: n/a
Tom,
Cor... Why not just use System.Environment.UserName?

Console.WriteLine (Environment.UserName)

Because I was lazy and just copied and pasted from a part of an older
program of me.
And thought with this is shown so much information, than he knows that as
well where to get that in an easy way as well.

However next time I do as you said.

:-)

Cor
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.