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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote Thread in another process 2

Status
Not open for further replies.

sfuterma

Programmer
Jan 9, 2006
5
CA
Hi,

1. How can I list / display / detailed, all Threads in a specific process.
2. After I found those details, how can I kill / stop, remote Thread, from my process.

Thanks,
Shai.
 
sfuterma

Welcome to the forum.

The following code will list all running processes and remove all instances of MS Word
Code:
[COLOR=blue]oManager = GETOBJECT([winmgmts:])
oApps = oManager.InstancesOf([Win32_process])
CREATE CURSOR TEMP (name C(20))
FOR EACH PROCESS IN oApps
[tab]INSERT INTO TEMP (name) VALUES (LOWER(PROCESS.name))
NEXT

BROW

cQuery = [select * from win32_process where name='winword.exe']
oResult = oManager.ExecQuery(cQuery)
FOR EACH oProcess IN oResult
[tab]oProcess.Terminate(0)
NEXT[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander[sup]tm[/sup].net
PDFcommander[sup]tm[/sup].com
 
Hi, I still need a way to know how can I list / display / detailed, all Threads in a specific process, on Windows. After I'll know each Threads details I need a way to stop or kill the specific Thread.

Thanks,
Shai.
 
Hi Chris,

A star for you. I was just looking at a better way to prevent users from launching multiple instances of an application. I think you have FAQ material here!

Jean
 
Jean

Thanks for the star - the following use of WMI at the top of a main.prg to determine the running processes will prevent multiple instances of the same app.
Code:
[COLOR=blue]LOCAL llQuit[COLOR=green]	
*!* Check for instance(s) of Myapp running[/color]
oManager = GETOBJECT([winmgmts:])
cQuery = [select * from win32_process where name='myapp.exe']
oResult = oManager.ExecQuery(cQuery)

IF oResult.Count > 1
[tab]llQuit = .T.
ENDI[COLOR=green]	
*!* Clean up[/color]
oManager = .NULL.
oResult = .NULL.
RELEASE cQuery, oResult, oManager

IF llQuit[COLOR=green] && Myapp.exe running twice[/color]
[tab]QUIT
ENDI[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander[sup]tm[/sup].net
PDFcommander[sup]tm[/sup].com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top