How do I change a local computer's name running XP to that of the Physical(Mac) Address with a dos script?

Hi Experts.

I would like to build a script which I would like to run on a computer which would firstly somehow extract a computers physical (Mac) Address from the NIC and use that value (00-22-64-75-90-BB --> 00226475BB) to update the Computers name.

I think that firstly a command like ipconfig /all will be run and the Physical Address that it displays must be put in an environment variable or piped to a text file. (Only the address itself without the "-" between each two characters.) After this value (00226475BB) is available it must be updated to the necessary fields or registry values to change the computer name.

Overview of expected solution:
1) Get Physical (Mac) Address and set value to environment variable or pipe value to text file.
2) Remove "-" from the environment variable or text file
3) Enter the value into the necessary environment variables or registry. (i dunno where?)

I need this script because I'm ghosting a bunch of computers and would like each of them to be uniquely identified by their Physical (Mac) Address. If somebody can help me with this I will look for a beggar and give him some money (200Eth Birr(20USD)). The person helping me would therefore help some poor bloke in Ethiopia. (I'm working in Addis Abeba) Any help will be greatly appreciated!

PS.I know that it's probably not the best place to say that Expert Exchange have helped me with plenty of solutions over the years and this is the first time that I actually had to ask an unasked question. I would like to thank all the Guys and Gals that have solved so many of my problems.
Rebel_no_1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Pearl_export_benConnect With a Mentor Commented:
only a slightly epic problem :P

Try this instead then... we'll do it through registry instead of NetDOM

'Creates a Network Object Variable - Used To Pull PC Name
Set oNetwork = CreateObject("WScript.Network")
 
'Gets Current PC Name
strComputer = oNetwork.ComputerName
strComputerName = oNetwork.ComputerName
 
'Uses WMI Service on Current Computer (Computer Name)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
 
'For Each Item Returned:
For Each objItem in colItems
 
'strComputer = Stripped Down MAC Address
strMAC = Replace(objItem.MACAddress, ":", "")
 
'Run's NETDOM (XP PC Rename) to strComputer (Stripped MAC)
const HKLM   = &H80000002
strKeyPath   = "System\CurrentControlSet\Control\ComputerName\ComputerName"
set objReg = GetObject("winmgmts:\\" & strComputer & _
                       "\root\default:StdRegProv")
intRC = objReg.SetStringValue(HKLM, strKeyPath, "ComputerName", strMAC)
if intRC <> 0 then
   WScript.Echo "Error setting ComputerName value: " & intRC
else
   WScript.Echo "Successfully set ComputerName value to " & strMAC
end if
 
strKeyPath   = "System\CurrentControlSet\Services\Tcpip\Parameters"
intRC = objReg.SetStringValue(HKLM, strKeyPath, "NV Hostname", strMAC)
if intRC <> 0 then
   WScript.Echo "Error setting NV Hostname value: " & intRC
else
   WScript.Echo "Successfully set NV Hostname value to " & strMAC
end if
 
WScript.Echo "Please Reboot Your PC..."
next

Open in new window

0
 
sjl1986Commented:
I'm not sure how to do what you want, but another idea is, whenever you ghost computers, you'll want to put in their original windows keys unless you are doing all corporate licensing. You get the machine the way you want it and then do a "reseal" on the computer, then create the ghost image. If you do it this way, the first time you boot up the machine after ghosting it will look like a new computer and ask you for the computer's name, user's name, and a few other settings. This will give you a chance to name each individual machine albeit by manually, but it will also let you put in the computers OEM XP key located on the side of the case so all your machines are legitimate (assuming they are OEMs).

Hope this helps. If you need info on how to do the reseal, let me know.
0
 
Pearl_export_benCommented:
Save this as a VBS Script and Run it...

Will do what is needed.
'Creates a Network Object Variable - Used To Pull PC Name
Set oNetwork = CreateObject("WScript.Network")
 
'Gets Current PC Name
strComputer = oNetwork.ComputerName
 
'Uses WMI Service on Current Computer (Computer Name)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
 
'For Each Item Returned:
For Each objItem in colItems
 
'strComputer = Stripped Down MAC Address
strComputer = Replace(objItem.MACAddress, ":", "")
 
'Run's NETDOM (XP PC Rename) to strComputer (Stripped MAC)
Dim shell
    Set shell = CreateObject("WScript.Shell")
	strComputer = ("NETDOM RENAMECOMPUTER machine /NewName:" & strComputer)
	shell.Run(strComputer)
Next

Open in new window

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Rebel_no_1Author Commented:
I am aware of the procedure that sjl1986 is refering to. Unfortunately I do not want to follow that route as time is critical in deploying this 'change' to each windows.

Pearl_export_ben: I have tried your script(Copied text out of your screen, copied to text file and changed file extension to .vbs). I however get an error saying:
Script: G:\New text document.vbs
Line: 22
Char: 9
Error: The system cannot find the file specified.
Code: 80070002
Source: (null)

Thank you for the speedy responses. Wow!
0
 
Pearl_export_benCommented:
Sorry - stupid mistake....

Replace this:
strComputer = ("NETDOM RENAMECOMPUTER machine /NewName:" & strComputer)

With This:

strComputer = ("NETDOM RENAMECOMPUTER " & oNetwork.ComputerName & " /NewName:" & strComputer")

I forgot that the word machine would need replacing with the current machine name..Sorry
0
 
Rebel_no_1Author Commented:
I tried the change and now get:
Script: G:\New text document.vbs
Line: 21
Char: 103
Error: Undetermined string constant
Code: 800A0409
Source: Microsoft VBScript compilation error

'Creates a Network Object Variable - Used To Pull PC Name
Set oNetwork = CreateObject("WScript.Network")
 
'Gets Current PC Name
strComputer = oNetwork.ComputerName
 
'Uses WMI Service on Current Computer (Computer Name)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
 
'For Each Item Returned:
For Each objItem in colItems
 
'strComputer = Stripped Down MAC Address
strComputer = Replace(objItem.MACAddress, ":", "")
 
'Run's NETDOM (XP PC Rename) to strComputer (Stripped MAC)
Dim shell
    Set shell = CreateObject("WScript.Shell")
        strComputer = ("NETDOM RENAMECOMPUTER " & oNetwork.ComputerName & " /NewName:" & strComputer")
        shell.Run(strComputer)
Next

Open in new window

0
 
Rebel_no_1Author Commented:
The actual error is:
Error: Unterminated string constant
not
Error: Undetermined string constant

Read the error too quickly... Sorry.
0
 
Pearl_export_benCommented:
Weird....  Works fine for me...

I've rewritten it slightly, so try this:

'Creates a Network Object Variable - Used To Pull PC Name
Set oNetwork = CreateObject("WScript.Network")
 
'Gets Current PC Name
strComputer = oNetwork.ComputerName
strComputerName = oNetwork.ComputerName
 
'Uses WMI Service on Current Computer (Computer Name)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
 
'For Each Item Returned:
For Each objItem in colItems
 
'strComputer = Stripped Down MAC Address
strComputer = Replace(objItem.MACAddress, ":", "")
 
'Run's NETDOM (XP PC Rename) to strComputer (Stripped MAC)
Dim shell
    Set shell = CreateObject("WScript.Shell")
        strComputer = ("NETDOM RENAMECOMPUTER " & strComputerName & " /NewName:" & strComputer")
        shell.Run(strComputer)
Next

Open in new window

0
 
Pearl_export_benCommented:
OK, got it...

There was a stupid extra Quote mark i missed:

Sorry for messing you around..

Ben
'Creates a Network Object Variable - Used To Pull PC Name
Set oNetwork = CreateObject("WScript.Network")
 
'Gets Current PC Name
strComputer = oNetwork.ComputerName
strComputerName = oNetwork.ComputerName
 
'Uses WMI Service on Current Computer (Computer Name)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
 
'For Each Item Returned:
For Each objItem in colItems
 
'strComputer = Stripped Down MAC Address
strMAC = Replace(objItem.MACAddress, ":", "")
 
'Run's NETDOM (XP PC Rename) to strComputer (Stripped MAC)
Dim shell
    Set shell = CreateObject("WScript.Shell")
        strComputer = ("NETDOM RENAMECOMPUTER " & strComputerName & " /NewName:" & strMAC)
        shell.Run(strComputer)
Next

Open in new window

0
 
Rebel_no_1Author Commented:
No prob!
I tried your last script. Again an error msg:
Script: G:\New text document.vbs
Line: 23
Char: 9
Error: The system cannot find the file specified
Code: 80070002
Source: (null)

I'll attach the text again exactly as I have it in the .vbs file. Maybe I'm copying like an ...

'Creates a Network Object Variable - Used To Pull PC Name
Set oNetwork = CreateObject("WScript.Network")
 
'Gets Current PC Name
strComputer = oNetwork.ComputerName
strComputerName = oNetwork.ComputerName
 
'Uses WMI Service on Current Computer (Computer Name)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
 
'For Each Item Returned:
For Each objItem in colItems
 
'strComputer = Stripped Down MAC Address
strMAC = Replace(objItem.MACAddress, ":", "")
 
'Run's NETDOM (XP PC Rename) to strComputer (Stripped MAC)
Dim shell
    Set shell = CreateObject("WScript.Shell")
        strComputer = ("NETDOM RENAMECOMPUTER " & strComputerName & " /NewName:" & strMAC)
        shell.Run(strComputer)
Next

Open in new window

0
 
Rebel_no_1Author Commented:
I look like a disc jockey with this memory stick between the two laptops...
haha!
0
 
Rebel_no_1Author Commented:
Just a stupid question: Do I have netdom standard with windows Xp or must I get it somewhere?
0
 
Pearl_export_benCommented:
Seems to be working at this end...

What OS you running?
test.jpg
0
 
Pearl_export_benCommented:
NetDOM is standard with XP Pro
0
 
Rebel_no_1Author Commented:
XP Pro SP2
Not updated or anything. I searched the drive for netdom and could not find it. Not sure if that might be a problem?
0
 
Rebel_no_1Author Commented:
My screenshot...

untitled.jpg
0
 
Rebel_no_1Author Commented:
I have tested the solution, rebooted and worked EXACTLY as I wanted it to. !!!   :-)   !!!

You are an absolute genius!!! thank you so much for your help. This site (and yourself) have absolutely made my day. I will keep my promise and donate 20USD to the first beggar I encounter tomorrow.

Thank you so much! May I ask to have your e-mail addr as I might have more work for you in future. Some of my work (most) involve systems with, let's say, operate countries on the highest level and I can't publish code which might jeopardize security protocols online...

Thanx Dude!
0
 
Rebel_no_1Author Commented:
Perfect solution utilizing only standard windows components and commands. Netdom also not required.
0
 
Pearl_export_benCommented:
email address will be on my profile in about 5 mins dude...

Take a lookie.
0
 
Rebel_no_1Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.