Results 1 to 6 of 6

Thread: How can you get the comp name on windows?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    54
    does anyone know how to get the computer name from the network properties?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    #include <windows.h>
    #include <iostream.h>
    
    char *buffer = new TCHAR[256];
    DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
    GetComputerName(buffer,&len);
    //buffer contains computer name
    cout<<buffer<<endl;
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Change this:

    char *buffer = new TCHAR[256];

    to this:

    TCHAR *buffer = new TCHAR[MAX_COMPUTERNAME_LENGTH];
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Ah , thans Parksie. I put the MAX_COMPUTERNAME_LENGTH in the code later so i forgot to change it in the buffer declaration.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    54
    Well the first one worked why the change?
    Thanks again..

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Okay...normally TCHAR resolves to char. However, if you compile for Unicode it resolves to wchar_t, which is two bytes. So, normally it's fine.

    That's the obscure one gone...

    The other change was just to match the buffer sizes.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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