From LedHed's Wiki
Jump to: navigation, search

How to set the hostname environment variable from a batch file.

for /f %%x in ('hostname.exe') do set hostname=%%x

Note: when running from the command line you only need 1 percent sign in front of the x.

for /f %x in ('hostname.exe') do set hostname=%x

Usage:

echo %hostname%

or

xcopy \\%hostname%\c$\temp \\computer2\c$\temp


OR


You can just use the %ComputerName% environment variable.

Guess I didn't know that when I originally wrote this article.