Advertisement
obernardovieira

Get NetBios Name/HostName/domain

May 31st, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. //by MSDN - Microsoft
  2.  
  3. #define _WIN32_WINNT 0x0500
  4.  
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <tchar.h>
  8.  
  9. void _tmain(void)
  10. {
  11.     TCHAR buffer[256] = TEXT("");
  12.     TCHAR szDescription[8][32] = {TEXT("NetBIOS"),
  13.         TEXT("DNS hostname"),
  14.         TEXT("DNS domain"),
  15.         TEXT("DNS fully-qualified"),
  16.         TEXT("Physical NetBIOS"),
  17.         TEXT("Physical DNS hostname"),
  18.         TEXT("Physical DNS domain"),
  19.         TEXT("Physical DNS fully-qualified")};
  20.     int cnf = 0;
  21.     DWORD dwSize = sizeof(buffer);
  22.    
  23.     for (cnf = 0; cnf < ComputerNameMax; cnf++)
  24.     {
  25.         if (!GetComputerNameEx((COMPUTER_NAME_FORMAT)cnf, buffer, &dwSize))
  26.         {
  27.             _tprintf(TEXT("GetComputerNameEx failed (%d)\n"), GetLastError());
  28.             return;
  29.         }
  30.         else _tprintf(TEXT("%s: %s\n"), szDescription[cnf], buffer);
  31.  
  32.         dwSize = _countof(buffer);
  33.         ZeroMemory(buffer, dwSize);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement