来一段吧,正准备自己用的Dim $sIP = @IPAddress1 ;取系统当前第1块网卡的IP地址
Dim $sIP_4 = StringSplit($sIP, ".") ;取IP地址中的各节
For $i = 1 To 4 ;将IP各节中不足3位的用0补足3位
Select
Case $sIP_4[$i] >= 0 And $sIP_4[$i] < 10
$sIP_4[$i] = "00" & $sIP_4[$i]
Case $sIP_4[$i] > 10 And $sIP_4[$i] < 100
$sIP_4[$i] = "0" & $sIP_4[$i]
EndSelect
Next
;Dim $NewName = "PC" & $sIP_4[1] & $sIP_4[2] & $sIP_4[3] & $sIP_4[4] ;取IP全部+PC为新名
;Dim $NewName = "PC" & $sIP_4[2] & $sIP_4[3] & $sIP_4[4] ;取IP后3节+PC为新名
Dim $NewName = "PC" & $sIP_4[3] & $sIP_4[4] ;取IP后2节+PC为新名
;Dim $NewName = "PC" & $sIP_4[4] ;取IP最后节+PC为新名
;以上4行只选用其中1行即可。建议使用后2节
;更改机器名
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", $NewName)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", $NewName)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName", $NewName)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", $NewName)
MsgBox(0, "提示", "新名是:" & $NewName & @LF & "建议重启电脑生效!")
|