We help IT Professionals succeed at work.

Changing computer names and joining domain vb.net1.1

tentavarious asked
Medium Priority
Last Modified: 2012-05-06
I am trying to change a computer name and join to a domain.  I found a lot of articles on how do to it but I am not sure how to actually make the change.  I referenced the system.management namespace and I have been missing around with code similar to this link: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_23027024.html.  Not really sure how to get it to work.  Where do i insert the new computer name and domain?
Watch Question

Most Valuable Expert 2012
Top Expert 2008

Hmmm...I always try to take WMI questions, even when I don't know the specific answer, so that I can learn more about WMI.

Are you talking about implementing this code?

Dim myPath As New ManagementPath
            myPath.Server = System.Net.Dns.GetHostName
            myPath.NamespacePath = "root\CIMV2"
            myPath.RelativePath = "Win32_Computersystem.Name='" & myPath.Server & "'"
            Dim myObj As New ManagementObject(myPath)
            Dim myParams() As Object = {"NewHostName"}
            myObj.InvokeMethod("Rename", myParams)

Open in new window

Most Valuable Expert 2012
Top Expert 2008
'myParams' is an object array that has the new host name, so you could do something like this (untested coding in the comment block):

Imports System.Management
Imports System.Net
Public Class Win32_ComputerSystem
   Public Shared Sub(ByVal oldMachineName As String, ByVal newMachineName As String)
      Dim path As New ManagementPath()
      path.Server = oldMachineName
      path.NamespacePath = "root\CIMV2"
      path.RelativePath = String.Format("Win32_ComputerSystem.Name='{0}'", oldMachineName)
      Dim obj As New ManagementObject(path)
      Dim params() As Object = {newMachineName}
      obj.InvokeMethod("Rename", params)
   End Sub
End Class

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


ok, so that would change the computer name, but what about joining to the domain?
Most Valuable Expert 2012
Top Expert 2008

Now, that, my friend, would be another related question.


Ok, i will see if i can get the name change working.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.