根据 MA​​C 地址自动重命名计算机

根据 MA​​C 地址自动重命名计算机

如何根据计算机的 MAC 地址自动重命名计算机主机/名称?

我有 40 台 PC,我需要一个脚本,以便在使用 ghost 后登录时自动重命名它们。
我处于 Windows 7 环境中。

答案1

这是一篇相当古老的文章(2009 年 2 月):根据 MA​​C 地址更改计算机名称的脚本

在微软脚本论坛。几年前我用过它。

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

相关内容