c# - Rename computer name with .NET -
i trying rename computer name c# application.
public class computersystem : icomputersystem { private readonly managementobject computersystemobject; public computersystem() { var computerpath = string.format("win32_computersystem.name='{0}'", environment.machinename); computersystemobject = new managementobject(new managementpath(computerpath)); } public bool rename(string newcomputername) { var result = false; var renameparameters = computersystemobject.getmethodparameters("rename"); renameparameters["name"] = newcomputername; var output = computersystemobject.invokemethod("rename", renameparameters, null); if (output != null) { var returnvalue = (uint)convert.changetype(output.properties["returnvalue"].value, typeof(uint)); result = returnvalue == 0; } return result; } }
the wmi call returns error code 1355.
msdn doesn't mention error codes, mean , how can fix it?
error code 1355 means error_no_such_domain
: "the specified domain either not exist or not contacted.".
the documentation rename method states name must contain domain name. non-domain-joined machine, try .\newname
instead of newname
.
Comments
Post a Comment