Problem : How to change a computer name with vb .net
Hi all!
I need specific vb.net code that will allow me to change the computer name. I have seen all the posts here, and have tried the many different solutions, but to no avail. No matter what I try, the computer name is not changing – not in the properties window, or the registry (yes, I am rebooting manually after the code runs. Do I need to reboot from code???)
I am using vb .net 2003 (yes, I know 2.0/2005 has been out for a while now – just haven’t gotten to it yet). I am testing this on a Windows 2000 Pro machine (is that the problem?) The target machine has Windows XP Pro.
Anyone have a good solid solution out there??
Solution: How to change a computer name with vb .net
Following solution seems to work on all OS
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)