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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Get computer name ?

Get computer name ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
28 Posts 8 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.
  • S Surivevoli

    I have a small question : what function is used to get name of my computer ?

    E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #5

    You have the answer in your question itself :)


    --[V]--

    [My Current Status]

    S 1 Reply Last reply
    0
    • T ThatsAlok

      Surivevoli wrote:

      what function is used to get name of my computer ?

      GetComputerName()...

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta VC Forum Q&A :- I/ IV

      S Offline
      S Offline
      Surivevoli
      wrote on last edited by
      #6

      but i don't know use parameter in that funtion : GetComputerName(...); could you help me ???

      T 1 Reply Last reply
      0
      • E Eytukan

        You have the answer in your question itself :)


        --[V]--

        [My Current Status]

        S Offline
        S Offline
        Surivevoli
        wrote on last edited by
        #7

        but i don't know use parameter in that funtion : GetComputerName(...); could you help me ???

        E K 2 Replies Last reply
        0
        • K kiran janaswamy

          hi, use GetComputerName(...) Api or gethostbyname(...) Api. cheers, uday. uday kiran

          S Offline
          S Offline
          Surivevoli
          wrote on last edited by
          #8

          but i don't know use parameter in that funtion : GetComputerName(...); could you help me ???

          1 Reply Last reply
          0
          • S Surivevoli

            but i don't know use parameter in that funtion : GetComputerName(...); could you help me ???

            K Offline
            K Offline
            kiran janaswamy
            wrote on last edited by
            #9

            hi , This is the Snippet of Code //=========================================================== #define INFO_BUFFER_SIZE 32767 TCHAR infoBuf[INFO_BUFFER_SIZE]; DWORD bufCharCount = INFO_BUFFER_SIZE; GetComputerName( infoBuf, &bufCharCount); //========================================================== the infoBuf contains the Computer Name. good luck. cheers. uday kiran

            S 2 Replies Last reply
            0
            • S Surivevoli

              but i don't know use parameter in that funtion : GetComputerName(...); could you help me ???

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #10

              #define INFO_BUFFER_SIZE 32767 LPSTR computerName = new char(50); dw = INFO_BUFFER_SIZE; GetComputerName(computerName,&dw);


              --[V]--

              [My Current Status]

              R 1 Reply Last reply
              0
              • K kiran janaswamy

                hi , This is the Snippet of Code //=========================================================== #define INFO_BUFFER_SIZE 32767 TCHAR infoBuf[INFO_BUFFER_SIZE]; DWORD bufCharCount = INFO_BUFFER_SIZE; GetComputerName( infoBuf, &bufCharCount); //========================================================== the infoBuf contains the Computer Name. good luck. cheers. uday kiran

                S Offline
                S Offline
                Surivevoli
                wrote on last edited by
                #11

                Thank you very and very much !!!

                1 Reply Last reply
                0
                • K kiran janaswamy

                  hi, use GetComputerName(...) Api or gethostbyname(...) Api. cheers, uday. uday kiran

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #12

                  kiran janaswamy wrote:

                  use...gethostbyname(...) Api.

                  This function does not retrieve the host name. It uses the host name to retrieve host information such as IP address.


                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                  "We will be known forever by the tracks we leave." - Native American Proverb

                  K S 2 Replies Last reply
                  0
                  • D David Crow

                    kiran janaswamy wrote:

                    use...gethostbyname(...) Api.

                    This function does not retrieve the host name. It uses the host name to retrieve host information such as IP address.


                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                    "We will be known forever by the tracks we leave." - Native American Proverb

                    K Offline
                    K Offline
                    kiran janaswamy
                    wrote on last edited by
                    #13

                    hi, sorry it is gethostname(...) Api. cheers, uday. uday kiran

                    1 Reply Last reply
                    0
                    • S Surivevoli

                      but i don't know use parameter in that funtion : GetComputerName(...); could you help me ???

                      T Offline
                      T Offline
                      ThatsAlok
                      wrote on last edited by
                      #14

                      Surivevoli wrote:

                      GetComputerName(...);

                      TCHAR szCompName[MAX_PATH]; GetComputerName(szCompName,MAX_PATH);

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      cheers, Alok Gupta VC Forum Q&A :- I/ IV

                      H 1 Reply Last reply
                      0
                      • E Eytukan

                        #define INFO_BUFFER_SIZE 32767 LPSTR computerName = new char(50); dw = INFO_BUFFER_SIZE; GetComputerName(computerName,&dw);


                        --[V]--

                        [My Current Status]

                        R Offline
                        R Offline
                        Ryan Binns
                        wrote on last edited by
                        #15

                        VuNic wrote:

                        #define INFO_BUFFER_SIZE 32767

                        What's wrong with using the system-defined MAX_COMPUTERNAME_LENGTH?

                        Ryan

                        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                        S 1 Reply Last reply
                        0
                        • T ThatsAlok

                          Surivevoli wrote:

                          GetComputerName(...);

                          TCHAR szCompName[MAX_PATH]; GetComputerName(szCompName,MAX_PATH);

                          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                          cheers, Alok Gupta VC Forum Q&A :- I/ IV

                          H Offline
                          H Offline
                          Hamid Taebi
                          wrote on last edited by
                          #16

                          Hi ThatsAlok, I thnik he can read from registry

                          S S T 3 Replies Last reply
                          0
                          • H Hamid Taebi

                            Hi ThatsAlok, I thnik he can read from registry

                            S Offline
                            S Offline
                            Surivevoli
                            wrote on last edited by
                            #17

                            could you tell me do that ?

                            H 1 Reply Last reply
                            0
                            • D David Crow

                              kiran janaswamy wrote:

                              use...gethostbyname(...) Api.

                              This function does not retrieve the host name. It uses the host name to retrieve host information such as IP address.


                              "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                              "We will be known forever by the tracks we leave." - Native American Proverb

                              S Offline
                              S Offline
                              Surivevoli
                              wrote on last edited by
                              #18

                              Could you tell me : How to get my IP address ??? What's happened if my computer don't connect to the Internet or LAN, or i don't install IIS ??? And: If i connect over LAN, how to get other Computer name if i know its IP and how to get other computer's IP if i know its name ?

                              D 1 Reply Last reply
                              0
                              • K kiran janaswamy

                                hi , This is the Snippet of Code //=========================================================== #define INFO_BUFFER_SIZE 32767 TCHAR infoBuf[INFO_BUFFER_SIZE]; DWORD bufCharCount = INFO_BUFFER_SIZE; GetComputerName( infoBuf, &bufCharCount); //========================================================== the infoBuf contains the Computer Name. good luck. cheers. uday kiran

                                S Offline
                                S Offline
                                Surivevoli
                                wrote on last edited by
                                #19

                                Could you tell me : How to get my IP address ??? What's happened if my computer don't connect to the Internet or LAN, or i don't install IIS ??? And: If i connect over LAN, how to get other Computer name if i know its IP and how to get other computer's IP if i know its name ?

                                1 Reply Last reply
                                0
                                • R Ryan Binns

                                  VuNic wrote:

                                  #define INFO_BUFFER_SIZE 32767

                                  What's wrong with using the system-defined MAX_COMPUTERNAME_LENGTH?

                                  Ryan

                                  "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                                  S Offline
                                  S Offline
                                  Surivevoli
                                  wrote on last edited by
                                  #20

                                  what's MAX_COMPUTERNAME_LENGTH ? what is its value ?

                                  D 1 Reply Last reply
                                  0
                                  • S Surivevoli

                                    Could you tell me : How to get my IP address ??? What's happened if my computer don't connect to the Internet or LAN, or i don't install IIS ??? And: If i connect over LAN, how to get other Computer name if i know its IP and how to get other computer's IP if i know its name ?

                                    D Offline
                                    D Offline
                                    David Crow
                                    wrote on last edited by
                                    #21

                                    Surivevoli wrote:

                                    How to get my IP address ???

                                    I'm not sure what your IP address would be;), but to get your computer's IP address, use gethostname() followed by gethostbyname().

                                    Surivevoli wrote:

                                    What's happened if my computer don't connect to the Internet or LAN...

                                    Then I guess it doesn't get access to certain resources.

                                    Surivevoli wrote:

                                    What's happened if...i don't install IIS ???

                                    Regardless of who does not install it, the computer does not get to utilize any of the benefits that IIS offers.

                                    Surivevoli wrote:

                                    how to get other Computer name if i know its IP

                                    Use gethostbyaddr().

                                    Surivevoli wrote:

                                    and how to get other computer's IP if i know its name ?

                                    Use gethostbyname().


                                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                    "We will be known forever by the tracks we leave." - Native American Proverb

                                    S 1 Reply Last reply
                                    0
                                    • S Surivevoli

                                      what's MAX_COMPUTERNAME_LENGTH ? what is its value ?

                                      D Offline
                                      D Offline
                                      David Crow
                                      wrote on last edited by
                                      #22

                                      Surivevoli wrote:

                                      what's MAX_COMPUTERNAME_LENGTH ? what is its value ?

                                      Do you just refuse to look anything up for yourself? Look in WinBase.h for this value.


                                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                      "We will be known forever by the tracks we leave." - Native American Proverb

                                      1 Reply Last reply
                                      0
                                      • H Hamid Taebi

                                        Hi ThatsAlok, I thnik he can read from registry

                                        S Offline
                                        S Offline
                                        Shog9 0
                                        wrote on last edited by
                                        #23

                                        Yes, but he shouldn't. Using the proper APIs is much less likely to fail in odd ways.

                                        Now taking suggestions for the next release of CPhog...

                                        H 1 Reply Last reply
                                        0
                                        • D David Crow

                                          Surivevoli wrote:

                                          How to get my IP address ???

                                          I'm not sure what your IP address would be;), but to get your computer's IP address, use gethostname() followed by gethostbyname().

                                          Surivevoli wrote:

                                          What's happened if my computer don't connect to the Internet or LAN...

                                          Then I guess it doesn't get access to certain resources.

                                          Surivevoli wrote:

                                          What's happened if...i don't install IIS ???

                                          Regardless of who does not install it, the computer does not get to utilize any of the benefits that IIS offers.

                                          Surivevoli wrote:

                                          how to get other Computer name if i know its IP

                                          Use gethostbyaddr().

                                          Surivevoli wrote:

                                          and how to get other computer's IP if i know its name ?

                                          Use gethostbyname().


                                          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                          "We will be known forever by the tracks we leave." - Native American Proverb

                                          S Offline
                                          S Offline
                                          Surivevoli
                                          wrote on last edited by
                                          #24

                                          I don't know to use parameters: Could you tell me use parameters in these function: gethostname() gethostbyname() gethostbyaddr() Could you teach me step by step ???

                                          D 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