如何获取到实际物理内存(已解决)
本帖最后由 surongfu 于 2012-6-26 08:33 编辑如何获取到实际物理内存并检测共插了几条{:face (332):} 本帖最后由 fpquenya 于 2012-6-25 09:40 编辑
回复 1# surongfu
;------------------------------
;查询物理内存信息(WMI方法)
;------------------------------
Local $oWMI,$colItems,$oFoundItem
$oWMI = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $oWMI.ExecQuery("SELECT TotalPhysicalMemory FROM Win32_ComputerSystem")
Local $iTotalMem
For $oFoundItem In $colItems
$iTotalMem = "内存总容量:" & Round($oFoundItem.TotalPhysicalMemory/1024/1024/1024,2) & "GB"
Next
Local $colMemory = $oWMI.ExecQuery("SELECT DeviceLocator,Manufacturer,Capacity,Speed,SerialNumber,TotalWidth FROM Win32_PhysicalMemory")
Local $iCount = $colMemory.Count ;内存条数量
Local $oMem,$sMemInfo
For $oMem In $colMemory
$sMemInfo = $sMemInfo & _
"内存厂商:" & StringStripWS($oMem.Manufacturer,1+2+4) & @CRLF & _
"单条容量:" & Round($oMem.Capacity/1024/1024/1024,1) & "GB" & @CRLF & _
"插槽位置:" & $oMem.DeviceLocator & @CRLF & _
"速度:" & $oMem.Speed & " MHz" & @CRLF & _
"序列号:" & StringStripWS($oMem.SerialNumber,1+2+4) & @CRLF & _
"总带宽:" & $oMem.TotalWidth & "位" & @CRLF
Next
MsgBox(0,"物理内存信息",$iTotalMem & @CRLF & "内存数量:" & $iCount & "条" & @CRLF & @CRLF & $sMemInfo)
修改一下,用所有内存条容量相加方法.
;------------------------------------------------------------
;精准查询物理内存信息(WMI方法)
;将所有内存条容量相+,避免32位系统只能识别3.25G内存的问题.
;------------------------------------------------------------
Local $oWMI,$colItems,$oFoundItem
$oWMI = ObjGet("winmgmts:\\.\root\cimv2")
;~ $colItems = $oWMI.ExecQuery("SELECT TotalPhysicalMemory FROM Win32_ComputerSystem")
;~ Local $iTotalMem
;~ For $oFoundItem In $colItems
;~ $iTotalMem = "内存总容量:" & Round($oFoundItem.TotalPhysicalMemory/1024/1024/1024,2) & "GB"
;~ Next
Local $colMemory,$iCount,$iCapacity,$oMem,$sMemInfo
$colMemory = $oWMI.ExecQuery("SELECT DeviceLocator,Manufacturer,Capacity,Speed,SerialNumber,TotalWidth FROM Win32_PhysicalMemory")
$iCount = $colMemory.Count ;内存条数量
$iCapacity = 0
For $oMem In $colMemory
$iCapacity = $iCapacity + Round($oMem.Capacity/1024/1024/1024,1) ;GB
$sMemInfo = $sMemInfo & _
"插槽位置:" & $oMem.DeviceLocator & @CRLF & _
"单条容量:" & Round($oMem.Capacity/1024/1024/1024,1) & "GB" & @CRLF & _
"内存厂商:" & StringStripWS($oMem.Manufacturer,1+2+4) & @CRLF & _
"速度:" & $oMem.Speed & " MHz" & @CRLF & _
"序列号:" & StringStripWS($oMem.SerialNumber,1+2+4) & @CRLF & _
"总带宽:" & $oMem.TotalWidth & "位" & @CRLF & @CRLF
Next
MsgBox(0,"物理内存信息","总容量:" & $iCapacity & "GB" & @CRLF & "内存数量:" & $iCount & "条" & @CRLF & @CRLF & $sMemInfo)
不够准确,我是插着两条2G的,但是检测结是3.25G条数2条没有错 回复 3# surongfu
你是xp吧,32位系统最大只认识3.25G 回复 4# haijie1223
发哥,你忘记上QQ了· 回复surongfu
fpquenya 发表于 2012-6-19 09:31 http://www.autoitx.com/images/common/back.gif
谢谢,虽然在xp底下不能精确识别,但我能已经内存插的数量,也就可以自己判断有几G的内存了 XP 3.25 用破解可4GB 分享来自bbs.wglm.net siyizhu提供代码吧,获取精确无误Global $objwmiservice,$wnc,$mem1, $mem3
Local $object, $objoperatingsystem
$objwmiservice = ObjGet("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2")
$wnc = $objwmiservice.execquery("select * from win32_physicalmemory")
For $object In $wnc
$mem = String(Int($object.capacity / 1048576))
If $mem1 = "" Then
$mem1 = $mem & "MB"
$mem2 = ""
Else
$mem1 &= "/" & $mem & "MB"
$mem2 = "(" & $mem1 & ")"
EndIf
$mem3 += $mem
Next
$nc = $mem3 & "MB" & $mem2
MsgBox (32,"",$nc) 回复 8# surongfu
确实精准无比! 我一直头痛获取物理内存实际值的方法,8L的方法真是帅呆了~ 本帖最后由 netegg 于 2012-6-20 18:43 编辑
#Include <WinAPIEx.au3>
_WinAPI_GetPhysicallyInstalledSystemMemory
条数还需要另外的 把二楼和五楼的合起来还不好合哦... 回复 2# fpquenya
$colMemory = $oWMI.ExecQuery("SELECT DeviceLocator,Manufacturer,Capacity,Speed,SerialNumber,TotalWidth FROM Win32_PhysicalMemory")
$colMemory = ^ ERROR
这是为什么?
页:
[1]