Kill Process

330 views
Skip to first unread message

Qatan

unread,
Oct 23, 2014, 7:00:10 PM10/23/14
to harbou...@googlegroups.com
Hello,
 
I am pretty sure it exists but right now I can’t remember where I saw it...
I even used something to kill a process in Windows. It was to kill Adobe Reader so I could create a PDF without having problems (like when it’s already created and opened previously).
Does anyone know how to terminate a program from inside Harbour?
Thanks for any help.
 
Qatan
 

marek.h...@interia.pl

unread,
Oct 24, 2014, 12:15:42 AM10/24/14
to harbou...@googlegroups.com

help taskkill

Regards,
Marek Horodyski

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Bernard Mouille [w]

unread,
Oct 24, 2014, 1:06:20 AM10/24/14
to harbou...@googlegroups.com

Hello Qatan,

 

You can try a basic sample for Windows.

 

Bernard.

 

 

* bm_ExeKill() - Fermer un programme.

* -----------------------------------

 

/*

 

En cours de développement.

Harbour 3.0.0 - Windows 7 pro 32

Ce programme est un exemple basique.

 

# Test.hbp - Compilation de Test.EXE.

# -----------------------------------

#

# Nom du programme avec éventuellement son chemin.

#

-oTEST.EXE

#

# Affiche tous les warnings.

#

-w3

#

# Ne fabrique pas l'exe si warning.

#

-es2

#

# Programme maître.

#

TEST.PRG

#

# Librairies : respecter l'ordre.

#

hbwin.lib

 

*/

 

*

* --------------

PROCEDURE Main

* --------------

*

SET DATE FRENCH

*

* Mise en ANSI ( Windows ) langue française.

*

REQUEST HB_LANG_FR

REQUEST HB_CODEPAGE_FRWIN

HB_CDPSELECT( 'FRWIN' )

HB_LANGSELECT( 'FR' )

*

SETMODE( 43, 80 )                                     && Lignes et colonnes d'affichage écran.

*

bm_ExeKill( "AcroRd32.exe" )

?

*

?

?

WAIT

*

RETURN

*

* ---------------------------------

FUNCTION bm_ExeKill( vExe )

* ---------------------------------

*

LOCAL oLocator, ;                           && Objet OleAutoClient

      oProcess, ;                           && Objet ExecQuery

      oWMI, ;                               && Objet ConnectServer

      cProc                                 && Programme à détruire.

*

oLocator := WIN_OleCreateObject("WbemScripting.SWbemLocator")

*

oWMI     := oLocator:ConnectServer(".", "root\cimv2")

*

oProcess := oWMI:ExecQuery('Select * from Win32_Process where Name = "' + vExe + '"')

*

FOR EACH cProc in oProcess

 cProc:Terminate()

ENDFOR

*

* Libère la mémoire.

*

oLocator := NIL

oProcess := NIL

oWMI     := NIL

*

RETURN NIL

 


De : harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] De la part de Qatan
Envoyé : vendredi 24 octobre 2014 01:00
À : harbou...@googlegroups.com
Objet : [harbour-users] Kill Process

--
Test.txt

Qatan

unread,
Oct 24, 2014, 2:39:28 AM10/24/14
to harbou...@googlegroups.com
Hello Marek,
 
Can be a good option but I was looking for something from inside Harbour – I mean, some function but in any case thanks for your suggestion.
I think taskkill is for Win Vista and plus, right? And tskill is for XP is I am not wrong.
I will search about it.
Thanks
 
Qatan

Qatan

unread,
Oct 24, 2014, 2:39:32 AM10/24/14
to harbou...@googlegroups.com
Hello Bernard,
 
It seems to be a good option.
I remember it was something like that... I am still looking for it on my *messy* source code archive...
I will do some tests and I will post the results.
Merci Beaucoup.
 
Qatan

Sergy

unread,
Oct 24, 2014, 8:42:29 AM10/24/14
to harbou...@googlegroups.com
Hi Qatan

taskkill works under my XP SP3 actually like as under W7

But yes - internal call of WMI service is more accurate.

пятница, 24 октября 2014 г., 10:39:28 UTC+4 пользователь Qatan написал:

Qatan

unread,
Oct 24, 2014, 10:34:31 AM10/24/14
to harbou...@googlegroups.com
Hello Bernard,
 
I found it!
It’s a bit different but uses the same principle.
It is interesting to see the differences to understand it.
Why do you use this way? => oLocator:ConnectServer(".", "root\cimv2")
Follows:
 
------8<-----
/* This code came originally from the PCTOLEDO forum by Leonardo Machado and modified by José Alves Siqueira
*
* Adapted to MiniGUI x Harbour by Marcelo Antonio Lázzaro Carli – malc...@terra.com.br
* 29/03/2012
*
* Reformated and minor changes (removed xhb.hbc dependency) by Mario Wan Stadnik (Qatan)
* 24/10/2014
*
* STATUSEXE()               -> Returns a list of active EXE
* STATUSEXE("TESTE.EXE", 1) -> If it is active returns .T. otherwise .F.
* STATUSEXE("TESTE.EXE", 2) -> Terminates it
*/
 
FUNCTION Main()
 
   LOCAL aMatriz:= StatusExe(), i
 
   SETMODE( 25,80 )
   CLS
  
   FOR i:= 1 TO LEN( aMatriz )
      ? aMatriz[i] // list all the processes
   NEXT
   ?
   ? 'Close WORD'
   ? 'Is WORD active? '; ?? StatusExe( [WINWORD.EXE], 1 )               // Is WORD active?
   ? 'Was it sucesfully terminated? '; ?? StatusExe( [WINWORD.EXE], 2 ) // terminates Word
   ?
   WAIT
  
RETURN NIL
 
 
FUNCTION Statusexe( cExecutavel, nDerruba )
 
   LOCAL aNomesProcesso:={}, oScriptObj, oWmiService, oListaProcess, oProcessos, lRet:= .F.
  
  
   hb_Default( @nDerruba, 0 )
 
   BEGIN SEQUENCE WITH { |oErr| BREAK( oErr ) }
      oScriptObj := win_OleCreateObject([wbemScripting.SwbemLocator])
      oWmiService:= oScriptObj:ConnectServer()
   RECOVER
      RETURN IF( nDerruba == 0, aNomesProcesso, lRet )
   END
 
   BEGIN SEQUENCE WITH { |oErr| BREAK( oErr ) }
      oListaProcess:= oWmiService:ExecQuery( "select * from Win32_Process" + IF( nDerruba == 0, "", " where Name='" + cExecutavel + "'" ) )
   RECOVER
      RETURN IF( nDerruba == 0, aNomesProcesso, lRet )
   END
 
   FOR EACH oProcessos IN oListaProcess
      AADD(aNomesProcesso, oProcessos:Name())
      lRet:= .T.
      IF nDerruba == 2
         oProcessos:Terminate()
      ENDIF
   NEXT
 
RETURN IF( nDerruba == 0, aNomesProcesso, lRet )
------>8------
 
Sent: Friday, October 24, 2014 7:06 AM
Subject: RE: [harbour-users] Kill Process
 

Hello Qatan,

Bernard Mouille [w]

unread,
Oct 24, 2014, 10:45:43 AM10/24/14
to harbou...@googlegroups.com

Hello Qatan,

 

I use this to connect to the current computer.

The other way is also good, I think.

 

Bernard

 

 


De : harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] De la part de Qatan
Envoyé : vendredi 24 octobre 2014 16:32
À : harbou...@googlegroups.com
Objet : Re: [harbour-users] Kill Process

BD

unread,
Dec 3, 2016, 9:31:24 AM12/3/16
to Harbour Users
Hi All,

When I compile Hazael's version of the kill process, I received the following error :

undefined reference HB_FUN_HB_DEFAULT


What am I missing here ?

Please help.

Regards.

Klas Engwall

unread,
Dec 3, 2016, 10:02:18 AM12/3/16
to harbou...@googlegroups.com
Hi BD,

> When I compile Hazael's version of the kill process, I received the
> following error :
>
> undefined reference HB_FUN_HB_DEFAULT
>
> What am I missing here ?
>
> Please help.

Are you still using Harbour 3.0 and not 3.2? hb_Default() was introduced
in this commit:

2012-06-04 17:51 UTC+0200 Viktor Szakats (vszakats.net/harbour)
* include/harbour.hbx
* src/rtl/Makefile
+ src/rtl/hbdef.c
+ added HB_DEFAULT( @<xVariable>, <xDefaultValue> )
it can replace DEFAULT ... TO ... command. In addition
it will set the value to the default one even when the
variable has any other type, not only NIL.

You can work around the missing function by using DEFAULT ... TO ...
or by checking the argument with valtype()

Regards,
Klas

BD

unread,
Dec 3, 2016, 10:11:25 AM12/3/16
to Harbour Users
Thanks Klas,

Yes, I am still running 3.0. Time to move over to 3.2, I suppose.

Regards.

Hazael

unread,
Dec 7, 2016, 4:44:11 PM12/7/16
to Harbour Users
Hi BD,

I confirm that the code still works fine with the latest Harbour 3.2 Nightly Build and Windows 10 Pro x64


Yes, I am still running 3.0. Time to move over to 3.2, I suppose.


I strongly recommend to change to Harbour 3.2 because it got so many commits (fixes, improvements, additions, etc...) but depending of your source code it may require to change some few things.

Anyway I definitely think the work to upgrade is worth.
Reply all
Reply to author
Forward
0 new messages