Sign in to follow this  
Followers 0
smirnoff

Help - Cpu Usage and kill ...

7 posts in this topic

#1 ·  Posted (edited)

Hi, in fac i've 2 questions,

first, i wanan know cpu usage of one soft and kill it if its less than 5%

i've found this and modify

Run("I:\mangos\mangosd.exe", "I:\mangos", @SW_MINIMIZE)

Sleep(1000)

While 1

$rc = StringSplit(StringTrimRight(StatusbarGetText("WHAT MUST I PUT HERE?", "", 2), 1), " ")

$rc = Int($rc[$rc[0]])

If $rc < 5 Then

ProcessClose("mangosd.exe")

$PID = ProcessExists("mangosd.exe") ;

If $PID Then ProcessClose($PID)

EndIf

Sleep(10)

If Not ProcessExists ( "realmd.exe" ) Then

RunWait ( "I:\mangos\realmd.exe", "I:\mangos", @SW_MINIMIZE )

EndIf

WEnd

IS it correct? if the CPu usage of the soft i wanna launch is less than 5 % it kill it, and after relaunch it?

So the program must check the cpu usage of mangosd.exe, if less than 5%, kill and restart it, and in the second way, check for realmd.exe exist, if not, launch it ...

Is it correct?

thanks in advance

Edited by smirnoff

Share this post


Link to post
Share on other sites



title :P


[quote name='AceLoc']I gots new sunglasses there cool.[/quote]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

HI,

maybe this helps further:

$process = "scite"

While 1
    Sleep(10)
    $cpu_usage = _Get_CPU_Usage(@ComputerName, 5, $process); return usages if above the percent passed in
    If Not @error Then
        MsgBox(0, "CPU Usage of " & $process, $cpu_usage)
        ExitLoop
    EndIf
WEnd

Func _Get_CPU_Usage($strComputer, $percent = 5, $strProcess = "")
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    
    If $strProcess <> "" Then $strProcess = " WHERE Name = '" & $strProcess & "'"
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process" & $strProcess, "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
    If IsObj($colItems) Then
        For $objItem In $colItems
            If Number($objItem.PercentProcessorTime) > Number($percent) Then Return $objItem.PercentProcessorTime
        Next
    EndIf
    SetError(1)
    Return ""
EndFunc  ;==>_Get_CPU_Usage

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

for the help, already read that but my AutoID refuse to compil this code ... dunno why, error in WMI ... must i need the beta ?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

title :P

What about title? its a DOS window ... so Title is tha path? "I:\mangos\mangosd.exe" ? exact?

Edited by smirnoff

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$rc = StringSplit(StringTrimRight(StatusbarGetText("WHAT MUST I PUT HERE?", "", 2), 1), " ");you must put the Title there.

EDIT:

well use the AutoIt Window Info thingy :P!

Edited by aceloc

[quote name='AceLoc']I gots new sunglasses there cool.[/quote]

Share this post


Link to post
Share on other sites

ok now it work fine, thanks u 2

:P

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0