Computer Name

This section details functions for retrieving and setting various aspects of a computer's name within the Windows operating system.

Overview

In Windows, a computer's name is a unique identifier on a network. This can include its NetBIOS name and its DNS host name. Understanding and managing these names is crucial for network communication, resource sharing, and system administration.

Core Functions

GetComputerNameEx

Retrieves the name of the local computer in a specified format.

BOOL GetComputerNameEx(
  COMPUTER_NAME_FORMAT NameType,
  LPTSTR lpBuffer,
  LPDWORD nSize
);

Parameters

Parameter Description
NameType A COMPUTER_NAME_FORMAT enumerated type value that specifies the type of name to be retrieved. This can include ComputerNameNetBIOS, ComputerNameDnsHostname, ComputerNameFullDnsDomainName, etc.
lpBuffer A pointer to a buffer that receives the computer name.
nSize A pointer to a DWORD value that, on input, specifies the size of the buffer pointed to by lpBuffer, in characters. On output, this parameter receives the actual number of characters copied to the buffer, including the null-terminating character.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Requirements

Header
lmcons.h

SetComputerName

Sets the NetBIOS name of the local computer.

BOOL SetComputerName(
  LPCTSTR lpString
);

Parameters

Parameter Description
lpString A pointer to a null-terminated string that specifies the new NetBIOS name for the computer. The name can contain up to 15 characters.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Requirements

Header
lmcons.h

Related Topics