Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Machine Name from Command Line

Status
Not open for further replies.

lifegard2

IS-IT--Management
Mar 28, 2002
250
US
Anyone know how to get the machine name from a command line?

I have a batch file that I want to run that needs to be able to detect if it's running on a certain PC (mine), or being run from accross the network on another PC. If it's being run on my PC, all the commands need to be called locally with c:\ whereas if it's run accross the network, the commands need to be called remotely with \\pcname\c$\. Any ideas?
 
just type HOSTNAME from the command prompt. It should be located in \winnt\system32
 
I'm trying to do it without using any SET variables in the autoexec or System Properties.

The hostname utility works great, but I can't assign it to a variable. For instance, if I do:

set pc = hostname

I run into a wall. Admittedly my batch scripting isn't the best. Any ideas on how to assign a variable name to hostname?
 
How about HOSTNAME >c:\myhost.txt for example.

This will pipe the HOSTNAME value to a file, which you can then play with in your batch file....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top