Stopping Service when Memory reaches 2 GB

Discussion in 'Scripting' started by FB, Jul 6, 2009.

  1. FB

    FB Guest

    We have an App and when it reaches 2 GB of RAM begins to behaviour erractly.
    The only solutions is to restar the corresponding service and everything is
    fine again. It´s a Leaky App and te deveoper know about and don´t do anything
    about it.

    We need to create a Script to:

    1) Check if the the APP is "eating" all memory (2 GB is the limit, so,
    monitoring when the App reaches 1.7 GB of RAM, it´s fine)

    2) If so, we need to test if someone is connected (netstat -na | find
    ":1443" does the Job)

    3) If nobody is connected, the Service can be restarted.

    Wich "language" is more suitable for this?

    Batch? VBS/WMI? PowerShell?

    Batch can use neststat, find, tasklist and sc/net

    PowerSchell can use Get-Service and Stop-Service to to the Job, but theres
    no ways to obtain the "netstat" info to decide if the service can be

    VBS/WMI is very complex of rmy skills...

    Someone can help me?
    FB, Jul 6, 2009
    1. Advertisements

  2. I would use a batch file, e.g. something like this:
    @echo off
    set app=Firefox
    for /F "tokens=5" %%a in ('tasklist.exe ^| find /i "%app%"') do set mem=%%a
    set mem=000000000%mem:,=%
    if %mem:~-12% GTR 000001700000 goto :eof
    netstat . . .
    net stop . . .
    net start . . .
    Pegasus [MVP], Jul 6, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.