stevetaylor15 0 Newbie Poster

Hey guys,

I'm trying to disable a local workstation user account using WMI setpropertyvalue. the code but it doesn't actually work. The put() causes the exception. it return 'invalid object' if i run this without the put() it find the object and return the value..

Any ideas? thanks!
Steve

ManagementScope scope = new ManagementScope("\\\\" + line + "\\root\\cimv2", conns);
                    scope.Connect();
                    ObjectQuery MyQuery = new ObjectQuery("select name,disabled,SID from Win32_UserAccount WHERE name='iwam'");

                    ManagementObjectSearcher mysearch = new ManagementObjectSearcher(scope, MyQuery);
                    ManagementObjectCollection moc = mysearch.Get();

                    
                    foreach (ManagementObject mo in moc)
                    {
                        textBox1.Text += mo.GetPropertyValue("Disabled");
                        mo.SetPropertyValue("Disabled", true);
                        mo.Put();
                        textBox1.Text += mo.GetPropertyValue("Disabled");
                        textBox1.Text += "found iwam..";


                    }