Tool Share, Check for running process from EG

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
dan Edens
Experienced User
Posts: 99
Joined: Mon Sep 24, 2018 7:57 pm

Tool Share, Check for running process from EG

Post by dan Edens » Mon Mar 16, 2020 7:52 pm

When I get to my desk at work, I have EG boot up certain software.
I don't want this to happen if
1. I'm at home.
2. Software is already running.

The 'Already running' bit gave me trouble since I couldn't get Psutil to work from inside EG, so i thought I'd share my answer!
Below macro checks for preset list (eg.globals.Boot_programs), or if payload is set, adds payload to list.
It doesn't need to be global how it is now, but I set the boot list from my "globals" python script that launches on boot.


Cheers!

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="WIP-2019.12.07-08.20.58">
    <Macro Name="Check process" XML_Guid="{AF20CE56-0CCE-4DFF-81CE-A9CF4A665C31}" Expanded="True">
        <Event Name="*.check?process*" XML_Guid="{837DD4E6-BA95-4AA5-8AD7-10057D70B555}" />
        <Action Name="Check for running process" XML_Guid="{ACBF1FA4-4B88-4171-9B81-45D2936556F2}">
            EventGhost.PythonScript(u'egg = eg.globals\nimport win32com.client\nwmi=win32com.client.GetObject(\'winmgmts:\')\negg.Boot_programs = [\'LCore.exe\', \'ShareX.exe\']\n\nif eg.event.payload is None:\n    pass\nelif eg.event.payload == "":\n    pass\nelse:\n    if eg.event.payload[-3:] == "exe":\n        print eg.event.payload\n        egg.Boot_programs.append(eg.event.payload)\n        print egg.Boot_programs\n    else:\n        pass\n\n\nfor p in wmi.InstancesOf(\'win32_process\'):\n    for e in egg.Boot_programs:\n        if e in p.name:\n            eg.plugins.EventGhost.TriggerEvent(u\'Is_running_\'+e, 0.0, None, False, False, False)\n            #print e +" is running"\n        else:\n            pass\n        \n        \n        ')
        </Action>
    </Macro>
</EventGhost>

RiseUp
Posts: 19
Joined: Mon Nov 24, 2014 3:28 am

Re: Tool Share, Check for running process from EG

Post by RiseUp » Wed Apr 01, 2020 5:39 pm

Thanks for sharing, Dan! I've been using psutil in an old version of EventGhost, but after finally updating to 0.5, my psutil python script stopped working. Your solution has fixed my setup. :D

RiseUp
Posts: 19
Joined: Mon Nov 24, 2014 3:28 am

Re: Tool Share, Check for running process from EG

Post by RiseUp » Thu Apr 02, 2020 1:42 pm

By chance I stumbled upon another method of checking for a running program/process at this forum post. Here's the content of the example python script from that post if anyone is curious:

Code: Select all

from eg.cFunctions import GetProcessDict
eg.result = 'chrome.exe' in GetProcessDict().itervalues()

User avatar
kgschlosser
Site Admin
Posts: 5214
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Tool Share, Check for running process from EG

Post by kgschlosser » Sun Apr 05, 2020 10:48 pm

@RiseUp
I am going to put together a list of available things that can be used in cFunctions and also eg.WinApi. There are all sorts of goodies in there that can be used.
If you like the work I have been doing then feel free to Image

dan Edens
Experienced User
Posts: 99
Joined: Mon Sep 24, 2018 7:57 pm

Re: Tool Share, Check for running process from EG

Post by dan Edens » Mon Apr 06, 2020 4:19 am

@RIseup

O nice one, thanks I like that.

Post Reply