What is the error in this code? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

What is the error in this code?

IonlineIonline Posts: 31Member
Hi,

I want to rename a local computer by using the following code. But the code fails throwing an exception "Invalid method Parameter(s)". Any help is highly appreciated.

private void button1_Click(object sender, System.EventArgs e)
{
try
{
ManagementClass mComputerSystem = new ManagementClass(
"Win32_ComputerSystem");
ManagementBaseObject outParams;
//ManagementObjectCollection objMOC = objMC.GetInstances();
ManagementBaseObject objNewComputerName = mComputerSystem.GetMethodParameters("Rename");
//foreach( outParams in
//objNewComputerName.
objNewComputerName["Name"] = txtCompName.Text;
objNewComputerName["UserName"] = txtUserID.Text;
objNewComputerName["Password"] = txtPwd.Text;
outParams = mComputerSystem.InvokeMethod("Rename", objNewComputerName, null);
//int val = Convert.ToInt32(outParams["ReturnValue"]);

}
catch(Exception ex)
{
MessageBox.Show("Unable to Set Computer Name: " + ex.Message);
}
}

Sign In or Register to comment.