Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quit a Process

Status
Not open for further replies.

Hannes214

IS-IT--Management
Jan 30, 2006
45
0
0
DE
Hi

How can I quit an other process from a vfp-application?
I want to kill the process abc.exe at a special time and run an other application...

Can anybody help me?

IT-Management
( FoxPro-Newbi :eek:) )
 

You would need to get the process handle of the application to be terminated. If you can do that, use the TerminateProcess() API:

Code:
DECLARE INTEGER TerminateProcess IN kernel32;
    INTEGER nHandle,;
    INTEGER nExitCode

TerminateProcess(<put process handle here>, 0)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thx .. but how can I get the process handle??
I only have the name of the process...

IT-Management
( FoxPro-Newbi :eek:) )
 
Hannes214

The following snippit will kill any instances of process2kill.exe
Code:
[COLOR=blue]oManager = GETOBJECT([winmgmts:])
cQuery = [select * from win32_process where name='process2kill.exe']
oResult = oManager.ExecQuery(cQuery)
FOR EACH oProcess IN oResult
[tab]oProcess.Terminate(0)
NEXT
oManager = .NULL.
oResult	= .NULL[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander[sup]tm[/sup].net
PDFcommander[sup]tm[/sup].com
 
Thx Cris

But I have the "old" problem, that I can't use [winmgmts:]under VFp 6.0 ...

IT-Management
( FoxPro-Newbi :eek:) )
 
I want to kill a screen-saver at a special time...
so I dont think, that it has a titel... and I dont know the titel...

IT-Management
( FoxPro-Newbi :eek:) )
 
Ok .. I find a solution that works with VFP 6.0

Code:
Local lcRemoteComputer, lcAdminUserName, lcAdminPassword, loSWbemLocator, loSWbemServices

lcAdminUserName=""
lcAdminPassword=""
lcRemoteComputer = "."

loSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
loSWbemServices = loSWbemLocator.ConnectServer(lcRemoteComputer, "root\cimv2",lcAdminUserName,lcAdminPassword)
lcolSWbemObjectSet = loSWbemServices.InstancesOf("Win32_Process")

FOR EACH loProcess In lcolSWbemObjectSet
	IF TRANSFORM(loProcess.Name) = "blackshow.scr"
    	*Messagebox("Name: " + TRANSFORM(loProcess.Name)+CHR(13)+"Process ID: " +;
    	*			TRANS(loProcess.ProcessID)+CHR(13)+"Prozess wird beendet.")
    	loProcess.Terminate(0)
    ENDIF
NEXT

IT-Management
( FoxPro-Newbi :eek:) )
 

Hannes,

Your solution seems to work, but Im curious ... what exactly is WbemScripting? I've not come across it before. Also, is the reference to a "remote computer" significant? It works OK on a local machine.

I also discovered that loProcess.Name is case-sensitive.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

From MSDN:
In summary, WBEM is not browser-based, nor is it a user interface (UI) tool, a data repository, a network management protocol, a component model, or a registry, directory, or file system replacement. WBEM is an initiative that proposes a set of standards for managing the enterprise network

Evidently, WMI is a portion of WBEM.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Yup. Typical doublespeak from someone trying to invent a standard. [smile]
I thought the "what it isn't" description was quite entertaining.
The "what it is" part, I don't think anyone really knows.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top