Results 1 to 4 of 4

Thread: My.Computer.Name Property

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    My.Computer.Name Property

    Both of the below return the computers name in upper case even when the actual name is in lower case

    Code:
     MsgBox("Computer name: " & My.Computer.Name)
            MsgBox(Environment.MachineName)
    I have had a look in the help and on MSDN and could not find any explanation to confirm this.

    Is this true for every windows version?

    regards
    toe

    ps: i only use MsgBox when testing

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: My.Computer.Name Property

    A machine name is unique on the network and case-insensitive. So it should not matter what case it returns. You can always convert it to the one you want using any of the string functions.
    e.g.

    Code:
            MsgBox(My.Computer.Name.ToLower)
            MsgBox(My.Computer.Name.ToUpper)
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: My.Computer.Name Property

    thanks fro the explanation.

    The problem i came across was i was using the pc name as a registration key. [I know it isn't the most efficient way of doing it but that's all i am capable of at the moment]

    On my 3 machines the pc names are in lower case so the program failed to start because the .net language was converting the pc name to upper case.

    i just have to remember to change it to upper case

    regards
    toe

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My.Computer.Name Property

    Why not just do a case-insensitive comparison? That way it doesn't matter what case is used where. The String.Equals method, among others, supports case-insensitive comparisons.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width