找回密码
 加入
搜索
查看: 13450|回复: 25

[系统综合] [已解决]自己做的获取实际内存大小的UDF,求精简及优化

 火... [复制链接]
发表于 2010-10-21 11:26:32 | 显示全部楼层 |阅读模式
本帖最后由 kingfirekkk 于 2010-10-28 19:02 编辑

使用WMI方式获取的内存与实际内存大小总是有些区别,这点在集成显卡的主板上面犹为明显,特地配合CPUZ.exe写了一个“UDF”,请各位大大看看能否改进....另外,如果别人的机器上面没装CPUZ.exe或者CPUz.exe的路径不对的时候,怎么处理呢?
#include-once
Local $x=""
getmem()
MsgBox(0,"提示!","本机实际内存大小为:"&@CRLF&$x&"  MB")
Func getmem()
$sFile ="report.txt"
Run("cpuz.exe"&' -txt=report',@ScriptDir)
Sleep(2000)
$getfile=FileRead($sFile)
$sR=stringRegExp($getfile,"\W+Max module size\W+(\d{4}\s+)MBytes",3)
;$sR1=stringRegExp($getfile,"\W+max capacity\W+(\d{4}\s+)MBytes",3)
;_ArrayDisplay($sR, UBound($sR))
;_ArrayDisplay($sR1, UBound($sR1))
$x=$sr[0]
;$y=$sr1[0]
;MsgBox(0,"提示!","本机实际内存大小为:"&@CRLF&$x&"  MB")
;MsgBox(0,"提示!","本机实际内存大小为:"&@CRLF&$y&"  MB")
Return $x
EndFunc

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-10-21 11:35:17 | 显示全部楼层
FileInstall  打包一个不就完了吗

判断路径肯定不方便   因为我用的就是绿色版  没法判断路径
发表于 2010-10-21 17:28:16 | 显示全部楼层
调用第三方绝对会存在诸多问题,比如兼容问题和效率问题。
发表于 2010-10-22 10:07:27 | 显示全部楼层
收下留着后用
 楼主| 发表于 2010-10-23 08:36:38 | 显示全部楼层
换了台机器,就发现问题了,压根没有关键字:Max module size和max capacity,请楼上的兄弟不急着收藏了.而关键字Memsize又不是我想要的...
发表于 2010-10-23 10:18:57 | 显示全部楼层
这个应该是准确的。
#include <array.au3>
#Include <WinAPI.au3>
Local $info,$str

$info=_WinAPI_GlobalMemoryStatus()
$str='内存使用百分比为:'&$info[0]&"%"&@CRLF& _
        '内存总数为(K):'&Int($info[1]/1024)&""&@CRLF& _
        '可用内存数为(K):'&Int($info[2]/1024)&""
MsgBox(0,0,$str)

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-10-23 13:05:04 | 显示全部楼层
6#果然是高手,连这个API都知道
发表于 2010-10-23 13:29:34 | 显示全部楼层
支持楼主继续改进。

cpuz是绿色的,可以不管目标机器是否有安装cpuz,都 FileInstall 。

6楼的方法,在 32位 WindowsXP 的情况下,不能发现实际存在的 4G 物理内存。
发表于 2010-10-23 16:43:13 | 显示全部楼层
感谢3mile ,6#代码好用
发表于 2010-10-24 03:25:22 | 显示全部楼层
不错,6楼  牛B
 楼主| 发表于 2010-10-26 09:27:47 | 显示全部楼层
6楼兄弟的代码,仍然无法获取实际内存大小,不过仍然谢谢捧场..
发表于 2010-10-26 10:55:34 | 显示全部楼层
回复 11# kingfirekkk
上图看下问题出在什么地方。
 楼主| 发表于 2010-10-28 09:13:24 | 显示全部楼层
使用3mile兄的程式运行后的结果:

使用Everest实际装的内存条,2条2G的...如下图:


所以想实现的功能是真真正正的找出实际的内存大小。
谢谢各位大大!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-10-28 09:30:19 | 显示全部楼层
本帖最后由 3mile 于 2010-10-28 09:34 编辑

不知道任务管理器中表现内存如何啊?
用wmi来获取试试:
; 生成于 AutoIt Scriptomatic

__wmi_Win32_PhysicalMemory()
Func __wmi_Win32_PhysicalMemory()
        Local $wbemFlagReturnImmediately = 0x10
        Local $wbemFlagForwardOnly = 0x20
        Local $colItems = ""
        Local $strComputer = "localhost"

        Local $Output=""
        $Output &= "Computer: " & $strComputer  & @CRLF
        $Output &= "==========================================" & @CRLF
        Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemory", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

        If IsObj($colItems) then
           For $objItem In $colItems
              $Output &= "BankLabel: " & $objItem.BankLabel & @CRLF
              $Output &= "Capacity: " & $objItem.Capacity & @CRLF
              $Output &= "Caption: " & $objItem.Caption & @CRLF
              $Output &= "CreationClassName: " & $objItem.CreationClassName & @CRLF
              $Output &= "DataWidth: " & $objItem.DataWidth & @CRLF
              $Output &= "Description: " & $objItem.Description & @CRLF
              $Output &= "DeviceLocator: " & $objItem.DeviceLocator & @CRLF
              $Output &= "FormFactor: " & $objItem.FormFactor & @CRLF
              $Output &= "HotSwappable: " & $objItem.HotSwappable & @CRLF
              $Output &= "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
              $Output &= "InterleaveDataDepth: " & $objItem.InterleaveDataDepth & @CRLF
              $Output &= "InterleavePosition: " & $objItem.InterleavePosition & @CRLF
              $Output &= "Manufacturer: " & $objItem.Manufacturer & @CRLF
              $Output &= "MemoryType: " & $objItem.MemoryType & @CRLF
              $Output &= "Model: " & $objItem.Model & @CRLF
              $Output &= "Name: " & $objItem.Name & @CRLF
              $Output &= "OtherIdentifyingInfo: " & $objItem.OtherIdentifyingInfo & @CRLF
              $Output &= "PartNumber: " & $objItem.PartNumber & @CRLF
              $Output &= "PositionInRow: " & $objItem.PositionInRow & @CRLF
              $Output &= "PoweredOn: " & $objItem.PoweredOn & @CRLF
              $Output &= "Removable: " & $objItem.Removable & @CRLF
              $Output &= "Replaceable: " & $objItem.Replaceable & @CRLF
              $Output &= "SerialNumber: " & $objItem.SerialNumber & @CRLF
              $Output &= "SKU: " & $objItem.SKU & @CRLF
              $Output &= "Speed: " & $objItem.Speed & @CRLF
              $Output &= "Status: " & $objItem.Status & @CRLF
              $Output &= "Tag: " & $objItem.Tag & @CRLF
              $Output &= "TotalWidth: " & $objItem.TotalWidth & @CRLF
              $Output &= "TypeDetail: " & $objItem.TypeDetail & @CRLF
              $Output &= "Version: " & $objItem.Version & @CRLF
              if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
              $Output=""
           Next
        Else
           Msgbox(0,"WMI 输出","没有在类 " & "Win32_PhysicalMemory" & "中找到WMI对象" )
        Endif
EndFunc


Func WMIDateStringToDate($dtmDate)

        Return (StringMid($dtmDate, 5, 2) & "/" & _
        StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
        & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

评分

参与人数 1金钱 +25 收起 理由
afan + 25

查看全部评分

 楼主| 发表于 2010-10-28 16:57:31 | 显示全部楼层
谢谢3Mile,正式的UDF出来了,我自己精简了一下,不知道会不会有问题,通过以下UDF,能够得到实际的内存大小值,希望对大家有用哦!!谢谢!
$x=getmem()
MsgBox(0,"MEM is",$x/1024/1024/1024&'GB')
Func getmem()
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemory", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)        
If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output &$objItem.Capacity & @CRLF
;~       if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
$Output+=$output
Return $output
$Output=""
  Next
  
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PhysicalMemory" )
Endif
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-6 00:46 , Processed in 0.093709 second(s), 30 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表