Programming Field

Hostname - DOS/Command Prompt Reference

[Windows NT series?/XP or later] Outputs the hostname that refers to the computer where the program is executed (local computer).

Syntax

hostname[.exe]

No parameters/options available.

Details

The Hostname program internally outputs the result of the ‘GetHostNameW’ function (Microsoft Lean). While this function may return a name used in NetBIOS (computer name) as per specifications, it is not guaranteed to do so. Therefore, the output may differ from the name stored in the environment variable ‘COMPUTERNAME’.

Samples

Sample 1

for /f "delims=" %N in ('hostname') do set "MY_HOSTNAME=%N"

[Extensions] Sets the value of the environment variable ‘MY_HOSTNAME’ to the hostname output by the Hostname program.