Equivalent of Linux command `hostname --fqdn` in Windows XP?

You can find it in the system properties ("Computer name" tab).

With the command line, you can run IPCONFIG /ALL and have a look at the "Host name" and "Primary DNS suffix" fields.


There is no such option to the hostname command in windows. However, this should do the trick:

echo %COMPUTERNAME%.%USERDNSDOMAIN%

Or you can grep (under Windows: find /I "string") for Host- and Domain from set or systeminfo or ipconfig -all name and glue it together elsewhere.

Edit: fixed Typo. Thanks Benoit

Update: The variable %USERDNSDOMAIN% is only available when logged on to a domain... The DNS suffix you get from a DHCP server is not put into a environment variable (as far as I could figure out).


The command is:

ping -a localhost

vbscript :

' Print FQDN in lower case letters
' Volker Fröhlich (2011)

option explicit
dim Message
dim output
dim WshShell, objEnv
dim mydomain

' Read value from registry
function readFromRegistry (strRegistryKey, strDefault )
    Dim WSHShell, value

    On Error Resume Next
    Set WSHShell = CreateObject("WScript.Shell")
    value = WSHShell.RegRead( strRegistryKey )

    if err.number <> 0 then
        readFromRegistry= strDefault
    else
        readFromRegistry=value
    end if

    set WSHShell = nothing
end function

mydomain = readfromRegistry("HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Domain", "asdf")

' Get the WshShell object
Set WshShell = CreateObject("WScript.Shell")

' Get collection by using the Environment property
Set objEnv = WshShell.Environment("Process")

if (mydomain="") then
Message = LCase(objEnv("COMPUTERNAME"))
else
Message = LCase(objEnv("COMPUTERNAME")) & "." & mydomain
end if

' Write to stdout
set output = wscript.stdout
output.writeline Message

DOS BATCH FILE TO CALL ABOVE SCRIPT :

for /f %%a in ('cscript //nologo yourscriptname.vbs') do set FQDN=%%a
echo %FQDN%
pause

Try this from the command prompt:

FOR /F "tokens=2" %i in ('systeminfo ^| find /i "Domain"') do echo %computername%.%i

remember to use double % for %i if using this in a batchfile. e.g. %%i

A reason you may want to do it this way is: if your users and computers are in different domains, the %USERDNSDOMAIN% will not be correct when applied to your computer. If you only have one domain and no child domains, then you can use the other solutions above if you like.