是否可以使用Windows 2003自带工具在命令行中更改主机名?
是否可以使用Windows 2003自带工具在命令行中更改主机名?
之前提到的wmic
命令是一个很好的选择,因为它在最近版本的Windows中默认安装。以下是我的小改进,通过从环境中检索当前名称来实现通用化:
wmic computersystem where name="%COMPUTERNAME%"
call rename name="NEW-NAME"
注意:该命令必须在一行中输入,但我将其分成两行以避免出现滚动条。正如@rbeede所提到的,您需要重新启动以完成更新。
wmic
不随Windows XP一起提供。 - IdontCareAboutReputationPointswmic computersystem where name="%COMPUTERNAME%" rename "NEW-NAME"
- MOPO3OB命令(cmd):
netdom renamecomputer %COMPUTERNAME% /Newname "NEW-NAME"
PowerShell(Windows 2008/2012):
netdom renamecomputer "$env:COMPUTERNAME" /Newname "NEW-NAME"
之后,您需要重新启动计算机。
psexec.exe -h -e \\\IPADDRESS -u USERNAME -p PASSWORD netdom renamecomputer CurrentComputerName /newname:NewComputerName /force
我不知道有没有一个命令可以做到这一点,但你可以用VBScript或类似的东西来实现。像这样:
sNewName = "put new name here"
Set oShell = CreateObject ("WSCript.shell" )
sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"
With oShell
.RegDelete sTcpipParamsRegPath & "Hostname"
.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With ' oShell
MsgBox "Computer name changed, please reboot your computer"
可以使用netdom.exe命令行程序。该程序可从Windows XP支持工具或Server 2003支持工具(均在安装CD上)中获取。
使用指南此处
这是使用WHS脚本另一种实现方式:
Set objWMIService = GetObject("Winmgmts:root\cimv2")
For Each objComputer in _
objWMIService.InstancesOf("Win32_ComputerSystem")
objComputer.rename "NewComputerName", NULL, NULL
Next