View Single Post
  #7 (permalink)  
Old 12-29-2008, 9:35 AM
suresh_ed suresh_ed is offline
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: May 2008
Posts: 26
Reputation: 25
suresh_ed is on a distinguished programming path ahead
Default KillProcess class

I am using the following function to kill the specific process. But it couldn't able to find the process to kill.

calling KillProcess("yandytex.exe")


Dim prc() As Process
Dim ERROR_FILE_NOT_FOUND As Integer = 2
Dim ERROR_ACCESS_DENIED As Integer = 5
Try
prc = System.Diagnostics.Process.GetProcessesByName(Proc essName)
Dim eprc As IEnumerator = prc.GetEnumerator
eprc.Reset()

While eprc.MoveNext
Dim proc As Process = CType(eprc.Current, Process)
proc.Kill()
proc = Nothing
End While

eprc = Nothing
prc = Nothing

Catch e As System.ComponentModel.Win32Exception
If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
'MessageBox.Show(e.Message + ". Process not found.")
Throw New UnauthorizedAccessException(e.Message & ". Process not found.")
Else
If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
' Note that if your word processor might generate exceptions
' such as this, which are handled first.
'MessageBox.Show(e.Message + ". You do not have permission to kill this process.")
Throw New UnauthorizedAccessException(e.Message & ". You do not have permission to kill this process.")
End If
End If
End Try

Please Suggest
Reply With Quote