Skip to content

Latest commit

 

History

History
136 lines (93 loc) · 5.66 KB

File metadata and controls

136 lines (93 loc) · 5.66 KB
UID NF:winbase.GetComputerNameW
title GetComputerNameW function (winbase.h)
description Retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry. (Unicode)
helpviewer_keywords
GetComputerName
GetComputerName function
GetComputerNameW
_win32_getcomputername
base.getcomputername
winbase/GetComputerName
winbase/GetComputerNameW
old-location base\getcomputername.htm
tech.root winprog
ms.assetid 8ca3e611-e5fb-4909-adf6-98eb8552c9e1
ms.date 12/05/2018
ms.keywords GetComputerName, GetComputerName function, GetComputerNameA, GetComputerNameW, _win32_getcomputername, base.getcomputername, winbase/GetComputerName, winbase/GetComputerNameA, winbase/GetComputerNameW
req.header winbase.h
req.include-header Windows.h
req.target-type Windows
req.target-min-winverclnt Windows 2000 Professional [desktop apps \| UWP apps]
req.target-min-winversvr Windows 2000 Server [desktop apps \| UWP apps]
req.kmdf-ver
req.umdf-ver
req.ddi-compliance
req.unicode-ansi GetComputerNameW (Unicode) and GetComputerNameA (ANSI)
req.idl
req.max-support
req.namespace
req.assembly
req.type-library
req.lib Kernel32.lib
req.dll Kernel32.dll
req.irql
targetos Windows
req.typenames
req.redist
ms.custom 19H1
f1_keywords
GetComputerNameW
winbase/GetComputerNameW
dev_langs
c++
topic_type
APIRef
kbSyntax
api_type
DllExport
api_location
api-ms-win-core-kernel32-legacy-l1-1-6.dll
Kernel32.dll
API-MS-Win-Core-Kernel32-Legacy-l1-1-0.dll
kernel32legacy.dll
API-MS-Win-Core-Kernel32-Legacy-l1-1-1.dll
API-MS-Win-Core-Kernel32-Legacy-l1-1-2.dll
API-MS-Win-DownLevel-Kernel32-l2-1-0.dll
API-MS-Win-Core-Kernel32-Legacy-L1-1-3.dll
API-MS-Win-Core-Kernel32-Legacy-L1-1-4.dll
API-MS-Win-Core-Kernel32-Legacy-L1-1-5.dll
api_name
GetComputerName
GetComputerNameA
GetComputerNameW

GetComputerNameW function

-description

Retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry.

GetComputerName retrieves only the NetBIOS name of the local computer. To retrieve the DNS host name, DNS domain name, or the fully qualified DNS name, call the GetComputerNameEx function. Additional information is provided by the IADsADSystemInfo interface.

The behavior of this function can be affected if the local computer is a node in a cluster. For more information, see ResUtilGetEnvironmentWithNetName and UseNetworkName.

-parameters

-param lpBuffer [out]

A pointer to a buffer that receives the computer name or the cluster virtual server name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.

-param nSize [in, out]

On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs copied to the destination buffer, not including the terminating null character.

If the buffer is too small, the function fails and GetLastError returns ERROR_BUFFER_OVERFLOW. The lpnSize parameter specifies the size of the buffer required, including the terminating null character.

-returns

If the function succeeds, the return value is a nonzero value.

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

-remarks

The GetComputerName function retrieves the NetBIOS name established at system startup. Name changes made by the SetComputerName or SetComputerNameEx functions do not take effect until the user restarts the computer.

If the caller is running under a client session, this function returns the server name. To retrieve the client name, use the WTSQuerySessionInformation function.

Examples

For an example, see Getting System Information.

Note

The winbase.h header defines GetComputerName as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

-see-also

Computer Names

GetComputerNameEx

SetComputerName

SetComputerNameEx

System Information Functions