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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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,
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top