Start Program if it is NOT running

If you have a question or need help, this is the place to be.
Post Reply
Search&Destroy
Posts: 25
Joined: Wed Aug 19, 2009 10:40 am

Start Program if it is NOT running

Post by Search&Destroy » Wed Aug 25, 2021 10:18 pm

Hi there,

I would like to start a Program if it is NOT already running.
Because it is possible to open that Program multiple time, but I dont want that.
How do I check that?

I tried to "Find Window" -> selected the Program -> added a Jump If -> last command not successful -> jumped to macro that starts the Program.
But that did not worked for me.

Any other solutions?

User avatar
Sem;colon
Plugin Developer
Posts: 892
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Start Program if it is NOT running

Post by Sem;colon » Thu Aug 26, 2021 5:51 am

If you like my work, Image me a drink :wink:

Search&Destroy
Posts: 25
Joined: Wed Aug 19, 2009 10:40 am

Re: Start Program if it is NOT running

Post by Search&Destroy » Thu Aug 26, 2021 1:35 pm

THX for your answer :)

But I no clue, how I can use it in my case :D
I just saw that it shows me in the Log, that a Program did start or have been closed.
Process.Created.XYZ
Process.Destroyed.XYZ

But what if I restart PC/EventGhost?
EG would not have Process.Destroyed or Process.Created in the log while EG was not running so it cant know if its already running or not (just by this 2 Log entrys).

Cant find any Actions related to that PlugIn.

User avatar
Sem;colon
Plugin Developer
Posts: 892
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Start Program if it is NOT running

Post by Sem;colon » Thu Aug 26, 2021 5:16 pm

Hi!
Can you check if you have the right version? (You see it when adding the plugin to your config)
It should be 1.1.0 and not the one that comes with EventGhost.. I could imagine that the import didn't work
If you like my work, Image me a drink :wink:

cvben
Posts: 42
Joined: Wed Jun 07, 2017 8:30 pm

Re: Start Program if it is NOT running

Post by cvben » Tue Sep 07, 2021 5:19 am

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc6">
    <Folder Name="is it running" XML_Guid="{1FB12095-674B-46D8-B5DD-57086A7502B5}">
        <Macro Name='Run Command: TASKLIST /FI "IMAGENAME eq notepad.exe"' XML_Guid="{EB374D38-E883-4135-BD23-15998F6BDC26}" Expanded="True">
            <Event Name="Main.OnInit" XML_Guid="{630C9032-FCC1-4B88-B744-82CAB77C3885}" />
            <Action XML_Guid="{FAA583D9-3275-46A6-A284-C372BD7095CA}">
                System.Command(u'TASKLIST /FI "IMAGENAME eq notepad.exe"', False, True, u'', True, True, True, False, False)
            </Action>
        </Macro>
        <Macro Name="Python Script" XML_Guid="{5996E376-E64C-4665-B2FE-80F35567558D}" Expanded="True">
            <Event Name="System.WindowsCommand" XML_Guid="{94D8D9D0-CBF8-4706-98E1-ABFCE5B9FE12}" />
            <Action XML_Guid="{21D9572D-837F-4518-96CA-11166AB5C82F}">
                EventGhost.PythonScript(u'import os\n\nif "No tasks" in eg.event.payload:\n    os.system(r"C:\\Windows\\System32\\notepad.exe")')
            </Action>
        </Macro>
    </Folder>
</EventGhost>
Copy that into your eg.

Main.OnInit triggers the cmd command: TASKLIST /FI "IMAGENAME eq notepad.exe" This checks whether a specific program is running. You can change the trigger to suit your needs.

Then there is a small python snippet that starts the program if it's not running.

You could also code in an eg.TriggerEvent to fire a macro to run the program through the eg system module run application, or use the cmd command: tasklist itself if you want to check against the entire list. A python script along the lines of: if "notepad.exe" not in eg.event.payload then do x

Post Reply