Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Terminate a DOS app from VFP?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00921791
Message ID:
00921801
Vues:
18
Just a couple of comments:

If instead of using InstancesOf you use a ExecQuery, then you can filter the name of the program directly in it, and WMI will do a case insensitive search of it, for example:
loCIMV2		= GetObject("winmgmts://localhost/root/cimv2")
loProcesses	= loCimv2.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" + lcExe + "'")
For Each objProcess in loProcesses
	objProcess.Terminate(0)
Next
The where clause will work no matter what was the actual "case" of the application instance, making it, IMO simpler.

The other comment is about the number of instances, if multiple instances of the program are running, but you only one to kill one, using the name is somewhat random, so I think that, for lack of information (for example Process_id) is better to terminate all processes. Of course that is just my opinion.

>* from WMI
>LPARAMETERS lcexe,lcmachine
>*FUNCTION KillProcess(lcExe,lcMachine)
>
>lcMoniker = "winmgmts://" + IIF(!EMPTY(lcMachine),lcMachine + "/","")
>oWMI = GETOBJECT(lcMoniker)
>loProcesses = oWMI.InstancesOf("Win32_Process")
>lcExe = LOWER(lcEXE)
>
>FOR EACH loProcess in loProcesses
> IF LOWER(loProcess.Name) = lcExe
> IF loProcess.Terminate() = 0
> RETURN .T.
> ENDIF
> ENDIF
>ENDFOR
>
>RETURN .F.
>
>Just pass something like killprocess('cmd.exe')
>
>John
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform