Sign in to follow this  
Followers 0
Ibrahim

change computer name

26 posts in this topic

in windows xp i want to change my computer name without having to restart my computer would somebody please help oding that in autoit as i did a program to change mac address and ip address but computer name requirs a reboot to be changed

Share this post


Link to post
Share on other sites



;====================================================================================
; Fix Computer Name & Workgroup Name Script
; by: tHe SkInNy WhItE GuY
; 03-06-2007
;====================================================================================

; Initialize Settings
#include <GUIConstants.au3>
#NoTrayIcon

; Initialize Variables Needed
Dim $CompName, $Workgroup, $dir_create

; Build Forms to ask User for New Name and Workgroup Selection Box
Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("Name Changer", 200, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Enter the name and workgroup to set on this computer", 10, 10, 180, 30)
GUICtrlCreateLabel("Name", 10, 40, 70, 20)
GUICtrlCreateLabel("Workgroup", 10, 60, 70, 20)
$inp_name = GUICtrlCreateInput("", 80, 40, 100, 20)
$inp_group = GUICtrlCreateInput("", 80, 60, 100, 20)
$set = GUICtrlCreateButton("Set", 70, 90, 60)
GUICtrlSetOnEvent($set, "Set_Names")
GUISetState(@SW_SHOW)

While 1
    Sleep(1000) ; Idle around
WEnd

Func Set_Names()
; Name & Workgroup Name
    $CompName = GUICtrlRead($inp_name, 1)
    $Workgroup = GUICtrlRead($inp_group, 1)
    GUICtrlSetState($inp_name, $GUI_DISABLE)
    GUICtrlSetState($inp_group, $GUI_DISABLE)
    GUICtrlSetData($set, "Updating...")
    GUICtrlSetState($set, $GUI_DISABLE)

; Install needed files onto the computer
    FileInstall ("NetDom.exe", @TempDir & "NetDom.exe", 1)

; Make some registry changes to also change the name now
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname")

    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_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_USERS\.Default\Software\Microsoft\Windows Media\WMSDK\General", "Computername", "REG_SZ", $CompName)

; Change Workgroup with Netdom.exe
    RunWait (@TempDir & "Netdom.exe Member \\" & $CompName & " /JOINWorkgroup " & $Workgroup, "", @SW_HIDE)

; Remove needed files
    FileDelete (@TempDir & "NetDom.exe")

    MsgBox(0, "Done", "Computer was renamed to """ & $CompName & """ and workgroup was set to """ & $Workgroup & """.")
    GUICtrlSetState($inp_name, $GUI_ENABLE)
    GUICtrlSetState($inp_group, $GUI_ENABLE)
    GUICtrlSetData($set, "Set")
    GUICtrlSetState($set, $GUI_ENABLE)
EndFunc  ;==>Set_Names

Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked

That code requires Netdom.exe to exist in the same directory as the script when you compile it/run it, search on google, it's free, and it's only needed for changing the Workgroup name as well, so if you don't need that, just edit out the lines that use it, and have fun.

Share this post


Link to post
Share on other sites

Uh, I use it at work, and my method above correctly changes the PC name without needing a reboot. Run it, then check your System Properties for the change.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

yup i know but it takes long time to be effective in the network i need to make it immediate

I"m just guessing here but maybe you could use in the end of the script proposed about --> ipconfig /release, ipconfig /renew so the network stuff would be resent?

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

basically I don't think it is possible to rename A PC without reboot..

I would like to see someone prove me wrong but I'm quite confident on this one..

the computername is easy to change (plenty of different approaches to do it) but TCP/IP will be the root of the problem..

(try pinging the computers' new hostname before reboot, or the old hostname for that matter)


Share this post


Link to post
Share on other sites

well that man script does it and without a reboot the problem is the long time the server service takes to apply changes,except for that this script does it

Share this post


Link to post
Share on other sites

That's why if you release your IP address, the new address will be associated with the new hostname. Did you even try it?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

C:\Documents and Settings\Family>ipconfig /release

Windows IP Configuration

The operation failed as no adapter is in the state permissible for

this operation.

C:\Documents and Settings\Family>ipconfig /renew

Windows IP Configuration

The operation failed as no adapter is in the state permissible for

this operation.

first off all i use static ip and second of i guess it's never related and last but not least i really thank you guys for the effort

Edited by Ibrahim

Share this post


Link to post
Share on other sites

What is the environment you are doing this in ?

AD/DHCP/Dynamic DNS or something else ?

How do you determine that the hostname didn't change ?

You are aware the a PC doesn't do a DNS lookup everytime a hostname/IPaddress is provide but has its own cache in which the DNS entries are cached for a period as define by TTL ?

To flush that use: IPconfig /flushdns


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

well that man script does it and without a reboot the problem is the long time the server service takes to apply changes,except for that this script does it

My guess would be to restart the server service, have you tried that??

(restarting fixes a lot in windows... :) )

Edited by TzarAlkex

Share this post


Link to post
Share on other sites

well as to know that my computer name has changed "nbtstat -R" "nbtstat -A 10.0.0.33" restarting the server service is the first thing i did,but i can try something else restarting the network connection never done that.realy thank you guys,gonna give it a try

Share this post


Link to post
Share on other sites

Guys, i did it thanks alot for your help and thank you skinnywhite guy for ur reply couldn't do it without your help and never know the netdom tool ,and guys all you have to do is to repair your network connection as ipconfig /release,renew isn't working with static ip addresses and repairing will flush all changable data, Thanks again

Share this post


Link to post
Share on other sites

;====================================================================================
; Fix Computer Name & Workgroup Name Script
; by: tHe SkInNy WhItE GuY
; 03-06-2007
;====================================================================================

; Initialize Settings
#include <GUIConstants.au3>
#NoTrayIcon

; Initialize Variables Needed
Dim $CompName, $Workgroup, $dir_create

; Build Forms to ask User for New Name and Workgroup Selection Box
Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("Name Changer", 200, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Enter the name and workgroup to set on this computer", 10, 10, 180, 30)
GUICtrlCreateLabel("Name", 10, 40, 70, 20)
GUICtrlCreateLabel("Workgroup", 10, 60, 70, 20)
$inp_name = GUICtrlCreateInput("", 80, 40, 100, 20)
$inp_group = GUICtrlCreateInput("", 80, 60, 100, 20)
$set = GUICtrlCreateButton("Set", 70, 90, 60)
GUICtrlSetOnEvent($set, "Set_Names")
GUISetState(@SW_SHOW)

While 1
    Sleep(1000) ; Idle around
WEnd

Func Set_Names()
; Name & Workgroup Name
    $CompName = GUICtrlRead($inp_name, 1)
    $Workgroup = GUICtrlRead($inp_group, 1)
    GUICtrlSetState($inp_name, $GUI_DISABLE)
    GUICtrlSetState($inp_group, $GUI_DISABLE)
    GUICtrlSetData($set, "Updating...")
    GUICtrlSetState($set, $GUI_DISABLE)

; Install needed files onto the computer
    FileInstall ("NetDom.exe", @TempDir & "NetDom.exe", 1)

; Make some registry changes to also change the name now
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname")

    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_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_USERS\.Default\Software\Microsoft\Windows Media\WMSDK\General", "Computername", "REG_SZ", $CompName)

; Change Workgroup with Netdom.exe
    RunWait (@TempDir & "Netdom.exe Member \\" & $CompName & " /JOINWorkgroup " & $Workgroup, "", @SW_HIDE)

; Remove needed files
    FileDelete (@TempDir & "NetDom.exe")

    MsgBox(0, "Done", "Computer was renamed to """ & $CompName & """ and workgroup was set to """ & $Workgroup & """.")
    GUICtrlSetState($inp_name, $GUI_ENABLE)
    GUICtrlSetState($inp_group, $GUI_ENABLE)
    GUICtrlSetData($set, "Set")
    GUICtrlSetState($set, $GUI_ENABLE)
EndFunc  ;==>Set_Names

Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked

That code requires Netdom.exe to exist in the same directory as the script when you compile it/run it, search on google, it's free, and it's only needed for changing the Workgroup name as well, so if you don't need that, just edit out the lines that use it, and have fun.

Thanks to "SkinnyWhiteGuy", this is exactly what I've been looking for! the script works like a charm.

Share this post


Link to post
Share on other sites

Hi, I need some expert help and thanks for any feedback.

I got this working under Vista x64. Now I created a php script to create a random name

in 8 character bit as the computer name. I created an au3 to extract the random characters

but I'm stuck integrating it into this code.

What I wanted is that the computer is random and the workgroup is the same, and when this

au3 or compiled exe is run it will change automatically.

I hope I get my point across.

I know this is easy for some but I'm new to autoit.

Local $sData = InetRead("http://localhost/demo/changepcname.php")
Local $nBytesRead = @extended
MsgBox(4096, "", "Code: " & BinaryToString($sData))

and changepcname.php

<?php
$secret = 'some secret key here';
$hash = md5($secret . mt_rand());
echo substr(strtoupper(base64_encode($hash)),0,8);
?>

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

;====================================================================================
; Fix Computer Name & Workgroup Name Script
; by: tHe SkInNy WhItE GuY
; 03-06-2007
;====================================================================================

; Initialize Settings
#include <GUIConstants.au3>
#NoTrayIcon

; Initialize Variables Needed
Dim $CompName, $Workgroup, $dir_create

; Build Forms to ask User for New Name and Workgroup Selection Box
Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("Name Changer", 200, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Enter the name and workgroup to set on this computer", 10, 10, 180, 30)
GUICtrlCreateLabel("Name", 10, 40, 70, 20)
GUICtrlCreateLabel("Workgroup", 10, 60, 70, 20)
$inp_name = GUICtrlCreateInput("", 80, 40, 100, 20)
$inp_group = GUICtrlCreateInput("", 80, 60, 100, 20)
$set = GUICtrlCreateButton("Set", 70, 90, 60)
GUICtrlSetOnEvent($set, "Set_Names")
GUISetState(@SW_SHOW)

While 1
    Sleep(1000) ; Idle around
WEnd

Func Set_Names()
; Name & Workgroup Name
    $CompName = GUICtrlRead($inp_name, 1)
    $Workgroup = GUICtrlRead($inp_group, 1)
    GUICtrlSetState($inp_name, $GUI_DISABLE)
    GUICtrlSetState($inp_group, $GUI_DISABLE)
    GUICtrlSetData($set, "Updating...")
    GUICtrlSetState($set, $GUI_DISABLE)

; Install needed files onto the computer
    FileInstall ("NetDom.exe", @TempDir & "NetDom.exe", 1)

; Make some registry changes to also change the name now
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname")

    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_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_USERS\.Default\Software\Microsoft\Windows Media\WMSDK\General", "Computername", "REG_SZ", $CompName)

; Change Workgroup with Netdom.exe
    RunWait (@TempDir & "Netdom.exe Member \\" & $CompName & " /JOINWorkgroup " & $Workgroup, "", @SW_HIDE)

; Remove needed files
    FileDelete (@TempDir & "NetDom.exe")

    MsgBox(0, "Done", "Computer was renamed to """ & $CompName & """ and workgroup was set to """ & $Workgroup & """.")
    GUICtrlSetState($inp_name, $GUI_ENABLE)
    GUICtrlSetState($inp_group, $GUI_ENABLE)
    GUICtrlSetData($set, "Set")
    GUICtrlSetState($set, $GUI_ENABLE)
EndFunc  ;==>Set_Names

Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked

That code requires Netdom.exe to exist in the same directory as the script when you compile it/run it, search on google, it's free, and it's only needed for changing the Workgroup name as well, so if you don't need that, just edit out the lines that use it, and have fun.

It seems that not any version of Netdom.exe works... the latest version doesn't even have the same syntax nor functionality to change workgroup.

I did however find the version that works (v1.8)

ftp://ftp.microsoft.com/reskit/nt4/x86/

cheers!

Edited by faldo

Share this post


Link to post
Share on other sites

;====================================================================================
; Fix Computer Name & Workgroup Name Script
; by: tHe SkInNy WhItE GuY
; 03-06-2007
;====================================================================================

; Initialize Settings
#include <GUIConstants.au3>
#NoTrayIcon

; Initialize Variables Needed
Dim $CompName, $Workgroup, $dir_create

; Build Forms to ask User for New Name and Workgroup Selection Box
Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("Name Changer", 200, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Enter the name and workgroup to set on this computer", 10, 10, 180, 30)
GUICtrlCreateLabel("Name", 10, 40, 70, 20)
GUICtrlCreateLabel("Workgroup", 10, 60, 70, 20)
$inp_name = GUICtrlCreateInput("", 80, 40, 100, 20)
$inp_group = GUICtrlCreateInput("", 80, 60, 100, 20)
$set = GUICtrlCreateButton("Set", 70, 90, 60)
GUICtrlSetOnEvent($set, "Set_Names")
GUISetState(@SW_SHOW)

While 1
    Sleep(1000) ; Idle around
WEnd

Func Set_Names()
; Name & Workgroup Name
    $CompName = GUICtrlRead($inp_name, 1)
    $Workgroup = GUICtrlRead($inp_group, 1)
    GUICtrlSetState($inp_name, $GUI_DISABLE)
    GUICtrlSetState($inp_group, $GUI_DISABLE)
    GUICtrlSetData($set, "Updating...")
    GUICtrlSetState($set, $GUI_DISABLE)

; Install needed files onto the computer
    FileInstall ("NetDom.exe", @TempDir & "NetDom.exe", 1)

; Make some registry changes to also change the name now
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
    RegDelete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname")

    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_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $CompName)
    RegWrite ("HKEY_USERS\.Default\Software\Microsoft\Windows Media\WMSDK\General", "Computername", "REG_SZ", $CompName)

; Change Workgroup with Netdom.exe
    RunWait (@TempDir & "Netdom.exe Member \\" & $CompName & " /JOINWorkgroup " & $Workgroup, "", @SW_HIDE)

; Remove needed files
    FileDelete (@TempDir & "NetDom.exe")

    MsgBox(0, "Done", "Computer was renamed to """ & $CompName & """ and workgroup was set to """ & $Workgroup & """.")
    GUICtrlSetState($inp_name, $GUI_ENABLE)
    GUICtrlSetState($inp_group, $GUI_ENABLE)
    GUICtrlSetData($set, "Set")
    GUICtrlSetState($set, $GUI_ENABLE)
EndFunc  ;==>Set_Names

Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked

That code requires Netdom.exe to exist in the same directory as the script when you compile it/run it, search on google, it's free, and it's only needed for changing the Workgroup name as well, so if you don't need that, just edit out the lines that use it, and have fun.

A couple of minor additions to improve SWG's code are a validity check to ensure that you're not trying to set a computer name with illegal characters.

I believe the following covers all of the illegal characters

if StringRegExp($name, '\\|/|:|\*|\?|"|<|>|\.|,|~|!|@|#|\$|%|\^|&|\(|\)|\;|{|}|_|=|\+|\[|\]|\x60' & "|'", 0) = 0 Then
        MsgBox(0,"", "Legal")
endif

\x60 is the italicised '

As part of my project, I also need to set the Computer Description to be the same as the computer name.

RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters", "srvcomment", "REG_SZ", $CompName)

Both have been tested in Windows XP. One minor prob I'm having is that the Computer Description isn't being updated until I reboot. If anybody has any tip to get that to refresh immediately, it would be appreciated.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I'm not sure if you are interested, but all this can be done very cleanly through WMI. There's documented functions for it and everything. But you will always require a reboot if you change anything related to the computer name or description. I think you can get away with changing workgroup/domain without a restart though.

I just finished a project doing this exact thing (changing computer name/workgroup/dhcp settings) for computers we image in our corporate computer lab. We run CloneZilla and needed an alternative to sysprep. I used DRBL-Winroll for a while, but it's a 120MB installation because of the Cygwin requirement. I wrote the same thing in AutoIt using SrvAny in about 400KB.

Edited by wraithdu

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  
Followers 0