how to check for your prg running?  
Author Message
Fox Me Up





PostPosted: Visual FoxPro General, how to check for your prg running? Top

heres my prob. when you launch my application and minimize it and then try and launch it in a second screen you get alot of errors.


how can i check if the program is already running so i know to cancel the prg right away if it is alrdy running


Visual FoxPro1  
 
 
Aleniko





PostPosted: Visual FoxPro General, how to check for your prg running? Top

I'm sure there must be bette ways to do this, but I used to have a file locally which I would lock a record at login and unlock it at logout.
But again, I'm sure there is a better way.



 
 
David Frankenbach





PostPosted: Visual FoxPro General, how to check for your prg running? Top

If your app as a static window title it's pretty easy.

_screen.Caption = "My cool app"

if ( AppAlreadyRunning() )
return
endif

messagebox( "here we go" )
return


function AppAlreadyRunning()

local lcCaption, llReturn

lcCaption = _screen.Caption

_screen.Caption = _screen.Caption + sys(2015) && temporarily change the caption

declare integer FindWindow in win32api ;
string lpClassName, ; && pointer to class name
string lpWindowName && pointer to window name

llReturn = ( FindWindow( .null., lcCaption ) > 0 )

_screen.Caption = lcCaption

return llReturn



 
 
Fox Me Up





PostPosted: Visual FoxPro General, how to check for your prg running? Top

thank you david :)

 
 
CetinBasoz





PostPosted: Visual FoxPro General, how to check for your prg running? Top






 
 
AttorneyProgrammer





PostPosted: Visual FoxPro General, how to check for your prg running? Top

Another possibility... use Windows Management Instrumentation Service...

I use this function to kill existing processes I don't want running...

PARAMETERS pc_ProcessToKill

* Get connection to Windows Management Instrumentation service

lo_WMI = GETOBJECT("winmgmts://")

* Set query into service to look for process to kill

lc_Query = "select * from win32_process where name='" + pc_ProcessToKill + "'"

* Get query results

lo_Results = lo_WMI.ExecQuery(lc_Query)

* Terminate all instances of process

FOR EACH oProcess IN lo_Results

* Terminate process session

oProcess.Terminate(0)

NEXT


 
 
CetinBasoz





PostPosted: Visual FoxPro General, how to check for your prg running? Top

WMI might not be available on a computer while winAPI does.
 
 
AttorneyProgrammer





PostPosted: Visual FoxPro General, how to check for your prg running? Top

Betin, I thought WMI was standard install from W2K going forward (it works on all of my W2K and newer OS pcs). But if you're talking pre-W2K, I believe you're correct. I just like WMI over API as it is very versatile and seemingly skinny on code.
 
 
CetinBasoz





PostPosted: Visual FoxPro General, how to check for your prg running? Top

Yes I mean pre2K (and we have many customers using win9x,winNT it's frustrating for me to always seek a method that would work on those machines too - meaning even with winAPI I have to choose carefully:( ).