473,545 Members | 666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To End Process Tree

Is there a way in VB.NET to mimic the "End Process Tree" option found
in the task manager? I have searched the process class and can not
find any way to determine a relationship between any two processes.
Is it possible to stop a process and all its "children" in VB.NET?

Oct 3 '07 #1
1 10435
On Oct 3, 3:29 pm, SVog...@gmail.c om wrote:
Is there a way in VB.NET to mimic the "EndProcessTree " option found
in the task manager? I have searched theprocessclass and can not
find any way to determine a relationship between any two processes.
Is it possible to stop aprocessand all its "children" in VB.NET?
Incase anyone else has his problem, i have finaly found code to solve
it for my purposes. If you have a process already handled in your
program, and have its ID, then you can loop though all processes using
the process class and send the ID ov each process to
GetParentProces sID. If the ID of your process matches the returned ID
then you can kill it. If anyone happens to read this and spots a
problem please let me know. Thanks
Private Declare Function CreateToolhelp3 2Snapshot Lib
"KERNEL32.D LL" _
(ByVal dwFlags As Integer, ByVal th32ProcessID As Integer) As
Integer
Private Declare Function Process32First Lib "KERNEL32.D LL" _
(ByVal hSnapshot As Integer, ByVal PE As Byte()) As Integer
Private Declare Function Process32Next Lib "KERNEL32.D LL" _
(ByVal hSnapshot As Integer, ByVal PE As Byte()) As Integer
Private Declare Function CloseHandle Lib "KERNEL32.D LL" _
(ByVal hObject As Integer) As Integer

Private Sub KillAllAssociat edProcesses(ByV al track As String)
Dim localAll As Process() = Process.GetProc esses()
For Each i As Process In localAll
Dim ParentProcessID As Integer
ParentProcessID = GetParentProces sID(i.Id)
If ParentProcessID = ClientTracks(Tr ack).Process.Id Then
Process.GetProc essById(i.Id).K ill()
End If
Next
End Sub

Function GetParentProces sID(ByVal id As Integer) As Integer
Dim b(564 - 1) As Byte
'write the size into the structure
BitConverter.Ge tBytes(SIZEOF_P ROCESSENTRY32). CopyTo(b,
SIZE_OFFSET)
Dim h As Integer =
CreateToolhelp3 2Snapshot(TH32C S_SNAPPROCESS, 0)
Try
Dim rv As Integer = Process32First( h, b)
If rv <1 Then
Throw New Exception("Coul d not enumerte processes.")
End If
While rv = 1
Dim pid As Integer = BitConverter.To Int32(b,
PROCESS_OFFSET)
Dim parent As Integer = BitConverter.To Int32(b,
PARENT_OFFSET)
If pid = id Then
Return parent
End If
rv = Process32Next(h , b)
End While
Finally
CloseHandle(h)
End Try

Return -1

End Function

Oct 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2763
by: Dinesh | last post by:
Hi, I have two tables 'master' and 'child', the master is the master table for all nodes in all trees. To get children of any node, we need to go to the 'child' table to get the nodeid of the children. The master has about 40,000 such trees with about 400 nodes in each tree. The input to me is the 'Root Node'/'First Node' of a tree. I need...
3
6377
by: pattanawadee | last post by:
Deall All, Could anybody suggestion me How to kill all inherrit processes (sibling child,previous and parent process) in the case I know only child process id and user id, For example I strart to trace pid 124 of user A (uid = 100) and then I noticed that he doing something wrong so, I get process id now process id is 156 (supposed) then I...
5
364
by: Roman Ziak | last post by:
Hello, I posted this message to comp.compilers couple days ago, but it did not apear there for some reason. --- I have had this idea about the compilation process, but I may be not sound enough yet to see the whole picture.
2
7758
by: Raed Sawalha | last post by:
Hello , I have windows service which do listening to specified directory using FileSystemWatcher , on Created Event and Get all the files in the directory using Directory.GetFiles function then foreach file in the files list and passed the file path to a function to read its content then process it then move it to another directory am reading...
3
2926
by: rao | last post by:
Hi All, I am generating temporary xml files to bind it to tree view control. A unique xml file is generated for each user. I generating these files Using streamwriter class. Later when I try to delete the file with File.Dlete in page unload event I gets an error File already in use by another process. When I examine process explorer...
0
3729
by: Tom Bower | last post by:
In the Windows Task Manager if I select a Process and right-click, I can choose to "End Process" or "End Process Tree." Is there a VB equivalent for "End Process Tree" if you have a handle to a process? I know about process.Kill and process.CloseMainWindow, but how would I do the equivalent of "End Process Tree" where any child or...
6
10531
by: kimiraikkonen | last post by:
Hello, I want to ask this: If i do: System.Diagnostics.Process.Start("c:\lame", "--preset standard c:\blabla.wav c:\blabla.mp3") it works. But i don't want this. I want my 2 textboxes must take place as variable like: System.Diagnostics.Process.Start("c:\lame", "--preset standard textbox1" textbox1.text + textbox2.text). But that...
1
2492
by: sternr | last post by:
Hey, Is there a way to create a new process that will not be my child process? Meaning, that after opening the new process, if I'll open TaskManager and do "End Process Tree" on the parent process, it will not terminate the child process as well? Thanks ahead sternr
0
1418
by: dogatemycomputer | last post by:
I'm new to C#. I am using the following C# method to populate a TreeView control. If you call this method once during the life of form then it works perfectly. If you call the method a second time (without closing and reloading the app) then the process list populates the TreeView control with varying degrees of success. Sometimes the...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7807
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.