Solved

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

Posted on 2009-05-11
20
455 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:Rebel_no_1
  • 11
  • 8
20 Comments
 
LVL 8

Expert Comment

by:sjl1986
ID: 24353895
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
 
LVL 8

Expert Comment

by:Pearl_export_ben
ID: 24354028
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
 

Author Comment

by:Rebel_no_1
ID: 24354116
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
 
LVL 8

Expert Comment

by:Pearl_export_ben
ID: 24354161
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
 

Author Comment

by:Rebel_no_1
ID: 24354229
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
 

Author Comment

by:Rebel_no_1
ID: 24354248
The actual error is:
Error: Unterminated string constant
not
Error: Undetermined string constant

Read the error too quickly... Sorry.
0
 
LVL 8

Expert Comment

by:Pearl_export_ben
ID: 24354254
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
 
LVL 8

Expert Comment

by:Pearl_export_ben
ID: 24354290
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
 

Author Comment

by:Rebel_no_1
ID: 24354352
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
 

Author Comment

by:Rebel_no_1
ID: 24354365
I look like a disc jockey with this memory stick between the two laptops...
haha!
0
Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

 

Author Comment

by:Rebel_no_1
ID: 24354390
Just a stupid question: Do I have netdom standard with windows Xp or must I get it somewhere?
0
 
LVL 8

Expert Comment

by:Pearl_export_ben
ID: 24354407
Seems to be working at this end...

What OS you running?
test.jpg
0
 
LVL 8

Expert Comment

by:Pearl_export_ben
ID: 24354418
NetDOM is standard with XP Pro
0
 

Author Comment

by:Rebel_no_1
ID: 24354454
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
 

Author Comment

by:Rebel_no_1
ID: 24354521
My screenshot...

untitled.jpg
0
 
LVL 8

Accepted Solution

by:
Pearl_export_ben earned 500 total points
ID: 24354534
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
 

Author Comment

by:Rebel_no_1
ID: 24354659
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
 

Author Closing Comment

by:Rebel_no_1
ID: 31580112
Perfect solution utilizing only standard windows components and commands. Netdom also not required.
0
 
LVL 8

Expert Comment

by:Pearl_export_ben
ID: 24354682
email address will be on my profile in about 5 mins dude...

Take a lookie.
0
 

Author Comment

by:Rebel_no_1
ID: 24354696
Thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now