Click to See Complete Forum and Search --> : Kill an executable File subroutine


dr223
December 1st, 2009, 04:38 AM
Hallo,

I would like to write a sub routine to kill an executable file called 'dfsvc.exe'. I'll call this subroutine when I exit my application to kill this file. When I exit my application this file is still running and takes around 15 minutes before it disappears. I would like to kill it to remove the delay.. The following code below doesnt work.. any ideas please


Private Sub Kill()

Dim aProcess As System.Diagnostics.Process

aProcess = System.Diagnostics.Process.GetProcessesByName("dfsvc.exe")

aProcess.Kill()

End Sub


Thanks

HanneSThEGreaT
December 2nd, 2009, 07:45 AM
What you have written kills the process, and not the actual file.

Try looking into the System.IO namespace and then using the File.Delete method.

If the exe is running, you might battle to delete it...