Jump to content





Recent Status Updates

  • Photo
      16 Apr
    Kadence

    If you're reading this, you're on my profile and I know you're on my profile because I'm probably viewing yours.

    Show comments (6)
  • Photo
      10 Apr
    Poe

    Finally (and hopefully) i'm getting a team together that knows a little of this and a little of that; and maybe all my open source projects that are half written can begin to be released. :)

View All Updates
Photo
- - - - -

How to kill a process by process description and even more ?!


  • Please log in to reply
19 replies to this topic

#1 SmartCoder

SmartCoder

    CC Lurker

  • New Member
  • Pip
  • 8 posts
  • Learning:C#, Visual Basic .NET

Posted 13 September 2012 - 10:39 AM

Hi To all dear members of this lovely forum :)

this is my first post on this forum !

i want to know how can i kill a process by its description .!

i know how to do it by process name but it seems to difficult for me to do it by process description.

any one can help me with the right code ?

my sencond question is how to access the description of processes that shout "Access is denied" message.

thanks alot.
  • 1

#2 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 13 September 2012 - 10:45 AM

Never heard about Process by Description before ... but I think you can loop through all processes and use debug to look into the process info see if the one that you want to kill has the description you want to kill.


Process.GetProcesses();
  • 1

www.pickmike.com
I don't just develop software. I find solutions to your business needs.


#3 SmartCoder

SmartCoder

    CC Lurker

  • New Member
  • Pip
  • 8 posts
  • Learning:C#, Visual Basic .NET

Posted 13 September 2012 - 11:04 AM

thanks alot my friend but can you help me with source code ?

here is a code that i used for getting description of all running process :



For Each p As Process In Process.GetProcesses
Try
Dim ProcessFile = FileVersionInfo.GetVersionInfo(p.MainModule.FileName)
ListBox1.Items.Add(ProcessFile.FileDescription)
Catch ex As System.ComponentModel.Win32Exception
If ex.Message = "Access is denied" Then
Else
MsgBox("Access is denied")
End If
End Try
Next



and here is a code that i used for killing process by name :


  Dim SUNProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")
                              For Each pro As Process In SUNProcess
                                      pro.Kill()
                  			    Next

but i do not know how to do it with description ?

can you help me with a source code ?

thanks alot.
  • 0

#4 BlackRabbit

BlackRabbit

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,930 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 13 September 2012 - 12:26 PM

i think you have it done already, just didn't put it together, you just have to use the "by description" loop, and kill "p" when its descriptions matches what you are looking for, is it perhaps the matching being the problem ?
  • 0

#5 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 13 September 2012 - 12:54 PM

You are almost there ... now create your own function ... like GetProcessByDescription

So I would modify this:

Function GetProcessesByDescription(Byval description as string) As Process()

Dim result as new List(of Process)
For
Each p As Process In Process.GetProcesses

If (description == matchDescription) Then
result.add(p)
endif

Next
return result.ToArray();

Now ... you will have all the process with what ever description ..loop through the process and kill 1 by 1. The above codes are prototype, it may contains error.

hope this helps ...
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.


#6 SmartCoder

SmartCoder

    CC Lurker

  • New Member
  • Pip
  • 8 posts
  • Learning:C#, Visual Basic .NET

Posted 13 September 2012 - 10:30 PM

Thanks alot my friends.
I merged the codes like below but when i run it ,it causes to show Blue Screen of Death !

I checked the code again and run it again but the Blue Screen of Death appears again !


Function GetProcessesByDescription(ByVal description As String) As Process()
	 Dim result As New List(Of Process)
	 For Each p As Process In Process.GetProcesses
		 If (description = "Notepad") Then
			 result.Add(p)
			
		 End If
	 Next
	 Return result.ToArray()
End Function

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		
	 Dim SUNProcess() As Process = GetProcessesByDescription("Notepad")
	 For Each pro As Process In SUNProcess
		 pro.Kill()
	 Next
End Sub

  • 0

#7 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 14 September 2012 - 07:46 AM

I see that there an error because you're checking the description == hard-coded NotePad ... if you put NotePad in the description ... then it will add all processes ... so eventually you will kill everything. You need to compare description == theCurrentProcessDescription

hope this helps
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.


#8 SmartCoder

SmartCoder

    CC Lurker

  • New Member
  • Pip
  • 8 posts
  • Learning:C#, Visual Basic .NET

Posted 15 September 2012 - 03:53 AM

thanks alot my freinds but can you give me the right tested code that i can use it safely !

i do not want to see the blue screen of death any more . :(

i am a newbie and i havevconfused to what should i do !

thanks alot.
  • 0

#9 SmartCoder

SmartCoder

    CC Lurker

  • New Member
  • Pip
  • 8 posts
  • Learning:C#, Visual Basic .NET

Posted 16 September 2012 - 03:24 AM

any one please help me .

i don not know what to do .
  • 0

#10 AceInfinity

AceInfinity

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 270 posts
  • Programming Language:C, C++, C#, Perl, Visual Basic .NET, Assembly, VBScript, Others

Posted 16 September 2012 - 05:14 PM

Here's a .NET way, although you may encounter some Win32Exception's.

Dim Desc As String = "windows media player"
Dim FindProc As Process = Process.GetProcesses().FirstOrDefault(Function(p) Regex.IsMatch(p.MainModule.FileVersionInfo.FileDescription, Desc, RegexOptions.IgnoreCase))
If FindProc IsNot Nothing Then FindProc.Kill()

  • 0

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image


#11 SmartCoder

SmartCoder

    CC Lurker

  • New Member
  • Pip
  • 8 posts
  • Learning:C#, Visual Basic .NET

Posted 16 September 2012 - 07:41 PM

Here's a .NET way, although you may encounter some Win32Exception's.

Dim Desc As String = "windows media player"
Dim FindProc As Process = Process.GetProcesses().FirstOrDefault(Function(p) Regex.IsMatch(p.MainModule.FileVersionInfo.FileDescription, Desc, RegexOptions.IgnoreCase))
If FindProc IsNot Nothing Then FindProc.Kill()



thanks alot but it did not work for me .

i run it without any error but when i tested it for mor 15 app , the message "Access is Denied" apears !

it did not kill even 1 application !

please help me , what should i do ?

thanks.
  • 0

#12 AceInfinity

AceInfinity

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 270 posts
  • Programming Language:C, C++, C#, Perl, Visual Basic .NET, Assembly, VBScript, Others

Posted 16 September 2012 - 09:16 PM


Here's a .NET way, although you may encounter some Win32Exception's.

Dim Desc As String = "windows media player"
Dim FindProc As Process = Process.GetProcesses().FirstOrDefault(Function(p) Regex.IsMatch(p.MainModule.FileVersionInfo.FileDescription, Desc, RegexOptions.IgnoreCase))
If FindProc IsNot Nothing Then FindProc.Kill()



thanks alot but it did not work for me .

i run it without any error but when i tested it for mor 15 app , the message "Access is Denied" apears !

it did not kill even 1 application !

please help me , what should i do ?

thanks.


Here:

although you may encounter some Win32Exception's.


Although this is because of the accessibility from a x86 solution to 64 bit process modules from my experience.
  • 1

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image