• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

Changing computer names and joining domain vb.net1.1

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?
0
tentavarious
Asked:
tentavarious
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
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

0
 
Bob LearnedCommented:
'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

0
 
tentavariousAuthor Commented:
ok, so that would change the computer name, but what about joining to the domain?
0
 
Bob LearnedCommented:
Now, that, my friend, would be another related question.
0
 
tentavariousAuthor Commented:
Ok, i will see if i can get the name change working.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now