简体   繁体   English

Win32类属性数据类型不匹配错误

[英]Win32 class property data type mismatch error

I'm trying to set a new value to the "InstallDate" property of class Win32_NetworkAdapter . 我正在尝试为Win32_NetworkAdapter类的“ InstallDate”属性设置一个新值。

here is a link to a description of the class: 这是该类说明的链接:

http://msdn.microsoft.com/en-us/library/aa394216%28v=vs.85%29.aspx http://msdn.microsoft.com/zh-CN/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. 但是,当我尝试设置新的DateTime时,即使尝试设置结构中列出的DateTime对象,也会收到“类型不匹配”错误。

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. 此属性是从CIM_ManagedSystemElement继承的。 This property has not been implemented yet. 此属性尚未实现。 It returns a NULL value by default. 默认情况下,它返回NULL值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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