Automatically rename computers based on their MAC address












1















How to automatically rename a 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.

I'm in a Windows 7 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















How to automatically rename a 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.

I'm in a Windows 7 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












1








1








How to automatically rename a 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.

I'm in a Windows 7 environment.










share|improve this question
















How to automatically rename a 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.

I'm in a Windows 7 environment.







windows-7 automation rename mac-address hostname






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 25 at 13:40









dirkt

9,44931221




9,44931221










asked Jul 18 '13 at 10:29









apoapo

1115




1115








  • 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





    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




1





Adding the operating system running on them might be a good idea.

– Mario
Jul 18 '13 at 10:31





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





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





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






active

oldest

votes


















0














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 & "rootdefault:StdRegProv")

strKeyPath = "SYSTEMCurrentControlSetControlComputerNameComputerName"
strValueName = "ComputerName"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
strValueName = "Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
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








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f621299%2fautomatically-rename-computers-based-on-their-mac-address%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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 & "rootdefault:StdRegProv")

strKeyPath = "SYSTEMCurrentControlSetControlComputerNameComputerName"
strValueName = "ComputerName"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
strValueName = "Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
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
















0














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 & "rootdefault:StdRegProv")

strKeyPath = "SYSTEMCurrentControlSetControlComputerNameComputerName"
strValueName = "ComputerName"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
strValueName = "Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
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














0












0








0







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 & "rootdefault:StdRegProv")

strKeyPath = "SYSTEMCurrentControlSetControlComputerNameComputerName"
strValueName = "ComputerName"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
strValueName = "Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
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















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 & "rootdefault:StdRegProv")

strKeyPath = "SYSTEMCurrentControlSetControlComputerNameComputerName"
strValueName = "ComputerName"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
strValueName = "Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
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














share|improve this answer



share|improve this answer








edited Jul 18 '13 at 16:02









Scott

15.9k113990




15.9k113990










answered Jul 18 '13 at 10:47









admintechadmintech

6,72812241




6,72812241








  • 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














  • 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








1




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





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





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


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f621299%2fautomatically-rename-computers-based-on-their-mac-address%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]