Change windows hostname from command line [closed]

2019-01-21 16:55发布

Is it possible to change the hostname in Windows 2003 from the command line with out-of-the-box tools?

8条回答
祖国的老花朵
2楼-- · 2019-01-21 17:23

cmd (command):

netdom renamecomputer %COMPUTERNAME% /Newname "NEW-NAME"

powershell (windows 2008/2012):

netdom renamecomputer "$env:COMPUTERNAME" /Newname "NEW-NAME"

after that, you need to reboot your computer.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-21 17:27

Here's another way of doing it with a WHS script:

Set objWMIService = GetObject("Winmgmts:root\cimv2")

For Each objComputer in _
    objWMIService.InstancesOf("Win32_ComputerSystem")

    objComputer.rename "NewComputerName", NULL, NULL 
Next

Source

查看更多
来,给爷笑一个
4楼-- · 2019-01-21 17:29

The netdom.exe command line program can be used. This is available from the Windows XP Support Tools or Server 2003 Support Tools (both on the installation CD).

Usage guidelines here

查看更多
Summer. ? 凉城
5楼-- · 2019-01-21 17:30

Use below command to change computer hostname remotely , Require system reboot after change..

psexec.exe -h -e \\\IPADDRESS -u USERNAME -p PASSWORD netdom renamecomputer CurrentComputerName /newname:NewComputerName /force

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-21 17:32

If you are looking to do this from Windows 10 IoT, then there is a built in command you can use:

setcomputername [newname]

Unfortunately, this command does not exist in the full build of Windows 10.

查看更多
等我变得足够好
7楼-- · 2019-01-21 17:38

Why be easy when it can be complicated? Why use third-party applications like netdom.exe when correct interogations is the way? Try 2 interogations:

wmic computersystem where caption='%computername%' get caption, UserName, Domain /format:value

wmic computersystem where "caption like '%%%computername%%%'" get caption, UserName, Domain /format:value

or in a batch file use loop

for /f "tokens=2 delims==" %%i in ('wmic computersystem where "Caption like '%%%currentname%%%'" get UserName /format:value') do (echo. UserName- %%i)

查看更多
登录 后发表回答