0

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?

Thanks

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

JohnyV
  • 938
  • 4
  • 26
  • 45

2 Answers2

1

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.

Rob

RobW
  • 2,806
  • 1
  • 19
  • 22
  • 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
1
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).

Ben Pilbrow
  • 12,041
  • 5
  • 36
  • 57
R2D2
  • 11
  • 1