Ending the application programmatically using the file path in vb.net

I want to end the application using the full path to the file via vb.net, but I could not find it in the "Process" section. I was hoping for a simple Process.Stop (file path), for example, with Process.Start, but there was no such luck.

How can i do this?

+6
terminate
source share
2 answers

You will need to study the properties of each module "Modules" and, in turn, check the file names in your desired path.

Here is an example:

Vb.net

Dim path As String = "C:\Program Files\Ultrapico\Expresso\Expresso.exe" Dim matchingProcesses = New List(Of Process) For Each process As Process In process.GetProcesses() For Each m As ProcessModule In process.Modules If String.Compare(m.FileName, path, StringComparison.InvariantCultureIgnoreCase) = 0 Then matchingProcesses.Add(process) Exit For End If Next Next For Each p As Process In matchingProcesses p.Kill() Next 

FROM#

 string path = @"C:\Program Files\Ultrapico\Expresso\Expresso.exe"; var matchingProcesses = new List<Process>(); foreach (Process process in Process.GetProcesses()) { foreach (ProcessModule m in process.Modules) { if (String.Compare(m.FileName, path, StringComparison.InvariantCultureIgnoreCase) == 0) { matchingProcesses.Add(process); break; } } } matchingProcesses.ForEach(p => p.Kill()); 

EDIT: Updated code to account for case sensitivity for string comparisons.

+2
source share

to try

System.Diagnostics.Process.GetProcessesByName (nameOfExeFile) .First (). Kill ()

This ignores the file path.

+2
source share

All Articles