Q. How can a batch retrieve the full DNS name of the current computer?

Jerold Schulman

December 18, 2006

1 Min Read
ITPro Today logo

The full DNS name my workstation is JSI009.JSIINC.COM and it's Common Name is JSI009.

Using standard commands, I have scripted FullDNSName.bat to retrieve the full DNS name of the current computer.

The syntax for using FullDNSName.bat is:

[call] FullDNSName Name

Where Name is a call directed environment variable that will contain the computer's full DNS name.

FullDNSName.bat contains:

@echo offif {%1}=={} @echo Syntax: FullDNSName Name&goto :EOFif exist "%TEMP%FullDNSName.vbs" goto [email protected] objSysInfo = CreateObject("ADSystemInfo") >"%TEMP%FullDNSName.vbs"@echo.strComputerDN = objSysInfo.ComputerName>>"%TEMP%FullDNSName.vbs"@echo.Set objComputer = GetObject("LDAP://" ^& strComputerDN)>>"%TEMP%FullDNSName.vbs"@echo.Wscript.Echo objComputer.dnsHostName>>"%TEMP%FullDNSName.vbs":doitset %1=Not Foundfor /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%FullDNSName.vbs"') do ( set %1=%%a)


Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like