#102033 - 2003-06-11 03:34 AM
Re: Rename workstation
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
NT Doc posted a thread about using NETDOM to do that... about a week or 2 ago
|
|
Top
|
|
|
|
#102034 - 2003-06-11 04:28 AM
Re: Rename workstation
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Saleem,
Here is a post I made using KiXforms with NETDOM to MOVE computers into an AD.
The current code does not support renaming a computer, but can be modified to do so.
Take a look at how the code works and modify it to complete the task your looking to do.
It is possible to do this without KiXforms, but harder to implement. I had to use some different array code and methods to hide the password, etc... without KiXforms.
http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=004394 [ 11. June 2003, 04:29: Message edited by: NTDOC ]
|
|
Top
|
|
|
|
#102037 - 2003-06-12 03:55 PM
Re: Rename workstation
|
Saleem
Hey THIS is FUN
Registered: 2001-04-11
Posts: 280
Loc: UAE
|
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
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 978 anonymous users online.
|
|
|