Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please check my below code here kill process one by one on selecting the process, but i need to close all task from my listbox..so plz can u help me

Thanx in advance


Dim p As System.Diagnostics.Process

For Each p In System.Diagnostics.Process.GetProcesses()

Dim arr() As String = _
lstProcesses.SelectedItem.ToString().Split("-")

Dim sProcess As String = arr(0).Trim()
Dim iId As Integer = Convert.ToInt32(arr(1).Trim())

If p.ProcessName = sProcess And p.Id = iId Then
p.Kill()
End If

Next


I am trying to closing all the running task in my computer using vb.net, but i am facing problem, when i try to closing the running task then my system also shutdown..so plz any one can help me how can prevent my system close while running the application.


Thanks in advance
Posted
Updated 9-Sep-13 0:32am
v4
Comments
Mike Meinz 7-Sep-13 7:09am    
You probably need to add something to your code to prevent that. You didn't include any source code so I can't tell you what to change.
rahul dev123 7-Sep-13 7:13am    
here is my button click code

first i am find and adding all the running task in a list then kill all from the list, but here i actully dont know how to mention not to close system progrma

For Each p As Process In Process.GetProcesses
lstProcesses.Items.Add(p.ProcessName.ToString)
If Not p.ProcessName = "winlogon.exe" Or p.ProcessName = "VCSystemTray.exe" Or p.ProcessName = "VCAdmin.exe" Then
p.Kill()
End If
Next
[no name] 7-Sep-13 7:13am    
it's quite obvious that ur all running applications includes applications like explorer.exe,csrss.exe etc..which is responsible for shutting down ur system..
you have to filter your criteria depending on need...
rahul dev123 7-Sep-13 7:16am    
yes, actually i cant find out the process which cause my system shutdown
rahul dev123 7-Sep-13 7:18am    
plz can u help me how to find the process which cause the system shutdown..Thanks in advance

1 solution

The code below adds only user tasks with windows to the ListBox.

VB
For Each p As Process In Process.GetProcesses
    If p.MainWindowTitle.Length > 0 AndAlso p.SessionId > 0 Then
        lstProcesses.Items.Add(p.ProcessName & " | " & p.MainWindowTitle)
    End If
Next


Why do you need to do this? Perhaps an insight into that would help us provide you best practices.

You may have to study the Win32 SDK APIs to find APIs that you can use to distinguish between user applications and services and other operating system components.

Also, killing processes without first prompting the user to save in process work is considered "bad form".
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900