rasim Posted June 2, 2008 Share Posted June 2, 2008 Hi everyone! This is a small example which shows, how to calculate a CPU usage.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $IDLETIME, $KERNELTIME, $USERTIME Global $StartIdle, $StartKernel, $StartUser Global $EndIdle, $EndKernel, $EndUser Global $Timer $IDLETIME = DllStructCreate("dword;dword") $KERNELTIME = DllStructCreate("dword;dword") $USERTIME = DllStructCreate("dword;dword") $hGUI = GUICreate("CPUmon", 200, 100, -1, -1, -1, $WS_EX_TOPMOST) GUISetIcon("shell32.dll", 13) GUICtrlCreateLabel("Total CPU Usage:", 25, 20, 105, 20) GUICtrlSetFont(-1, 8.5, 800, Default, "MS Sans Serif") $ValueLabel = GUICtrlCreateLabel("", 130, 20, 40, 20) GUICtrlSetFont(-1, 8.5, 800, Default, "MS Sans Serif") $StartButton = GUICtrlCreateButton("Start", 10, 60, 75, 23) $StopButton = GUICtrlCreateButton("Stop", 115, 60, 75, 23) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $StartButton _GetSysTime($StartIdle, $StartKernel, $StartUser) $Timer = TimerInit() GUICtrlSetState($StartButton, $GUI_DISABLE) GUICtrlSetState($StopButton, $GUI_ENABLE) Case $StopButton GUICtrlSetState($StopButton, $GUI_DISABLE) GUICtrlSetState($StartButton, $GUI_ENABLE) GUICtrlSetData($ValueLabel, "") EndSwitch If BitAND(GUICtrlGetState($StopButton), $GUI_ENABLE) And TimerDiff($Timer) >= 1000 Then _GetSysTime($EndIdle, $EndKernel, $EndUser) _CPUCalc() _GetSysTime($StartIdle, $StartKernel, $StartUser) $Timer = TimerInit() EndIf WEnd Func _GetSysTime(ByRef $sIdle, ByRef $sKernel, ByRef $sUser) DllCall("kernel32.dll", "int", "GetSystemTimes", "ptr", DllStructGetPtr($IDLETIME), _ "ptr", DllStructGetPtr($KERNELTIME), _ "ptr", DllStructGetPtr($USERTIME)) $sIdle = DllStructGetData($IDLETIME, 1) $sKernel = DllStructGetData($KERNELTIME, 1) $sUser = DllStructGetData($USERTIME, 1) EndFunc ;==>_GetSysTime Func _CPUCalc() Local $iSystemTime, $iTotal, $iCalcIdle, $iCalcKernel, $iCalcUser $iCalcIdle = ($EndIdle - $StartIdle) $iCalcKernel = ($EndKernel - $StartKernel) $iCalcUser = ($EndUser - $StartUser) $iSystemTime = ($iCalcKernel + $iCalcUser) $iTotal = Int(($iSystemTime - $iCalcIdle) * (100 / $iSystemTime)) & "%" If GUICtrlRead($ValueLabel) <> $iTotal Then ControlSetText($hGUI, "", $ValueLabel, $iTotal) EndFunc ;==>_CPUCalcAny comment`s are greeted Link to comment Share on other sites More sharing options...
YOUF Posted June 2, 2008 Share Posted June 2, 2008 3q you~ Link to comment Share on other sites More sharing options...
James Posted June 2, 2008 Share Posted June 2, 2008 Nice. I might add this to Disk Manager for the new update Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
rasim Posted June 2, 2008 Author Share Posted June 2, 2008 JamesBrooksGlad if this is useful for your great project. Link to comment Share on other sites More sharing options...
James Posted June 2, 2008 Share Posted June 2, 2008 JamesBrooksGlad if this is useful for your great project. Yeah if you don't mind Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
rasim Posted June 2, 2008 Author Share Posted June 2, 2008 JamesBrooksYeah if you don't mindCertainly i don`t mind, my friend! Link to comment Share on other sites More sharing options...
nobbe Posted June 3, 2008 Share Posted June 3, 2008 nice work i like it ! btw : do you have an ide how i can calculate the cpu times of all running processes? Link to comment Share on other sites More sharing options...
rasim Posted June 3, 2008 Author Share Posted June 3, 2008 (edited) nobbe do you have an ide how i can calculate the cpu times of all running processes?Hi! It`s no hard, in the Google you will be able to find many examples. Quick example: expandcollapse popupGlobal Const $PROCESS_ALL_ACCESS = 0x1F0FFF Global $CREATETIME = DllStructCreate("dword;dword") Global $EXITTIME = DllStructCreate("dword;dword") Global $KERNELTIME = DllStructCreate("dword;dword") Global $USERTIME = DllStructCreate("dword;dword") Global $StartKernelTime, $StartUserTime Global $EndKernelTime, $EndUserTime Global $ProcHandle Run(@ProgramFilesDir & "\Internet Explorer\IEXPLORE.EXE http:\\autoitscript.com") ProcessWait("IEXPLORE.EXE") $PID = ProcessExists("IEXPLORE.EXE") If $PID = 0 Then Exit $ProcHandle = DllCall("kernel32.dll", "hwnd", "OpenProcess", "dword", $PROCESS_ALL_ACCESS, "int", False, "dword", $PID) $ProcHandle = $ProcHandle[0] _GetProcTime($StartKernelTime, $StartUserTime) Sleep(1000) _GetProcTime($EndKernelTime, $EndUserTime) $Start = ($StartKernelTime + $StartUserTime) $End = ($EndKernelTime + $EndUserTime) $total = Int(($End - $Start) / 100000) DllCall("kernel32.dll", "int", "CloseHandle", "int", $ProcHandle) ProcessClose($PID) MsgBox(262144, "Calculate", "for 1 passed second process was used " & $total & "% of CPU") Func _GetProcTime(ByRef $sKernelTime, ByRef $sUserTime) DllCall("kernel32.dll", "int", "GetProcessTimes", "hwnd", $ProcHandle, "ptr", DllStructGetPtr($CREATETIME), _ "ptr", DllStructGetPtr($EXITTIME), "ptr", DllStructGetPtr($KERNELTIME), "ptr", DllStructGetPtr($USERTIME)) $sKernelTime = DllStructGetData($KERNELTIME, 1) $sUserTime = DllStructGetData($USERTIME, 1) EndFunc Edited June 3, 2008 by rasim Link to comment Share on other sites More sharing options...
zFrank Posted August 17, 2008 Share Posted August 17, 2008 hey! its good example but this one is better expandcollapse popup;================================================================================ ; Description: Memory Fusion ; Author(s): MrBond007 (Baki) & Picasso (Fida Florian) ; Comments: Recover and Defragments the PC Memory ; ; Recover function belongs to W0uter ; ; Remember if you like AutoIt Donate to the AutoIt Project: ; http://www.autoitscript.com/donate.php ;================================================================================ #NoTrayIcon #include <GuiConstants.au3> #Include <Constants.au3> Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) Dim $ok1, $ok2, $ok3, $fUpdateMeminfo = True Dim $memstats = MemGetStats() $version = "Memory Fusion" If WinExists($version) Then Exit AutoItWinSetTitle($version) $restoreitem = TrayCreateItem("Restore") TrayItemSetOnEvent(-1, "restm") TrayItemSetState(-1, $TRAY_DEFAULT) TrayCreateItem("") $recoveritem = TrayCreateItem("Recover") TrayItemSetOnEvent(-1, "recovermem") $defragitem = TrayCreateItem("Defrag") TrayItemSetOnEvent(-1, "_MemDefrag") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "exitr") $maing = GUICreate("Memory Fusion", 285, 290, -1, -1) GUISetBkColor(0xEBEBEB) GUICtrlCreateGroup("Status", 5, 5, 275, 75) GUICtrlCreateLabel("Used Memory", 10, 25, 75, 20) $label1 = GUICtrlCreateLabel("100%", 245, 25, 30) GUICtrlCreateGraphic(85, 25, 150, 15) GUICtrlSetColor(-1, 0x000000) $progress1 = GUICtrlCreateGraphic(86, 26, 0, 13) GUICtrlSetColor($progress1, 0x000000) GUICtrlSetBkColor($progress1, 0x0FB1FF) GUICtrlCreateLabel("Free Memory", 10, 50, 75, 20) $label2 = GUICtrlCreateLabel("100%", 245, 50, 30) GUICtrlCreateGraphic(85, 50, 150, 15) GUICtrlSetColor(-1, 0x000000) $progress2 = GUICtrlCreateGraphic(86, 51, 0, 13) GUICtrlSetColor($progress2, 0x000000) GUICtrlSetBkColor($progress2, 0x0FB1FF) GUICtrlCreateGroup("Info", 5, 85, 275, 75) GUICtrlCreateLabel("Total Memory", 10, 110, 235, 20) GUICtrlSetColor(-1, 0x0083C1) GUICtrlCreateLabel($memstats[1] & "KB", 85, 110, 55, 20) GUICtrlCreateLabel("Free Memory", 10, 135, 235, 20) GUICtrlSetColor(-1, 0x0083C1) $label3 = GUICtrlCreateLabel("", 85, 135, 55, 21) GUICtrlCreateLabel("Used Memory", 145, 110, 115, 20) GUICtrlSetColor(-1, 0x0083C1) $label4 = GUICtrlCreateLabel("", 220, 110, 55, 20) GUICtrlCreateLabel("Paging File", 145, 135, 105, 20) GUICtrlSetColor(-1, 0x0083C1) $label5 = GUICtrlCreateLabel("", 220, 135, 55, 20) $check1 = GUICtrlCreateRadio("Automaticlly recover memory when it's less than 10%", 5, 170, 270, 20) If @OSTYPE = "WIN32_WINDOWS" Then GUICtrlSetState($check1, $GUI_UNCHECKED) GUICtrlSetState($check1, $GUI_DISABLE) Else GUICtrlSetState($check1, $GUI_CHECKED) EndIf $check2 = GUICtrlCreateRadio("Automaticlly recover memory when it's less than 20%", 5, 195, 270, 20) If @OSTYPE = "WIN32_WINDOWS" Then GUICtrlSetState($check2, $GUI_UNCHECKED) GUICtrlSetState($check2, $GUI_DISABLE) EndIf $ok1 = GUICtrlCreateButton("Recover", 5, 255, 75, 25) If @OSTYPE = "WIN32_WINDOWS" Then GUICtrlSetState(-1, $GUI_DISABLE) $ok2 = GUICtrlCreateButton("Defrag", 105, 255, 75, 25) $ok3 = GUICtrlCreateButton("Exit", 205, 255, 75, 25) $ok4 = GUICtrlCreateButton("Memory Stress Test", 5, 220, 275, 25) If StringInStr($CmdLineRaw, "/tray") Then _MinimizeToTray(True) Else GUISetState() EndIf memcontrol() AdlibEnable("memcontrol", 500) While 1 $msg = GUIGetMsg() If GUICtrlRead($check1) = $GUI_CHECKED Then checkenable1() ElseIf GUICtrlRead($check2) = $GUI_CHECKED Then checkenable2() EndIf Select Case $msg = $GUI_EVENT_MINIMIZE _MinimizeToTray() Case $msg = $GUI_EVENT_CLOSE Or $msg = $ok3 ExitLoop Case $msg = $ok1 recovermem() Case $msg = $ok2 defragprepare() Case $msg = $ok4 _MemStressPrepare() EndSelect WEnd Func _MinimizeToTray($fStartup = False) $fUpdateMeminfo = False If Not $fStartup Then GUISetState(@SW_HIDE) TraySetState() AdlibDisable() EndFunc Func recovermem() $list = ProcessList() For $i = 1 To $list[0][0] If StringInStr($list[$i][0], "csrss") > 0 Or StringInStr($list[$i][0], "smss") > 0 Or StringInStr($list[$i][0], "winlogon") > 0 Or StringInStr($list[$i][0], "lsass") > 0 Then ContinueLoop ntmem($list[$i][1]) Next EndFunc Func ntmem($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf EndFunc Func checkenable1() If 100 - $memstats[0] < 10 Then recovermem() EndFunc Func checkenable2() If 100 - $memstats[0] < 20 Then recovermem() EndFunc Func restm() TraySetState(2) $fUpdateMeminfo = True GUISetState(@SW_SHOW) GUISetState(@SW_RESTORE) AdlibEnable("memcontrol", 500) EndFunc Func defragprepare() GUICtrlSetState($ok1, $GUI_DISABLE) GUICtrlSetState($ok2, $GUI_DISABLE) GUICtrlSetState($ok3, $GUI_DISABLE) GUICtrlSetState($ok4, $GUI_DISABLE) ClipPut("") _MemDefrag() EnvUpdate() If @OSTYPE == "WIN32_WINDOWS" Then GUICtrlSetState($ok1, $GUI_DISABLE) Else GUICtrlSetState($ok1, $GUI_ENABLE) EndIf GUICtrlSetState($ok2, $GUI_ENABLE) GUICtrlSetState($ok3, $GUI_ENABLE) GUICtrlSetState($ok4, $GUI_ENABLE) EndFunc Func _MemDefrag() $mem = MemGetStats() If @OSTYPE == "WIN32_WINDOWS" Then $dAtastruct = DllStructCreate("char[" & ($mem[1] * 512) & "]") $dAtastruct2 = DllStructCreate("char[" & ($mem[1] * 512) & "]") Sleep(7500) $dAtastruct = "" $dAtastruct2 = "" ElseIf @OSTYPE == "WIN32_NT" Then If @OSVersion == "WIN_VISTA" Then $dAtastruct = DllStructCreate("char[" & $mem[1] * 768 & "]") Sleep(7500) $dAtastruct = "" Else $dAtastruct = DllStructCreate("char[" & $mem[1] * 1024 & "]") Sleep(7500) $dAtastruct = "" EndIf EndIf EndFunc Func _MemStressPrepare() GUICtrlSetState($ok1, $GUI_DISABLE) GUICtrlSetState($ok2, $GUI_DISABLE) GUICtrlSetState($ok3, $GUI_DISABLE) GUICtrlSetState($ok4, $GUI_DISABLE) For $s = 1 To 3 _MemStress($memstats[2] * 32) _MemStress($memstats[2] * 64) _MemStress($memstats[2] * 128) _MemStress($memstats[2] * 256) _MemStress($memstats[2] * 320) _MemStress($memstats[2] * 256) _MemStress($memstats[2] * 128) _MemStress($memstats[2] * 64) _MemStress($memstats[2] * 32) Next If @OSTYPE == "WIN32_WINDOWS" Then GUICtrlSetState($ok1, $GUI_DISABLE) Else GUICtrlSetState($ok1, $GUI_ENABLE) EndIf GUICtrlSetState($ok2, $GUI_ENABLE) GUICtrlSetState($ok3, $GUI_ENABLE) GUICtrlSetState($ok4, $GUI_ENABLE) EndFunc Func _MemStress($amount) $dAtastruct = DllStructCreate("char[" & $amount & "]") Sleep(2000) $dAtastruct = "" EndFunc Func exitr() Exit EndFunc Func memcontrol() $i = 100 While 1 $i = $i + 10 If $i > 100 And $fUpdateMeminfo Then $memstats = MemGetStats() $RamF = Round(100 * ($memstats[1] - $memstats[2]) / $memstats[1], 1) GUICtrlSetPos($progress1, 86, 26, $RamF * 1.49, 13) GUICtrlSetData($label1, $RamF & "%") $RamF = Round(100 * ($memstats[2] / $memstats[1]), 1) If $RamF < 1 Then GUICtrlSetPos($progress2, 86, 51, 1, 13) Else GUICtrlSetPos($progress2, 86, 51, $RamF * 1.49, 13) EndIf GUICtrlSetData($label2, $RamF & "%") GUICtrlSetData($label3, $memstats[2] & "KB") $RamF = $memstats[1] - $memstats[2] GUICtrlSetData($label4, $RamF & "KB") GUICtrlSetData($label5, $memstats[4]) $i = 0 ExitLoop EndIf WEnd EndFunc i got it sometimes ago from here but now dont remember... all the credits goes to origional author. [font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php$Life = "Happy" If @Error Then $Life = "Risk" Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted August 17, 2008 Share Posted August 17, 2008 @zFrank, Indeed memory fusion is a very good example .. but no CPU information Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
pcguru000 Posted August 29, 2008 Share Posted August 29, 2008 Is there any way to get the control that task manager uses to moniter processor cores (and how much they are being used...) I've figured out Ram, and Pagefile but for some reason CPU information seems to be hard to get too... I cant seem to make CPUMon work without the start/stop switch - all i want is a simple progress bar control that shows the CPU usage... :/ Basically this: expandcollapse popup;Includes these... #include <GUIConstantsEX.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <GUIConstants.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> #include <GuiButton.au3> #include <GUIEnhance.au3> ;################### Load variables from "config.ini" ... Global $ToolBarLayout=IniRead("config.ini","Config","ToolBarLayout","<Empty>") Global $ToolBarBorder=IniRead("config.ini","Config","ToolBarBorder","<Empty>") Global $ToolBarColor=IniRead("config.ini","Config","ToolBarColor","<Empty>") Global $ToolBarAlwaysOnTop=IniRead("config.ini","Config","ToolBarAlwaysOnTop","<Empty>") Global $ToolBarFontSize=IniRead("config.ini","Config","ToolBarFontSize","<Empty>") Global $ToolBarFontWeight=IniRead("config.ini","Config","ToolBarFontWeight","<Empty>") Global $ToolBarFontAttribute=IniRead("config.ini","Config","ToolBarFontAttribute","<Empty>") Global $ToolBarFont=IniRead("config.ini","Config","ToolBarFont","<Empty>") ;################### Count for some loops Global $cnt = -1 ;################### CPU Monitering... Global $wbemFlagReturnImmediately = 0x10 Global $wbemFlagForwardOnly = 0x20 Global $wbemFlags = $wbemFlagReturnImmediately + $wbemFlagForwardOnly Global $strComputer = @ComputerName Global $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") ;################### Create the toolbar interface functions...############################# Func ToolBarCreate() Local $ToolBar ;Horizontal... if $ToolBarLayout="Horizontal" then ;No Border... if $ToolBarBorder==false Then $ToolBar = GUICreate("Dock", @DesktopWidth, 64, 0, @DesktopHeight-64, $WS_POPUP) ;Border... ElseIf $ToolBarBorder==true Then $ToolBar = GUICreate("Dock", @DesktopWidth, 64, 0, @DesktopHeight-64) EndIf ;Vertical... ElseIf $ToolBarLayout="Vertical" Then ;No Border... if $ToolBarBorder==false Then $ToolBar = GUICreate("Dock", 64, @DesktopHeight, @DesktopWidth-64, 32, $WS_POPUP) ;Border... ElseIf $ToolBarBorder==true Then $ToolBar = GUICreate("Dock", 64, @DesktopHeight, @DesktopWidth-64, 32) EndIf EndIf ;################### Other settings GUISetBkColor($ToolBarColor, $ToolBar) GUISetFont($ToolBarFontSize,$ToolBarFontWeight,$ToolBarFontAttribute,$ToolBarFont) if $ToolBarAlwaysOnTop==true then GUICtrlSetState($ToolBar,$GUI_ONTOP) WinSetOnTop($ToolBar, "", $ToolBarAlwaysOnTop) EndIf Return $ToolBar EndFunc Func ToolBarModule($Name) Local $Button, $PadLeft, $PadTop $cnt +=1 ;Horizontal... if $ToolBarLayout="Horizontal" then $PadLeft = ($cnt * 64) ;Make RAM module... If $Name = "RAM" Then Global $RAM = GUICtrlCreateProgress($PadLeft+5,4,16,48,0x04) Global $RAMT = GUICtrlCreateInput("XX%",$PadLeft+25,24,36,16,0x0800) GUICtrlSetFont($RAMT,9,700) $RAMLabel = GUICtrlCreateLabel("RAM",$PadLeft+4,54,40,16) GUICtrlSetFont($RAMLabel,6) Return $RAM ;Make page file module... ElseIf $Name = "PF" Then Global $PF = GUICtrlCreateProgress($PadLeft+5,4,16,48,0x04) Global $PFT = GUICtrlCreateInput("XX%",$PadLeft+25,24,36,16,0x0800) GUICtrlSetFont($PFT,9,700) $PFLabel = GUICtrlCreateLabel("PF",$PadLeft+8,54,40,16) GUICtrlSetFont($PFLabel,6) Return $PF ;Make page file module... ElseIf $Name = "CPU" Then Global $CPU = GUICtrlCreateProgress($PadLeft+5,4,16,48,0x04) Global $CPUT = GUICtrlCreateInput("XX%",$PadLeft+25,24,36,16,0x0800) GUICtrlSetFont($CPUT,9,700) $CPULabel = GUICtrlCreateLabel("CPU",$PadLeft+4,54,40,16) GUICtrlSetFont($CPULabel,6) Return $CPU Else ;Make a button... $Button = GUICtrlCreateButton($Name, $PadLeft, 0, 64, 64) Return $Button EndIf ;Vertical... ElseIf $ToolBarLayout="Vertical" then $PadTop = $cnt * 64 ;Make RAM module... If $Name = "RAM" Then Global $RAM = GUICtrlCreateProgress(5,$PadTop+4,16,48,0x04) Global $RAMT = GUICtrlCreateInput("XX%",25,$PadTop+24,36,16,0x0800) GUICtrlSetFont($RAMT,9,700) $RAMLabel = GUICtrlCreateLabel("RAM",4,$PadTop+54,40,16) GUICtrlSetFont($RAMLabel,6) Return $RAM ;Make page file module... ElseIf $Name = "PF" Then Global $PF = GUICtrlCreateProgress(5,$PadTop+4,16,48,0x04) Global $PFT = GUICtrlCreateInput("XX%",25,$PadTop+24,36,16,0x0800) GUICtrlSetFont($PFT,9,700) $PFLabel = GUICtrlCreateLabel("PF",8,$PadTop+54,40,16) GUICtrlSetFont($PFLabel,6) Return $PF ;Make page file module... ElseIf $Name = "CPU" Then Global $CPU = GUICtrlCreateProgress(5,$PadTop+4,16,48,0x04) Global $CPUT = GUICtrlCreateInput("XX%",25,$PadTop+24,36,16,0x0800) GUICtrlSetFont($CPUT,9,700) $CPULabel = GUICtrlCreateLabel("CPU",4,$PadTop+54,40,16) GUICtrlSetFont($CPULabel,6) Return $CPU Else ;Make a button... $Button = GUICtrlCreateButton($Name, 0, $PadTop, 64, 64) Return $Button EndIf EndIf EndFunc ;MEMORY INFO ;########################################################################################## ;################### Show our toolbar/GUI... $ToolBar = ToolBarCreate() ;################### Make our buttons... $Button = IniReadSection("config.ini", "Main") For $i = 1 To $Button[0][0] if $Button[$i][0] = "CPU" then ToolBarModule("CPU") elseif $Button[$i][0] = "RAM" then ToolBarModule("RAM") else ToolBarModule($Button[$i][0]) endif Next ;################### Exit Button... $ButtonLast = ToolBarModule("Exit") ;################### Fade in the GUI and buttons... _GUIEnhanceAnimateWin ($ToolBar, 500, $GUI_EN_ANI_FADEIN) GUISetState(@SW_SHOW, $ToolBar) ;################### Run the program... While 1 $msg = GUIGetMsg() ;Buttons Execute(IniRead("config.ini","Main",_GUICtrlButton_GetText($msg),"<>")) if $msg = $ButtonLast Then Exit ;;;;; ;CPU #CS Global $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlags) For $objItem In $colItems $sMsg = $objItem.LoadPercentage Next GUICtrlSetData($CPU, $sMsg) Sleep(100) #CE ;RAM $mem = MemGetStats() GUICtrlSetData($RAM, $mem[0]) GUICtrlSetData($RAMT, $mem[0] & "%") ;PF $pfUse = MemGetStats() $pfTotal = $pfUse[3] $pfAvailable = $pfUse[4] $pfUsed = $pfTotal-$pfAvailable $pfUsedPercent = round(($pfUsed/$pfTotal)*100,0) GUICtrlSetData($PF, $pfUsedPercent) GUICtrlSetData($PFT, $pfUsedPercent & "%") #CS FileWriteLine($file, "Memory Load (Percentage of memory currently in use): " & $mem[0] & "%") FileWriteLine($file, "Total Physical RAM: " & $mem[1] & " Kilobytes" & @CRLF) FileWriteLine($file, "Available Physical RAM: " & $mem[2] & " Kilobytes" & @CRLF) FileWriteLine($file, "Total Pagefile: " & $mem[3] & " Kilobytes" & @CRLF) FileWriteLine($file, "Available Pagefile: " & $mem[4] & " Kilobytes" & @CRLF) FileWriteLine($file, "Total virtual: " & $mem[5] & " Kilobytes" & @CRLF) FileWriteLine($file, "Available virtual: " & $mem[6] & " Kilobytes" & @CRLF) #CE ;Drag control... Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $GUI_EVENT_PRIMARYDOWN _SendMessage($ToolBar,$WM_SYSCOMMAND,0xF012,0) EndSelect WEnd But without the start/stop buttons... I cant seem to modify any of that without breaking it :/ Link to comment Share on other sites More sharing options...
crashdemons Posted September 9, 2008 Share Posted September 9, 2008 I was trying to add this to my project but I noticed that sometimes (I'm not sure if it's after an interval or after something happens - and it's not very often) your example returns values like: 1086% or 785% then it goes to -1 and starts working properly again. - I'm not sure why it's doing this, but I'll set up a debug messagebox to tell me all of the values when it does occur. My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted September 9, 2008 Share Posted September 9, 2008 Got one! - here you go - hopefully we can figure out why this is happening. My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
rasim Posted September 9, 2008 Author Share Posted September 9, 2008 pcguru000 I already warned you, don't hijack non your topic, create your own topic and post there question. crashdemons I was trying to add this to my project but I noticed that sometimes (I'm not sure if it's after an interval or after something happens - and it's not very often) your example returns values like: 1086% or 785% then it goes to -1 and starts working properly again.Hi. Very strange, i tested this code on several computer under Windows XP SP2 and code works fine. Also you can get current CPU loading using WMI: $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_Processor") For $objItem In $colItems ConsoleWrite("Load Percentage: " & $objItem.LoadPercentage & @LF) Next Link to comment Share on other sites More sharing options...
crashdemons Posted September 9, 2008 Share Posted September 9, 2008 yeah, like I said, it doesn't happen very often, and when it does it's when the execution of the script has been delayed for unnatural reasons. (other actions being done, GUI being moved for a long time) But, I think I've got it working in my project where it's almost a non-issue, and when it does fail I'm just ignoring the incorrect values - so you may see it in something I post in the near future. My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
rasim Posted September 9, 2008 Author Share Posted September 9, 2008 crashdemonsBut, I think I've got it working in my project where it's almost a non-issue, and when it does fail I'm just ignoring the incorrect valuesYes, I think this is a right solution.so you may see it in something I post in the near future.Ok, waiting. Good luck, my friend! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now