Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:12:38+00:00 2026-05-26T00:12:38+00:00

I need to rename my computer via .net application. I have tried this code:

  • 0

I need to rename my computer via .net application.
I have tried this code:

public static bool SetMachineName(string newName)
{
    MessageBox.Show(String.Format("Setting Machine Name to '{0}'...", newName));

    // Invoke WMI to populate the machine name
    using (ManagementObject wmiObject = new ManagementObject(new ManagementPath(String.Format("Win32_ComputerSystem.Name='{0}'",System.Environment.MachineName))))
    {
        ManagementBaseObject inputArgs = wmiObject.GetMethodParameters("Rename");
        inputArgs["Name"] = newName;

        // Set the name
        ManagementBaseObject outParams = wmiObject.InvokeMethod("Rename",inputArgs,null);

        uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
        if (ret == 0)
        {
            //worked
            return true;
        }
        else
        {
            //didn't work
            return false;
        }
    }
}

but it didn’t work.

and i have tried this one:

using System.Runtime.InteropServices;

[DllImport("kernel32.dll")]
static extern bool SetComputerName(string lpComputerName);

public static bool SetMachineName(string newName)
{

    bool done = SetComputerName(newName);
    if (done)
    {
        { MessageBox.Show("Done"); return true; }
    }
    else
    { MessageBox.Show("Failed"); return false; }
}

but it also didn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:12:39+00:00Added an answer on May 26, 2026 at 12:12 am

    I have tried all the ways i have found to change computer name and no one works…..it doesn’t change the computer name…
    the only way it worked is when i chaged some registry key values , this is the code , is it ok to do so?

    public static bool SetMachineName(string newName)
    {
        RegistryKey key = Registry.LocalMachine;
    
        string activeComputerName = "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName";
        RegistryKey activeCmpName = key.CreateSubKey(activeComputerName);
        activeCmpName.SetValue("ComputerName", newName);
        activeCmpName.Close();
        string computerName = "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName";
        RegistryKey cmpName = key.CreateSubKey(computerName);
        cmpName.SetValue("ComputerName", newName);
        cmpName.Close();
        string _hostName = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\";
        RegistryKey hostName = key.CreateSubKey(_hostName);
        hostName.SetValue("Hostname",newName);
        hostName.SetValue("NV Hostname",newName);
        hostName.Close();
        return true;
    }
    

    and after the restart the name changes….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file I need to rename to that of an existing file.
need ask you about some help. I have web app running in Net 2.0.
I need to rename the ASP.NET_SessionId cookie created by default by ASP.NET. Let's say
I need to rename all of my tables, stored procedures and obviously the code
I need to rename columns in my MySQL table using PHP. This is made
I have a large number of image files that i need to rename from
i hope this is not a stupid question i need to rename microsoft access
I have migrated a project from CVS to SVN. Now I need to rename
I have an ms access database with 24 tables. I need to rename the
We need to rename about 15 custom objects in a force.com. In Java, this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.