Jump to content
Macro Express Forums

How to detect if MEP is running in another profile

Recommended Posts

I have a server that runs many automated tasks. If one inadvertently starts another session, EG from the console versus remote, MEP can be running twice on the same machine and conflict. Does anyone have any idea how one might avoid this?


Reflexively I was thinking of a startup macro that would check to see if MEP is already running but there are a few problems with this. First how would I prevent all the other macros from running at startup. Second how would I detect a process running in another session. I did a quick test and the Repeat with Process only returns processes in the current session.


I was considering dropping a file or registry token but that seems like a bad idea. What if MEP crashes and doesn't manage to remove the token. I suspect I'll need to write a VB app as a launcher but it seems to me there should be a way to do it with MEP. Also even if I do create a launcher I suspect I might still have problems detecting processes in another session.


Perhaps I could create a macro that deletes a file from a folder whenever it appears. Then when the macro starts it creates the file and if it still exists a second later then it knows it's the only one and kills the file. Still seems inelegant. It's like I need an "If MEP is Already Running" condition.


And elegant solution ideas?

Link to comment
Share on other sites

The Terminal Services Session ID command will tell you if you are using the Console or some other session. Could you use that information? Perhaps write it to a file. When a macro starts have it compare the current Session ID with the Session ID in the file. If they match you know that Macro Express forgot to clear the flag the last time it ran. If they do not match you know another session set the flag.


Or, you may just decide to run the macros from the console session. I think the console session is always 1.


What conflicts? Do you need a unique filename? If you include the Session ID as part of the filename you could ensure that you have a unique file for each session.

Link to comment
Share on other sites

My solution would be to write a script that takes control of the MEP launch process and alloows it to be launched only if not already running. As an extreme example, I might rename MaxExp.exe to MEP.exe, then compile the Launcher script, written in Autoit, to an executable called Macexp.exe and locate it in the Macro Express folder.

This would also take care of MEP being launched indirectly, i.e. by double-clicking on a playable macro.

Link to comment
Share on other sites

Samrae I had not thought of the session IDs but it still comes down to the fact that a token of some sorts needs to be dropped someplace and picked up later on close. The peril here is what if there's a dirty termination of MEP due to crash or something the token wouldn't be picked up and the MEP would never run again until someone manually removed it. Hence my idea of trying to ping it by doing something like dropping a file and seeing if any other instance responded. The conflicts in this case is that MEP handles a lot of things and runs a lot of audits. For instance it monitors an FTP drop box and fires a macro when a new file arrives and does several things with it. They will both try and access the same file at the same time and many other things I don't even want to try and consider.


Paul I agree with you and at the moment all of the 'MEP only' solutions seem a kludge or have potential issues. I'm currently looking at the GetProcessByName method of the Process class in .NET. I can write a simple launcher app that will check and see if MacExp is already running and if not then launch MEP. I tested it just now and it sees processes in other sessions which is not the case with MEP. This is probably the best way to go but I wanted to see if there was something I was missing with MEP.


Really I need to rewrite all of these as services as MEP is not the right tool for the job. But there are several things changing at this client at the moment so I need to just make do for now.

Link to comment
Share on other sites

When Macro Express Pro loads up it checks to see if another instance of Macro Express Pro is already running. If it is then the new instance terminates. You cannot run two instances of Macro Express Pro in the same session.

Paul, is it possible for a process running in one session to see the process from another session? I thought they were independent of each other.


Edit, I see from Cory's response that .NET can see processes from other sessions.

Link to comment
Share on other sites

Maybe it's some Delphi limitation. Because the Repeat With Process also can not see processes in another session. I was thinking it would be cool if one had a checkbox in the Repeat With Process command to include other sessions but maybe that's not even possible. I was also considering requesting a command line switch to include other sessions in it's startup check but really I feel I'm probably the only person in the world that has this problem which is only temporary since I'm phasing it out and have the skills to create a launcher app.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...