change computer name and join domain
hi gurus
can this be done in VB.net, I would like to read a text file with a buncg of computer names, change the names and after that remove from one domain and join the same compter to a different domain without having to reboot the computer in between.
if this is possible where do I start looking.
Thanks
Re: change computer name and join domain
You can do this using WMI in the .NET Framework.
Add a reference to System.Management and System.Management.Instrumentation and import the namespaces. Then...
vb.net Code:
Dim managementObj as new ManagementObject("root\\CIMV2", "Win32_ComputerSystem.Name='" & _
Environment.MachineName & "'", Nothing)
Dim parameter as ManagementBaseObject = managementObj.GetMethodParameters("Rename") _
parameter["Name"] = "NEWCOMPUTERNAMEHERE"
Dim outParams as ManagementBaseObject = managementObj.InvokeMethod("Rename", inParams, null)
This should rename the computer. Does this work for you?
Joining a new domain is a different story. The computer name change will not take affect until the machine is rebooted.