简体   繁体   中英

Win32 class property data type mismatch error

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;
    }
  }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM