Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a nice link that discusses it in detail and also deals with active directory membership and machine naming in addition to the local machine name. <a href="http://derricksweng.blogspot.com/2009/04/programmatically-renaming-computer.html" rel="nofollow">http://derricksweng.blogspot.com/2009/04/programmatically-renaming-computer.html</a></p> <p>(Btw, should you have to deal with Active Directory naming, I would consider using the <a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.computerprincipal.aspx" rel="nofollow">ComputerPrincipal</a> class from the System.DirectoryServices.AccountManagement namespace vice anything from System.DirectoryServices namespace that was used in the blog post.)</p> <p>Tweaked code from the blog post (you will need to add a reference to System.Management to your project):</p> <pre><code> public void RenameRemotePC(String oldName, String newName, String domain, NetworkCredential accountWithPermissions) { var remoteControlObject = new ManagementPath { ClassName = "Win32_ComputerSystem", Server = oldName, Path = oldName + "\\root\\cimv2:Win32_ComputerSystem.Name='" + oldName + "'", NamespacePath = "\\\\" + oldName + "\\root\\cimv2" }; var conn = new ConnectionOptions { Authentication = AuthenticationLevel.PacketPrivacy, Username = oldName + "\\" + accountWithPermissions.UserName, Password = accountWithPermissions.Password }; var remoteScope = new ManagementScope(remoteControlObject, conn); var remoteSystem = new ManagementObject(remoteScope, remoteControlObject, null); ManagementBaseObject newRemoteSystemName = remoteSystem.GetMethodParameters("Rename"); var methodOptions = new InvokeMethodOptions(); newRemoteSystemName.SetPropertyValue("Name", newName); newRemoteSystemName.SetPropertyValue("UserName", accountWithPermissions.UserName); newRemoteSystemName.SetPropertyValue("Password", accountWithPermissions.Password); methodOptions.Timeout = new TimeSpan(0, 10, 0); ManagementBaseObject outParams = remoteSystem.InvokeMethod("Rename", newRemoteSystemName, null); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload