Get hostname and pass as a variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm writing a batch file trying to get the hostname of a local machine and
pass it on as a variable within the same file. Let's say in test.bat

@echo off

set n=
hostname

set n= (host name)

But, somehow it is not working. Any suggestion on how to get the hostname
and pass it on to a variable.

Thanks,

Mike
 
There is already an environmental variable already set to the host name !
COMPUTERNAME

To use, enclose in % (percent) signs.

For example; open a Command Prompt and type...

echo %COMPUTERNAME%

--
Dave




| Hi,
|
| I'm writing a batch file trying to get the hostname of a local machine and
| pass it on as a variable within the same file. Let's say in test.bat
|
| @echo off
|
| set n=
| hostname
|
| set n= (host name)
|
| But, somehow it is not working. Any suggestion on how to get the hostname
| and pass it on to a variable.
|
| Thanks,
|
| Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top