Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Killing a process
Message
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Killing a process
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01489697
Message ID:
01489697
Vues:
134
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.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform