≡ Menu

Find computer name from command line

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.

Get DNS or FQDN(fully qualified domain name) of the computer

net config workstation | findstr /C:"Full Computer name"

Find computer name using wmic

wmic computersystem  get name
7 comments… add one
  • Shahi

    net config works on win7 to get fqdn name. but it’s printing as below

    Full Computer name   mypc.mydomain.com

    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.

    • HELPER

      YOU NEED TO USE FOR /F %%

  • swar

    Help Needed

    In network i want to know PC name with the help of user id to know on which machine he login into ?
    Cmd pls

  • LiRo

    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”

    Is it possible?

  • anzor

    hi. i have 2 pc. my compiuter name is m110pc-01 and m140pc-01.
    how can i delete prefix >M< and live everything. 110pc-01 and 140pc-01
    with comand line

  • rookie_b

    echo %computername%%userdnsdomain%

  • RC

    Excellent. Thanks a lot for this!

Leave a Comment