Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System name using C#

System name using C#

Scheduled Pinned Locked Moved C#
csharptutorialquestion
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Hai, Can anyone tell me how to get the name of the computer (in which the code is running) using c#? thanks.

    F Offline
    F Offline
    Fazlul Kabir
    wrote on last edited by
    #2

    Thought this one should do

    String s = System.Diagnostics.Process.GetCurrentProcess().MachineName;

    // Fazlul


    Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

    O 1 Reply Last reply
    0
    • F Fazlul Kabir

      Thought this one should do

      String s = System.Diagnostics.Process.GetCurrentProcess().MachineName;

      // Fazlul


      Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

      O Offline
      O Offline
      omkamal
      wrote on last edited by
      #3

      Its giving me only a '.', its not giving me the name of the machine. any other suggestions????:confused: omkamal

      O F 2 Replies Last reply
      0
      • O omkamal

        Its giving me only a '.', its not giving me the name of the machine. any other suggestions????:confused: omkamal

        O Offline
        O Offline
        omkamal
        wrote on last edited by
        #4

        Ok. This is what I found out. I dont think there is a direct GetComputerName function in c# (as far as I know). Instead I read the following registry key HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName. I hope this key is created in all machine because the System subkey stores sys related info. If anyone wants to know the computer name, this is next to a good solution. Use, Microsoft.Win32 namespace for Registry related classes in c#. One more thing "Naivete" and "omkamal" are one and the same. I just changed my username. Thanks for your help. omkamal

        1 Reply Last reply
        0
        • O omkamal

          Its giving me only a '.', its not giving me the name of the machine. any other suggestions????:confused: omkamal

          F Offline
          F Offline
          Fazlul Kabir
          wrote on last edited by
          #5

          You're right, it doesn't work on my system either. According to .NET documentation, MachineName property should return the name of the system

          Gets the name of the computer the associated process is running on.

          // Fazlul


          Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

          O 1 Reply Last reply
          0
          • L Lost User

            Hai, Can anyone tell me how to get the name of the computer (in which the code is running) using c#? thanks.

            K Offline
            K Offline
            Kelly Herald
            wrote on last edited by
            #6

            Naivete wrote: Can anyone tell me how to get the name of the computer (in which the code is running) using c#? Try this: string s = SystemInformation.ComputerName; Kelly Herald Software Developer Micronpc, LLC

            O F 2 Replies Last reply
            0
            • F Fazlul Kabir

              You're right, it doesn't work on my system either. According to .NET documentation, MachineName property should return the name of the system

              Gets the name of the computer the associated process is running on.

              // Fazlul


              Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

              O Offline
              O Offline
              omkamal
              wrote on last edited by
              #7

              But if you read the document further it will also say that this property holds true only when you are trying to reach a remote computer... Remarks Specify a value for the MachineName property to view the processes running on another computer on the network. You can view statistical data and process information for processes running on remote computers but you .... omkamal

              F 1 Reply Last reply
              0
              • K Kelly Herald

                Naivete wrote: Can anyone tell me how to get the name of the computer (in which the code is running) using c#? Try this: string s = SystemInformation.ComputerName; Kelly Herald Software Developer Micronpc, LLC

                O Offline
                O Offline
                omkamal
                wrote on last edited by
                #8

                Awesome! Thanks Kelly. I appreciate your reply. I was so surprised how come c# doesnot provide such a functionality. But shame on me, that I felt so frustrating to check every single class for it. Nor did I try different search strings. Thanks again, Omkumar. omkamal

                1 Reply Last reply
                0
                • K Kelly Herald

                  Naivete wrote: Can anyone tell me how to get the name of the computer (in which the code is running) using c#? Try this: string s = SystemInformation.ComputerName; Kelly Herald Software Developer Micronpc, LLC

                  F Offline
                  F Offline
                  Fazlul Kabir
                  wrote on last edited by
                  #9

                  Thanks, this worked. // Fazlul


                  Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

                  O 1 Reply Last reply
                  0
                  • O omkamal

                    But if you read the document further it will also say that this property holds true only when you are trying to reach a remote computer... Remarks Specify a value for the MachineName property to view the processes running on another computer on the network. You can view statistical data and process information for processes running on remote computers but you .... omkamal

                    F Offline
                    F Offline
                    Fazlul Kabir
                    wrote on last edited by
                    #10

                    omkamal wrote: But if you read the document further it will also say that this property holds true only when you are trying to reach a remote computer... Sorry, I was obviously mistaken. I guess you can try SystemInformation::ComputerName, as suggested in another post. // Fazlul


                    Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

                    1 Reply Last reply
                    0
                    • F Fazlul Kabir

                      Thanks, this worked. // Fazlul


                      Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

                      O Offline
                      O Offline
                      omkamal
                      wrote on last edited by
                      #11

                      Sorry if I underestimated c#. Here you go. One more property to get the machine name... System.Environment.Machinename omkamal

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups