Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Test if program is running

Test if program is running

Test if program is running

Hello Colleagues!

I have an executable program (MENU0REC.EXE) that in its menu has a button to call another program

CODE -->


All programs are in VFP 9.

That said, the user execute MENU0REC.EXE, click on one button to execute MENU1EST.EXE and do his/her work. After some time he/she go out for a coffee with the program MENU1EST.EXE opened (running).

When the user get back to work the program is minimize and he/she forgot about it and executes (again!) the main program MENU0REC.EXE.

Is there a way to, when executing MENU0REC.EXE, it checks if there is another instance of MENU0REC.EXE or MENU1EST.EXE in the same computer?

Thank you,

RE: Test if program is running

Hello Chriss!

Ok, I saw the code, thank you.

It seems complicated but I will try to understand it. I have to know where in the code I have to put the 2 program names (MENU0REC.EXE and MENU1EST.EXE).

Also, I want to detect if one of the programs is already running (minimized) in the SAME computer, not in another computer.

Thank you,

RE: Test if program is running

No worries, this is in the same computer.

You want to knwo if MENU1EST.EXE already runs, so you would test for that one. And there are many ways to use this.
Either you check whether MENU1EST.EXE already runs in MENU0REC.EXE and then don't run it again.
Or in the start of MENU1EST.EXE this checks whether itself already runs. If it finds itself twice in the list, it can quit.


RE: Test if program is running

Hi SitesMasstec.

1) Chris' solution is great. 2) The code bellow works well too, and 3) you can always low-level read the tasks from the Windows Task Manager and determine if the exe is already running.


*====== main prg
* Make sure that PROG1.EXE is NOT already running
IF run_count > 1
* if run_count is >1, then the app is already running, so do not run again
* count=1 is original app
* count=2 is the next instance that would find it already running
MESSAGEBOX("The PROG1 is Already running. Press <ENTER>.",48)
* QUIT and switch to the other instance


* Program: IsExeRunning
* Purpose: to determine if an EXE is already running, and terminate it if directed so.

local loLocator, loWMI, loProcesses, loProcess
loLocator = createobject('WBEMScripting.SWBEMLocator')
loWMI = loLocator.ConnectServer()
loWMI.Security_.ImpersonationLevel = 3 && Impersonate

loProcesses = loWMI.ExecQuery([SELECT * FROM Win32_Process WHERE Name = '] + tcName + ['])

return loProcesses.count


Good luck,

RE: Test if program is running

Chris, Sime:

As I am not an expert in Visual FoxPro I opted to dive in Sima's code (because the few lines it has) and it worked for me.

Sima, I would like to know if the code you provided allows the same program to run in 2 different machines in a network.

All I need is the program NOT running twice in the SAME machine, but it needs to be run by users in different machines.

Thank you,

RE: Test if program is running

Sure, it can run on as many machines as you want (on a network location or their separate copies on the local drives), files shared, handshaking and all that. It just doesn't allow it to run twice from the same PC/workstations - which is what you want, right?

RE: Test if program is running

Just one thing, SitesMasstec

your question is valid, as WMI in general can query for other systems, too.
But both solutions are based on the local process list only. So only on the same computer. It takes a bit more to run WMI queries that search in many computers.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close