change computername via script with variables

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
bbrink
Pro Scripter
Posts: 71
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

change computername via script with variables

Post by bbrink » Sat Nov 05, 2016 1:33 pm

Hi,

Has anyone figured out how to change computer name via script?

Ideally I would like to compile the script and pass it a variable at runtime that contains the new hostname.

run>ChangeComputerName.exe mynewmachinename

Thanks in advance,

Bob

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: change computername via script with variables

Post by CyberCitizen » Sun Nov 06, 2016 6:23 am

wmic computersystem where name="%computername%" call rename name="Computer-Name"

Search the forums there is an example of passing variables via command line on compiled executables.
FIREFIGHTER

bbrink
Pro Scripter
Posts: 71
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

Re: change computername via script with variables

Post by bbrink » Sun Nov 06, 2016 2:57 pm

Excellent! thank you for your help.

To "pay it forward" here is my full script and a few notes...
computername below is automatically picked up by WMIC, do not set it as a MS variable.
NewHostName below is passed as a parameter when the compiled macro EXE is run. See note above.

To change the computername to MyNewComputerName run this with a command line parameter:
RenamePCandReboote.exe /NewHostName=MyNewComputerName

Let>RP_Admin=1
Run>%SYS_NATIVE%\cmd.exe /c wmic computersystem where name="%computername%" call rename name="%NewHostName%"
wait>2
//restart computer, do not force it
ShutDownWindows>1

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts