Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using wsname to rename workstations as they are deployed. i have a \logfile switch which changes the default location of the wsname logfile to a folder on the C drive. I want to change this to a network location however i need to be able to specify the name of file based on the mac address or the hostname in order to identify it from the other 20 computers that will be getting renamed at the same time. Is there a way to do it?


I have found that I can use the %computername% to rename the file to the computername. can it be done with mac addresses?

share|improve this question
up vote 1 down vote accepted

I assume you are using David Clarke's WSname.exe tool?

You might try the following snippet in your script to set the filename. It assumes that you have a single NIC, or that the last NIC is a good enough identifier:

for /f "tokens=1-15" %%a in ('ipconfig /all') do @echo %%a | find "Physical" > nul && set filename=%%l 
@echo My filename is %filename%

Explanation: Ipconfig /all gives NIC configuration information including the mac address. The line containing the mac address has the following format (Windows xp sp3, ymmv):

Physical Address. . . . . . . . . : 00-1A-1B-1C-1D-1E

This snippet pipes the output of ipconfig through find.exe and looks for "Physical" part of Physical Address. If Find.exe reports errorlevel=0 (success) it passes through the && to parse the remaining line and locate position "L" or the actual mac address. In this instance, it sets it to an environment variable called "filename".

This solution should produce the unique files you want, and uses native tools to a windows XP and higher OS. If using Vista or Windows 7, you may need to work with output of IPconfig specific to those platforms.


share|improve this answer
I also found a way that if i use the %computername% variable for the log file pathname i get a list of all the unique computernames that are attempting to be renamed which worked for me. – JohnyV Apr 27 '11 at 22:33
for /F %%a in ('wmic path win32_NetworkAdapterConfiguration where ^(IPEnabled^=^'true^' and DHCPEnabled^=^'true^'^) get MACAddress /value^| find "MACAddress"') do set %%a
set macadres=%macaddress%

In a batch file will set an environment variable macadres to the value of the active network card that has DHCP enabled (comes in handy in case there is only one active network card for example in case of booting over PXE).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.