rlemoine002 Posted September 2, 2014 Share Posted September 2, 2014 I am trying to find an easy AutoIt solution to both read and change a computer name. I have been up and down the command listing, but failed to see anything. Please help. Thank you. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 2, 2014 Moderators Share Posted September 2, 2014 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 More sharing options...
Wruck Posted September 2, 2014 Share Posted September 2, 2014 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. WMICall_PCRename('MyNewName') Func WMICall_PCRename($sPCName) Local $oResultItem, $oResultSet = ObjGet('winmgmts:\\localhost\ROOT\CIMV2') If IsObj($oResultSet) Then For $oResultItem In $oResultSet.InstancesOf('Win32_ComputerSystem') $oResultItem.Rename($sPCName) Next EndIf EndFunc ;==>WMICall_PCRename Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 2, 2014 Share Posted September 2, 2014 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 Else $pcname = InputBox("Black Magic Installer", "What do you want as the Computer Name?") EndIf If @Error = 1 Then Else ShellExecute("C:\Windows\System32\sysdm.cpl") 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") EndIf Link to comment Share on other sites More sharing options...
BrewManNH Posted September 2, 2014 Share Posted September 2, 2014 (edited) 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 | *]]] [/Force] [/REBoot[:Time in seconds]] [/securePasswordPrompt] 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 September 2, 2014 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 GudeHow 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 More sharing options...
rlemoine002 Posted September 19, 2014 Author Share Posted September 19, 2014 I want to thank everybody for their input. Sorry I didn't reply any sooner, but this is a part time project that I work on as time allows. I will be checking out the solutions above. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now