找回密码
 加入
搜索
查看: 2172|回复: 5

[系统综合] AU3获取本机内存大小?

  [复制链接]
发表于 2010-12-13 17:20:44 | 显示全部楼层 |阅读模式
AU3获取本机内存大小?求代码……
发表于 2010-12-13 18:25:11 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>


#Region ### START Koda GUI section ### Form=
$hwnd = GUICreate("清理垃圾工具", 569, 383, 193, 125)
$Button1 = GUICtrlCreateButton("退      出", 464, 120, 89, 25, 0)
GUICtrlCreateLabel("内    存:", 180,206,100,25)
$mem=GUICtrlCreateLabel("", 240,206,50,100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
info()

While 1
           $nMsg = GUIGetMsg()
        Switch $nMsg         
        Case $GUI_EVENT_CLOSE,$Button1
                   Exit
           EndSwitch
WEnd

Func info()
$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colSettings = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
$colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For $object  in $colMemory
GUICtrlSetData($mem,String(Int(Number($object.TotalPhysicalMemory) / (1024 * 1024))) & " MB")
Next
EndFunc
发表于 2010-12-13 18:31:22 | 显示全部楼层
不用太准的话,_memglobal*好像就可以
发表于 2010-12-13 18:34:10 | 显示全部楼层
MemGetStats()
具体用法看帮助文档,但取得的内存大小和楼上的代码取的大小有差别,不知道原因
发表于 2010-12-13 19:33:03 | 显示全部楼层
If _MemStats() Then 
        ;Next
        
Else
        
        Exit ;程序工作内存 大于 物理剩余内存 时,退出程序!
        
EndIf

;------------------------------------/
;_MemStats()
Func _MemStats()

        Local $Mem1 = ProcessGetStats(), $Mem2 = MemGetStats()

        If Not @Compiled Then
                ConsoleWrite(@LF & "程序内存占用:" & Int($Mem1[0] / 1000 / 1000) & "M")
                ConsoleWrite(@LF & "物理内存可用:" & Int($Mem2[2] / 1000) & "M" & @LF)
        EndIf

        If Int($Mem2[2] / 1000) > Int($Mem1[0] / 1000 / 1000) Then
                Return True
        Else
                Return False
        EndIf

;~         If Not @Compiled Then Return SetError(1,0,"")
;~
;~         Local $Mem
;~
;~         $Mem = ProcessGetStats()
;~         ConsoleWrite( _
;~                         @LF & "程序内存占用:" & Int($Mem[0] / 1000 / 1000) & "M" & _
;~                         @LF & "程序峰值内存:" & Int($Mem[1] / 1000 / 1000) & "M" & "" _
;~                         )

;~         $Mem = MemGetStats()
;~         ConsoleWrite( _
;~                         @LF & "内存使用率:" & Int($Mem[0]) & "%" & _
;~                         @LF & "物理内存总数:" & Int($Mem[1] / 1000) & "M" & _
;~                         @LF & "物理内存可用:" & Int($Mem[2] / 1000) & "M" & _
;~                         @LF & "页面文件大小:" & Int($Mem[3] / 1000) & "M" & _
;~                         @LF & "可用页面文件大小:" & Int($Mem[4] / 1000) & "M" & _
;~                         @LF & "虚拟内存大小:" & Int($Mem[5] / 1000) & "M" & _
;~                         @LF & "可用虚拟内存大小:" & Int($Mem[6] / 1000) & "M" & @LF _
;~                         )

EndFunc   ;==>_MemStats
;------------------------------------/
发表于 2010-12-13 20:44:49 | 显示全部楼层
建议楼主参考此文章:
http://www.autoitx.com/thread-19175-1-1.html
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-9 19:27 , Processed in 0.104397 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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