Jump to content

Changing computer name

Recommended Posts

  • Moderators

To read, just use the @ComputerName macro.

For changing, is it on a network or not?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

If you are looking for a quick & dirty way (not over a network) using WMI, you could always take this as a starting point and work with it from there.


Func WMICall_PCRename($sPCName)
    Local $oResultItem, $oResultSet = ObjGet('winmgmts:\\localhost\ROOT\CIMV2')
    If IsObj($oResultSet) Then
        For $oResultItem In $oResultSet.InstancesOf('Win32_ComputerSystem')
EndFunc   ;==>WMICall_PCRename
Link to comment
Share on other sites

I never found a "clean" way to do it on the backend.  Every time I found a solution later I find it was for older versions of windows, or can have bad effects on the domain.  Seems that Windows actually does quite a lot when you set a computer name/description so it was best for me to just automate the normal manual way of doing a computer name change.

My code is simple as I just started autoit but may give you a place to start if you do not mind this sort of solution.

$desc = InputBox("Black Magic Installer", "What do you want as the Computer Description?")
If @Error = 1 Then

$pcname = InputBox("Black Magic Installer", "What do you want as the Computer Name?")

If @Error = 1 Then

WinWait("System Properties", "")
WinActivate("System Properties", "")
ControlSetText("System Properties", "", 122, $desc)
ControlClick("System Properties", "", 12321)
ControlClick("System Properties", "", 115)
WinWait("Computer Name/Domain Changes", "")
WinActivate("Computer Name/Domain Changes", "")
ControlSetText("Computer Name/Domain Changes", "", 1002, $pcname)
ControlClick("Computer Name/Domain Changes", "", 1)
WinWait("Computer Name/Domain Changes", "OK")
WinActivate("Computer Name/Domain Changes", "OK")
ControlClick("Computer Name/Domain Changes", "OK", "Button1")
WinActivate("System Properties", "")
Controlclick("System Properties", "", 1)
WinWait("Microsoft Windows", "Restart &Later")
WinActivate("Microsoft Windows", "Restart &Later")
ControlClick("Microsoft Windows", "Restart &Later", "Button2")
Link to comment
Share on other sites

If it's a domain computer you can use Netdom renamecomputer. BTW, you can use Netdom even if the computer isn't on a domain, just wanted to mention that. :)


NETDOM RENAMECOMPUTER machine /NewName:new-name
           [/userD:user [/PasswordD:[password | *]]]
           [/userO:user [/PasswordO:[password | *]]]
           [/REBoot[:Time in seconds]]

NETDOM RENAMECOMPUTER renames a computer. If the computer is joined to a
domain, then the computer object in the domain is also renamed. Certain
services, such as the Certificate Authority, rely on a fixed machine name.
If any services of this type are running on the target computer, then a
computer name change would have an adverse impact. This command should not
be used to rename a domain controller.

machine is the name of the workstation or member server to be renamed

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...