How to store the hostname in a variable in a .bat file?

hmm – something like this?

set host=%COMPUTERNAME%
echo %host%

EDIT: expanding on jitter’s answer and using a technique in an answer to this question to set an environment variable with the result of running a command line app:

@echo off
hostname.exe > __t.tmp
set /p host=<__t.tmp
del __t.tmp
echo %host%

In either case, ‘host’ is created as an environment variable.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)