If anyone can offer some advice or help I would very much appreciate it!
Here's my code:
Expand|Select|Wrap|Line Numbers
- Try
- Dim classInstance As New ManagementObject("root\CIMV2", "Win32_ComputerSystem.Name='" & currentCompName & "'", Nothing)
- Dim inParams As ManagementBaseObject = classInstance.GetMethodParameters("Rename")
- inParams("Name") = newCompName
- inParams("Password") = "adminpass"
- inParams("UserName") = "administrator"
- Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("Rename", inParams, Nothing)
- 'If WMI returned 0 then success, otherwise report error.
- If outParams("ReturnValue") = 0 Then
- promptUser = MsgBox("Computer name changed to: " & newCompName & ". Change won't take effect until computer is restarted. Restart now?", MsgBoxStyle.YesNo)
- 'Ask the user if they want to restart the computer.
- If promptUser = vbYes Then
- System.Diagnostics.Process.Start("ShutDown", "-t 1 /r")
- End If
- Else
- MessageBox.Show("WMI returned an error. Computer name not changed." & vbCrLf & vbCrLf & "ReturnValue: " & outParams("ReturnValue"), "WMI Error")
- End If
- Catch err As ManagementException
- MessageBox.Show("WMI returned an error. Computer name not changed." & vbCrLf & vbCrLf & "Error: " & err.Message, "WMI Error")
- End Try