Win32 class property data type mismatch error

298 views Asked by At

I'm trying to set a new value to the "InstallDate" property of class Win32_NetworkAdapter.

here is a link to a description of the class:

http://msdn.microsoft.com/en-us/library/aa394216%28v=vs.85%29.aspx

Yet, when I'm trying to set a new DateTime, I get a "type mismatch" error, even though I'm trying to set a DateTime object like listed in the struct.

this is the code:

private static void Check()
{
  var win32DeviceClassName = "Win32_NetworkAdapter";
  var query = string.Format("select * from {0}", win32DeviceClassName);

  using (var searcher = new ManagementObjectSearcher(query))
  {
    ManagementObjectCollection objectCollection = searcher.Get();

    foreach (ManagementBaseObject managementBaseObject in objectCollection)
    {
      if (!managementBaseObject.Properties["Description"].Value.ToString().Contains("what i need"))
      {
        continue;
      }
      managementBaseObject.Properties["InstallDate"].Value = DateTime.Now;
    }
  }
}
1

There are 1 answers

2
Ehsan On BEST ANSWER

Your question has the answer, if you go through the documentation it says

InstallDate

Data type: datetime

Access type: Read-only

Date and time the object was installed. This property does not need a value to indicate that the object is installed. This property is inherited from CIM_ManagedSystemElement. This property has not been implemented yet. It returns a NULL value by default.