I found a vbscript from http://www.swynk.com/ to rename the PC and join to domain

It requires NTDOM.exe SHUTDOWN.EXE and SScrRun.dll, This DLL need to be registered.

It works fine in NT4 I made some changes for W2K but still it is giving some problems sometime, ast time it do the job otherwise it'll just rename the PC but dosent join to domain

Since I am not expert in VBscripting I am submitting this one to you for review.

If somebody can convert it to KIX it would be very nice

code:
Option Explicit

Dim objRegistry, objRegRem, objValue, OldPCName, NewPCName, oWshShell, test, Command

OldPCName = InputBox("Type in the PC you wish to rename")
NewPCName = InputBox("Type in the new name of the PC")

Set objRegistry = CreateObject("RegObj.Registry")
Set objRegRem = objRegistry.RemoteRegistry(OldPCName)
Set oWshShell = CreateObject("WScript.Shell")


RemoveDomain()
EditValueComputerName()
EditValueParameters()
Reboot()
JoinDomain()

Function RemoveDomain()
oWshShell.Run "netdom.exe MEMBER \\" & OldPCName & " /joinworkgroup workgroup", 1, TRUE
End Function

Function EditValueComputerName()
Set objValue = objRegRem.RegKeyFromString("\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName")
objValue.Values.Remove ("ComputerName")
objValue.Values.Add "ComputerName", NewPCName,1 'Recreates value with new pc name
End Function

Function EditValueParameters()
Set objValue = objRegRem.RegKeyFromString("\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters")
objValue.Values.Remove ("Hostname")
objValue.Values.Add "Hostname", NewPCName,1 'Recreates value with new pc name
Set objValue = objRegRem.RegKeyFromString("\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters")
objValue.Values.Remove ("NV Hostname")
objValue.Values.Add "NV Hostname", NewPCName,1 'Recreates value with new pc name
End Function

Function JoinDomain()
If reachable(NewPCName) then
oWshShell.Run "netdom.exe /domain:mydomain MEMBER " & NewPCName & " /ADD", 1, TRUE 'Edit DOMAIN with the proper domain PC is to be a part of
command = "net use \\" & NewPCName & "\ipc$ /user:" & NewPCName & "\administrator password" 'Edit PASSWORD with either the local administrator password or replace administrator with a local admin account followed by the password
oWshShell.Run command, 1, TRUE
command = "netdom.exe /domain:mydomain MEMBER " & NewPCName & " /JOINDOMAIN" 'Edit DOMAIN with the proper domain PC is to be a part of
oWshShell.Run command, 1, TRUE
Else
JoinDomain()
End If
End Function

Function Reboot
oWshShell.Run "SHUTDOWN.EXE \\" & OldPCName & " /r /t:01 /c /y", 1, TRUE
End Function

function reachable(HostName)
dim wshShell, fso, tfolder, tname, TempFile, results, retString, ts
Const ForReading = 1, TemporaryFolder = 2
reachable = false
set wshShell=wscript.createobject("wscript.shell")
set fso = CreateObject("Scripting.FileSystemObject")
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)

'-w 100000 is 5 mins worth of timeout to cope with establishing a dialup
wshShell.run "cmd /c ping -n 4 -w 10000 " & HostName & "> tempfile.txt" ,0,true
set results = fso.GetFile("tempfile.txt")
set ts = results.OpenAsTextStream(ForReading)
do while ts.AtEndOfStream <> True
retString = ts.ReadLine
if instr(retString, "Reply")>0 then
reachable = true
exit do
end if
loop
ts.Close
results.delete
end function

I am more comferteble in KIx rather VB Script.
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran