Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to automatically rename computer host / name based on it's MAC address? I have 40 PC's and I need a script to rename them automatically at logon after I use ghost. Win7 environment.

share|improve this question
1  
Adding the operating system running on them might be a good idea. –  Mario Jul 18 '13 at 10:31
    
Have you considered using DHCP? –  Scott Jul 18 '13 at 16:05
    
I am using Linux server with Win clients. I use dhcp to assign ip basedd on each MAC. Can I use dhcp to configure Windows host name? –  apo Jul 19 '13 at 8:57

1 Answer 1

This is quite an old (February 2009) article: Script to change computer name based on MAC address at Microsoft’s Scripting forums. I used it a couple of years ago.

Sub ChangeCompName(strComputer,Seg,IP)
'==============================================================================================
'This Sub Changes the Computer Name according to a Constant Value and the IP address entered
'It Changes the ComputerName key in the Registry and some other keys to do so
'==============================================================================================
const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
 strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName"
strValueName = "ComputerName"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
strValueName = "Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
strValueName = "NV Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


objFile.WriteLine "Computer Name: " & strValue
'==============================================================================================
'Write the new computer name to the Log
'==============================================================================================
End Sub
share|improve this answer
1  
Note: As stated in the article (from which this script was copied) and in the comments in the script itself, this works with IP address (or at least it claims to), rather than MAC address as requested. Worse, it appears to take the IP address as a parameter. Can you explain how the OP would invoke this script, and how the invoking method could obtain the MAC address? –  Scott Jul 18 '13 at 16:04
    
I have to use a batch file to run straight after the ghost and all the parameters should be in a single .txt file (ex. 00-00-00-00-01=pc-01 etc). –  apo Jul 19 '13 at 7:16

Your Answer

 
discard

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.