Find computer name from command line

by admin on January 29, 2009

You can find out your computer name from command line using hostname command.

c:\> hostname
techblogger-pc

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.

c:\>echo  %computername%
WINCMD-PC

c:\>

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.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: