Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking if another VFP app is running in Windows
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01409275
Message ID:
01409282
Views:
87
This message has been marked as a message which has helped to the initial question of the thread.
Hi David,

there are many approaches using API functions or WMI. Here's an approach with API function that uses my Struct class (available in the download area):
*=====================================================
* AProcess.PRG
*
* Returns a list of all running EXE files
*=====================================================
LParameter tacProcess

	External Array tacProcess

	*--------------------------------------------------
	* Declare WIN-API functions
	*--------------------------------------------------
	Declare Integer CreateToolhelp32Snapshot In win32api Integer, Integer
	Declare Integer CloseHandle In WIn32Api Integer
	Declare Integer Process32First In WIn32APi Integer, String@
	Declare Integer Process32Next In WIn32APi Integer, String@

	*--------------------------------------------------
	* load struct component
	*--------------------------------------------------
	Local oProcessEntry
	Set Class to Struct.VCX Additive
	oProcessEntry = CreateObject("PROCESSENTRY32")

	*--------------------------------------------------
	* get processes
	*--------------------------------------------------
	Local lnHandle, lnCount, lnRet, lcString, lcStringEmpty
	lnCount = 0
	lnHandle = CreateToolhelp32Snapshot(2,0)
	lcStringEmpty = oProcessEntry.GetString()
	If lnHandle > 0
		lcString = m.lcStringEmpty
		lnRet = Process32First(lnHandle,@lcString)
		oProcessEntry.SetString(lcString)
		Do While lnRet > 0
			lnCount = lnCount+1
			Dimension tacProcess[lnCount]
			tacProcess[lnCount] = oProcessEntry.cExeFile
			lcString = m.lcStringEmpty
			lnRet = Process32Next(lnHandle,@lcString)
			oProcessEntry.SetString(lcString)
		Enddo
		CloseHandle(lnHandle)
	Endif
	
	*--------------------------------------------------
	* cleanup
	*--------------------------------------------------
	oProcessEntry.Release	

Return lnCount

*-----------------------------------------------------
* PROCESSENTRY32 Struktur
*-----------------------------------------------------
Define Class PROCESSENTRY32 as Struct
	nSize = 296
	nCntUsage = 0
	nProcessID = 0
	nDefaultHeap = 0
	nModuleID = 0
	nCntThreads = 0
	nParentProcessID = 0
	nPriClassBase = 0
	nFlags = 0
	cExeFile = ""
	cMembers = "l:nSize,l:nCntUsage,l:nProcessId,"+;
		"l:nDefaultHeap,l:nModuleID,l:nCntThreads,"+;
		"l:nParentProcessID,L:nPriClassbase,"+;
		"l:nFlags,0c260:cExeFile"
Enddefine
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform