- Find computer name from command line
- Get DNS or FQDN(fully qualified domain name) of the computer
- Find computer name using wmic
- GetComputerNameExW function (sysinfoapi.h)
- Syntax
- Parameters
- Return value
- Remarks
- Examples
- GetComputerNameW function (winbase.h)
- Syntax
- Parameters
- Return value
- Remarks
- Examples
- GetComputerNameExA function (sysinfoapi.h)
- Syntax
- Parameters
- Return value
- Remarks
- Examples
Find computer name from command line
You can find out your computer name from command line using hostname command.
Note that hostname prints only the NetBios name of the computer, not the full DNS name. It works on all Windows versions- XP, Vista, Windows 7, Server 2003 and Server 2008.
System name is also stored in the environment variable computername. We can print the computer name using this environment variable as follows.
Note that, %computername% is more convenient to use in batch files. We can straight away use %computername% wherever we want to refer the local host name.
Get DNS or FQDN(fully qualified domain name) of the computer
Find computer name using wmic
net config works on win7 to get fqdn name. but it’s printing as below
how to print only fqdn and no additional text in the line? if I could do this, I can read the value to a variable in batch script.
YOU NEED TO USE FOR /F %%
In network i want to know PC name with the help of user id to know on which machine he login into ?
Cmd pls
Hi, How do I get the Computer name using Curl,
I have the following curl and I want to access the hostname(pass it instead of ABCD).
curl -X PUT “http://localhost:14121/api/SetValue?hostName=ABCD&status=false” -H “accept: application/json” -d “Content-Length: 0”
hi. i have 2 pc. my compiuter name is m110pc-01 and m140pc-01.
how can i delete prefix >M rookie_b
GetComputerNameExW function (sysinfoapi.h)
Retrieves a NetBIOS or DNS name associated with the local computer. The names are established at system startup, when the system reads them from the registry.
Syntax
Parameters
The type of name to be retrieved. This parameter is a value from the COMPUTER_NAME_FORMAT enumeration type. The following table provides additional information.
Value | Meaning |
---|---|
ComputerNameDnsDomain | The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS domain name of the cluster virtual server. |
ComputerNameDnsFullyQualified | The fully qualified DNS name that uniquely identifies the local computer. This name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. If the local computer is a node in a cluster, lpBuffer receives the fully qualified DNS name of the cluster virtual server. |
ComputerNameDnsHostname | The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the cluster virtual server. |
ComputerNameNetBIOS | The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the cluster virtual server. |
ComputerNamePhysicalDnsDomain | The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS domain name of the local computer, not the name of the cluster virtual server. |
ComputerNamePhysicalDnsFullyQualified | The fully qualified DNS name that uniquely identifies the computer. If the local computer is a node in a cluster, lpBuffer receives the fully qualified DNS name of the local computer, not the name of the cluster virtual server. The fully qualified DNS name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. |
ComputerNamePhysicalDnsHostname | The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the local computer, not the name of the cluster virtual server. |
ComputerNamePhysicalNetBIOS | The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the local computer, not the name of the cluster virtual server. |
A pointer to a buffer that receives the computer name or the cluster virtual server name.
The length of the name may be greater than MAX_COMPUTERNAME_LENGTH characters because DNS allows longer names. To ensure that this buffer is large enough, set this parameter to NULL and use the required buffer size returned in the lpnSize parameter.
On input, specifies the size of the buffer, in TCHARs. On output, receives 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_MORE_DATA. This parameter receives the size of the buffer required, including the terminating null character.
If lpBuffer is NULL, this parameter must be zero.
Return value
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. Possible values include the following.
Return code | Description |
---|---|
ERROR_MORE_DATA | The lpBuffer buffer is too small. The lpnSize parameter contains the number of bytes required to receive the name. |
Remarks
If group policy is not set for the local machine, the GetComputerNameEx function retrieves the NetBIOS or DNS names established at system startup. If group policy is set, the function returns the primary domain name set by group policy. Name changes made by the SetComputerName or SetComputerNameEx functions do not take effect until the user restarts the computer.
If the local computer is not configured to use DNS names, GetComputerNameEx will not return DNS information. To configure the computer to do this, follow the steps outlined in the operating system help and change the primary DNS suffix of the computer, then restart the computer.
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.
If you are working with environments that use different DNS layouts, where the computer’s FQDN does not match the FQDN of its domain, use LsaQueryInformationPolicy instead.
To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0500 or later. For more information, see Using the Windows Headers.
Examples
The sysinfoapi.h header defines GetComputerNameEx as an alias which 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 not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
GetComputerNameW function (winbase.h)
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.
Syntax
Parameters
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.
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.
Return value
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
The winbase.h header defines GetComputerName as an alias which 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 not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
GetComputerNameExA function (sysinfoapi.h)
Retrieves a NetBIOS or DNS name associated with the local computer. The names are established at system startup, when the system reads them from the registry.
Syntax
Parameters
The type of name to be retrieved. This parameter is a value from the COMPUTER_NAME_FORMAT enumeration type. The following table provides additional information.
Value | Meaning |
---|---|
ComputerNameDnsDomain | The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS domain name of the cluster virtual server. |
ComputerNameDnsFullyQualified | The fully qualified DNS name that uniquely identifies the local computer. This name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. If the local computer is a node in a cluster, lpBuffer receives the fully qualified DNS name of the cluster virtual server. |
ComputerNameDnsHostname | The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the cluster virtual server. |
ComputerNameNetBIOS | The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the cluster virtual server. |
ComputerNamePhysicalDnsDomain | The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS domain name of the local computer, not the name of the cluster virtual server. |
ComputerNamePhysicalDnsFullyQualified | The fully qualified DNS name that uniquely identifies the computer. If the local computer is a node in a cluster, lpBuffer receives the fully qualified DNS name of the local computer, not the name of the cluster virtual server. The fully qualified DNS name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. |
ComputerNamePhysicalDnsHostname | The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the local computer, not the name of the cluster virtual server. |
ComputerNamePhysicalNetBIOS | The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the local computer, not the name of the cluster virtual server. |
A pointer to a buffer that receives the computer name or the cluster virtual server name.
The length of the name may be greater than MAX_COMPUTERNAME_LENGTH characters because DNS allows longer names. To ensure that this buffer is large enough, set this parameter to NULL and use the required buffer size returned in the lpnSize parameter.
On input, specifies the size of the buffer, in TCHARs. On output, receives 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_MORE_DATA. This parameter receives the size of the buffer required, including the terminating null character.
If lpBuffer is NULL, this parameter must be zero.
Return value
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. Possible values include the following.
Return code | Description |
---|---|
ERROR_MORE_DATA | The lpBuffer buffer is too small. The lpnSize parameter contains the number of bytes required to receive the name. |
Remarks
If group policy is not set for the local machine, the GetComputerNameEx function retrieves the NetBIOS or DNS names established at system startup. If group policy is set, the function returns the primary domain name set by group policy. Name changes made by the SetComputerName or SetComputerNameEx functions do not take effect until the user restarts the computer.
If the local computer is not configured to use DNS names, GetComputerNameEx will not return DNS information. To configure the computer to do this, follow the steps outlined in the operating system help and change the primary DNS suffix of the computer, then restart the computer.
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.
If you are working with environments that use different DNS layouts, where the computer’s FQDN does not match the FQDN of its domain, use LsaQueryInformationPolicy instead.
To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0500 or later. For more information, see Using the Windows Headers.
Examples
The sysinfoapi.h header defines GetComputerNameEx as an alias which 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 not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.