Changing computer names and joining domain vb.net1.1

Posted on 2009-02-12
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 namespace and I have been missing around with code similar to this link:  Not really sure how to get it to work.  Where do i insert the new computer name and domain?
Question by:tentavarious
    LVL 96

    Expert Comment

    by:Bob Learned
    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

    LVL 96

    Accepted Solution

    '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


    Author Comment

    ok, so that would change the computer name, but what about joining to the domain?
    LVL 96

    Expert Comment

    by:Bob Learned
    Now, that, my friend, would be another related question.

    Author Comment

    Ok, i will see if i can get the name change working.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now