Jump to content

Help - Cpu Usage and kill ...


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...