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

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.