Re: test if a program is running

new topic     » goto parent     » topic index » view thread      » older message » newer message
otterdad said...

i use this tiny snippet to keep multiple instances of the same app from running on the same machine. it uses shared memory and stuffs the windows title. it could be tweaked to keep dependent concurrent apps from firing by stuffing the same key into shared memory. i call it only_one.ew

 
-- allow only one instance of this program 
-- 
-- check for multiple calls - will confuse you by shutting down early 
atom one_already one_already = False 
 
global procedure only_one(atom local_hwnd) 
	object jk atom zCreateSemaphore, zGetLastError, zERROR_ALREADY_EXISTS 
	if one_already then warnErr("calling only one multiple times") end if 
	one_already = True 
 
	zCreateSemaphore = registerw32Function(kernel32,"CreateSemaphoreA", 
    	{C_POINTER,C_INT,C_INT,C_POINTER},C_INT) 
	zGetLastError = registerw32Function(kernel32,"GetLastError",{},C_INT) 
	zERROR_ALREADY_EXISTS = 183 
 
	-- create a semaphore for this instance 
	jk = w32Func(zCreateSemaphore,{NULL, 0, 1,  
    	allocate_string(getText(local_hwnd))}) 
	jk = w32Func(zGetLastError,{}) 
	if jk = zERROR_ALREADY_EXISTS then  
    	abort(0) -- abort if we're already running ! 
	else 
    	--warnErr("good 2 go") 
	end if 
 
	return 
end procedure 
 

hope it helps!

OtterDad

Geez, that is way over my head. I need to know if program "xyz" (not mine btw) is running then I can't launch it again. It's a credit card verification program (xyz) which doesen't work correctly if it is already running since it's returned data is a text file on the local machine with the same name.

Can your routine check that?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu