Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Killing a process
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01489697
Message ID:
01489699
Views:
91
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I have the following code to kill all VFP instances
>
>
>FUNCTION IsExeRunning(tcName, tlTerminate)
>LOCAL loLocator, loWMI, loProcesses, loProcess, llIsRunning
>loLocator 	= CREATEOBJECT('WBEMScripting.SWBEMLocator')
>loWMI		= loLocator.ConnectServer() 
>loWMI.Security_.ImpersonationLevel = 3  		&& Impersonate
> 
>loProcesses	= loWMI.ExecQuery([SELECT * FROM Win32_Process WHERE Name = '] + tcName + ['])
>llIsRunning = .F.
>IF loProcesses.Count > 0
>	FOR EACH loProcess in loProcesses
>		llIsRunning = .T.
>		IF tlTerminate
>			loProcess.Terminate(0)
>		ENDIF
>	ENDFOR
>ENDIF
>RETURN llIsRunning
>
>However, today it was giving me out of memory error (VFP application seemed to go into infinite loop because of the bug I introduced - it was showing the same error over and over again in the messagebox).
>
>I was able to kill it immediatelly using Task Manager.
>
>I'm wondering how to make this (or similar) code to be 100% robust?
>
>Thanks.

I have always useid the TerminateProcess API rather WMI and always had success.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform