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

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Tom Shelton (tom_at_YOUKNOWTHEDRILLmtogden.com)
Date: 09/29/04


Date: Wed, 29 Sep 2004 08:40:40 -0700

In article <uUEF51ipEHA.3724@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]


Relevant Pages

  • Re: searching for the highest index within a directory
    ... Cor, thanks for the snippet. ... Nick, to answer your question.... ... an application for this type of naming is a sequential graphic animation ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Easy label question...
    ... I see it upi only setting to false in this snippet. ... Cor ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Frames show and hide?
    ... When it is about Iframes I am curious how you did what you wrote, ... show a little snippet? ... Cor ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SmtpMail causes application to hang...
    ... This snippet you show now in this newsgroup has been here often. ... Mostly is the error that the smtp mailserver is not correct. ... Cor ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How do I call a method of another from
    ... It's just in your nature Larry, admit it, you just have to have the last ... the subject matter, however, in a community 'Even an on-line community' such ... > If it turns out there are better solutions, then it would be in everyone's best interest> to get Cor to change his opinion to the better solution so that the next time that> question gets asked, he can offer the better solution. ... As you know Cor posts a> lot of messages, and helps many people, so getting him to see 'why' one solution is> better than another will 'maybe' persuade him to change his opinion of the best> solution for the task. ...
    (microsoft.public.dotnet.languages.vb)