Howdy, Stranger!

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


What is the error in this code?

IonlineIonline Member Posts: 31

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)
ManagementClass mComputerSystem = new ManagementClass(
ManagementBaseObject outParams;
//ManagementObjectCollection objMOC = objMC.GetInstances();
ManagementBaseObject objNewComputerName = mComputerSystem.GetMethodParameters("Rename");
//foreach( outParams in
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.