Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Process by PID
Message
From
10/07/2009 06:45:33
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01411347
Message ID:
01411356
Views:
63
Hallo Christof,

there is a application running multiple times on my comp (similiar to have VFP running more then once)

I need to have acces to a specific instance not to the first.

I know how to get the list of all applications and can read the ID from this.

But I will have a closer look at your code after my holiday.

Thank you
Agnes

>Hi Agnes,
>
>>how do I get the application of a given PID?
>
>What do you mean by "application"? Do you want to know the name of the EXE file, or do you want to get a process handle to change something for the application? Here's a program that would return the name of the EXE using API functions (requires my Struct.class). You can also use WMI to obtain these information.
>
>*=====================================================
>* Returns the name of the EXE for a given process ID
>*=====================================================
>LParameter tnPID
>
>	*--------------------------------------------------
>	* 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, lnRet, lcString, lcStringEmpty, lcEXE
>	lnHandle = CreateToolhelp32Snapshot(2,0)
>	lcStringEmpty = oProcessEntry.GetString()
>	lcEXE = ""
>	If lnHandle > 0
>		lcString = m.lcStringEmpty
>		lnRet = Process32First(lnHandle,@lcString)
>		oProcessEntry.SetString(lcString)
>		Do While lnRet > 0
>			If oProcessEntry.nProcessId == m.tnPID
>				lcEXE = oProcessEntry.cExeFile
>				Exit
>			EndIf 
>		 	lcString = m.lcStringEmpty
>			lnRet = Process32Next(lnHandle,@lcString)
>			oProcessEntry.SetString(lcString)
>		Enddo
>		CloseHandle(lnHandle)
>	Endif
>	
>	*--------------------------------------------------
>	* cleanup
>	*--------------------------------------------------
>	oProcessEntry.Release	
>
>Return m.lcEXE
>
>*-----------------------------------------------------
>* 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
>
>Alternatively, you can use GetProcessImageFileName (http://msdn.microsoft.com/en-us/library/ms683217%28VS.85%29.aspx), but you would need to open the process and pass in the handle.
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform