none
WMI 在win2003 查不到 Win32_PhysicalMemory 的信息 RRS feed

  • 问题

  • 代码是从scriptomatic生成的,在win7系统可以获取,但是在2003系统不行,我看了一下http://msdn.microsoft.com/en-us/library/aa394347%28VS.85%29.aspx ,这个是从win2000就支持的,这是什么原因呢? 代码如下:
    var wbemFlagReturnImmediately = 0x10;
    var wbemFlagForwardOnly = 0x20;
    
    var arrComputers = new Array("WIN2003-PC");
    for (i = 0; i < arrComputers.length; i++) {
      WScript.Echo();
      WScript.Echo("==========================================");
      WScript.Echo("Computer: " + arrComputers[i]);
      WScript.Echo("==========================================");
    
      var objWMIService = GetObject("winmgmts:\\\\" + arrComputers[i] + "\\root\\CIMV2");
      var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemory", "WQL",
                         wbemFlagReturnImmediately | wbemFlagForwardOnly);
    
      var enumItems = new Enumerator(colItems);
      for (; !enumItems.atEnd(); enumItems.moveNext()) {
       var objItem = enumItems.item();
    
       WScript.Echo("BankLabel: " + objItem.BankLabel);
       WScript.Echo("Capacity: " + objItem.Capacity);
       WScript.Echo("Caption: " + objItem.Caption);
       WScript.Echo("CreationClassName: " + objItem.CreationClassName);
       WScript.Echo("DataWidth: " + objItem.DataWidth);
       WScript.Echo("Description: " + objItem.Description);
       WScript.Echo("DeviceLocator: " + objItem.DeviceLocator);
       WScript.Echo("FormFactor: " + objItem.FormFactor);
       WScript.Echo("HotSwappable: " + objItem.HotSwappable);
       WScript.Echo("InstallDate: " + WMIDateStringToDate(objItem.InstallDate));
       WScript.Echo("InterleaveDataDepth: " + objItem.InterleaveDataDepth);
       WScript.Echo("InterleavePosition: " + objItem.InterleavePosition);
       WScript.Echo("Manufacturer: " + objItem.Manufacturer);
       WScript.Echo("MemoryType: " + objItem.MemoryType);
       WScript.Echo("Model: " + objItem.Model);
       WScript.Echo("Name: " + objItem.Name);
       WScript.Echo("OtherIdentifyingInfo: " + objItem.OtherIdentifyingInfo);
       WScript.Echo("PartNumber: " + objItem.PartNumber);
       WScript.Echo("PositionInRow: " + objItem.PositionInRow);
       WScript.Echo("PoweredOn: " + objItem.PoweredOn);
       WScript.Echo("Removable: " + objItem.Removable);
       WScript.Echo("Replaceable: " + objItem.Replaceable);
       WScript.Echo("SerialNumber: " + objItem.SerialNumber);
       WScript.Echo("SKU: " + objItem.SKU);
       WScript.Echo("Speed: " + objItem.Speed);
       WScript.Echo("Status: " + objItem.Status);
       WScript.Echo("Tag: " + objItem.Tag);
       WScript.Echo("TotalWidth: " + objItem.TotalWidth);
       WScript.Echo("TypeDetail: " + objItem.TypeDetail);
       WScript.Echo("Version: " + objItem.Version);
      }
    }
    
    function WMIDateStringToDate(dtmDate)
    {
      if (dtmDate == null)
      {
       return "null date";
      }
      var strDateTime;
      if (dtmDate.substr(4, 1) == 0)
      {
       strDateTime = dtmDate.substr(5, 1) + "/";
      }
      else
      {
       strDateTime = dtmDate.substr(4, 2) + "/";
      }
      if (dtmDate.substr(6, 1) == 0)
      {
       strDateTime = strDateTime + dtmDate.substr(7, 1) + "/";
      }
      else
      {
       strDateTime = strDateTime + dtmDate.substr(6, 2) + "/";
      }
      strDateTime = strDateTime + dtmDate.substr(0, 4) + " " +
      dtmDate.substr(8, 2) + ":" +
      dtmDate.substr(10, 2) + ":" +
      dtmDate.substr(12, 2);
      return(strDateTime);
    }
    

    2011年8月4日 8:50

答案

  • 代码本身肯定没问题, win 2003 上 肯定支持 Win32_physicalMemory 这个类,也有它的实例。

    或许 WMI repository 出现了问题,或者相关provider出问题了。难以判断。

    用 wbemtest 查看一下 Win32_physicalMemory 的几个实例,看它们是否存在,看看各个属性的值。 用 powershell 直接 get-wmiobject win32_physicalMemory 也可以。效果相同。

    2011年8月11日 14:28
    版主