Jump to content
Sign in to follow this  
PDowning

Change computer name

Recommended Posts

PDowning

My next project is to get a script working that will read the generic pc name given after imaging with Win7, allow input for new name, and write that data back. The machines are currently NOT on AD, but will be starting this summer.

I can read the @Computername, but am I correct that you can NOT write BACK to that value to change it? Is the only way to accomplish this is to find the reg values and write back those?

Anyone else tried this yet?

Thanks in advance

Edited: We are using Dell PC's and currently use the Service Tag as part of the ComputerName. Room# - ServiceTag. So the ST needs to be pulled from the system, and appended to the end of the computername. I have found a thread with reg entries that I am going to try.

Edited by PDowning

Share this post


Link to post
Share on other sites
careca

Never tried with autoit, but this is what i got:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"DefaultUserName"="Whatever"
"DefaultDomainName"="Whatever"
Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Keithdib

try a piece of software called "wsname.exe" this will rename the machine for you in multiple ways, depending what naming convention you use

Share this post


Link to post
Share on other sites
spudw2k

Perhaps this will provide you the mechanism you need.

http://blogs.technet.com/b/askds/archive/2009/02/19/renaming-a-computer-using-wmic-and-how-to-get-around-that-aggravating-invalid-global-switch-error.aspx

Share this post


Link to post
Share on other sites
JLogan3o13

As you mention you will be moving the PCs into AD shortly, I would suggest the AD UDF when you get to that point: http://www.autoitscript.com/forum/index.php?showtopic=106163

With the UDF, you should be able to rename them with _AD_RenameObject()

In the meantime, this should work just fine:

#RequireAdmin

$newName = InputBox("Rename PC", "What would you like the new name to be?")
$WMI = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
$aItems = $WMI.ExecQuery ("Select Name from Win32_ComputerSystem")

 For $element In $aItems
  $action = $element.Rename($newName)
    If $action <> 0 Then
    MsgBox(0, "Error - " & $action, "Error renaming PC")
  Else
   Shutdown(6)
  EndIf
 Next

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
PDowning

I did find this command via google. I can get it to output the service tag to a text file. Then I can read that into a string variable and append the inputted computer name into a variable and write that variable to the reg entries. Or am I making that too difficult?

Share this post


Link to post
Share on other sites
careca

I guess it's up to you, i think that would work.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
spudw2k
PDowning

#include

local $cmd = _RunDos("wmic csproduct get identifyingnumber > c:\users\public\st.txt") ;Runs hidden cmd, pulls service tag and writes to st.txt
$room=InputBox('Renamer v0.1','Please Enter Room Number') ;Allows user to input name for workstation
$stag=FileReadLine('c:\users\public\st.txt',2) ;pull service tag from generated text file
$CompName=($room&'-'&$stag) ;appends service tag to room number giving us the new workstation name

MsgBox(0,'test',$CompName) ;for debugging

;write reg keys to change workstation name
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Computername\Computername", "Computername", "REG_SZ", $CompName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername", "Computername", "REG_SZ", $CompName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $CompName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $CompName)
RegWrite ("HKEY_USERS\.Default\Software\Microsoft\Windows Media\WMSDK\General", "Computername", "REG_SZ", $CompName)

In theory this works. One minor problem, win7 won't let me write to the Local_Machine section. I did a test script to write to the other root keys and it works fine, ust can't write to LM. Anyone got an idea?

Edited: Sorta fixed. Turn UAC off and I can write to the LM key. But since the name is changed it won't reboot properly.

Edited by PDowning

Share this post


Link to post
Share on other sites
JLogan3o13

Try with #RequireAdmin at the top


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
PDowning

Well, got it working by turning UAC off. But as I said in my edit, it changes the regkeys while Windows is running and when it attempts to reboot, it blue screens. There is a step that I'm missing somewhere in the rename process that MS uses that keeps it from dying during a name change.

Share this post


Link to post
Share on other sites
careca

Create a batch with the instructions to import the reg file, or to execute your compiled script, or whatever, and then go to gpedit.msc -> computer configuration -> scripts (Startup/Shutdown) -> Double click shutdown in the right pane, add the file to be executed uppon shutdown, and maybe this way it can work. dunno


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
PDowning

Create a batch with the instructions to import the reg file, or to execute your compiled script, or whatever, and then go to gpedit.msc -> computer configuration -> scripts (Startup/Shutdown) -> Double click shutdown in the right pane, add the file to be executed uppon shutdown, and maybe this way it can work. dunno

i'll give that a shot ...

Edited: How would I get the $CompName value OUT to the batch file? I don't see a way to do that.

Edited by PDowning

Share this post


Link to post
Share on other sites
careca

Create the batch with autoit, like, grab the data from the txt file "X", add the variable data to it,

create new file paste all data, rename, in my mind this is making sense..doesn't mean it's simple,

Can't think of if you can rename extensions..

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
kylomas

PDowning,

I think I would persue the solution that JLogan3o13 offered. Using a system interface is safer (in my opinion) than operating directly on the registry. The fact that you are having boot problems lends some credence to this.

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Keithdib

If you use "wsname" all you need to do is run as follows

wsname.exe /N:$SERIALNUM or

wsname.exe /N:$ASSETTAG

etc etc

Share this post


Link to post
Share on other sites
PDowning

I've got it working with netdom considering we are going thru the process of converting to AD. It's not a pretty script, but it is working and does what is needed.

Thanks for the suggestions and prods in the proper direction.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×