Private Sub KillProcess(ByVal ProcessName As String)
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(ProcessName)
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
End Sub
Marshall.ReleaseComObject(..)
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
[COLOR=green]'Reading and getting info from excel sheet[/COLOR]
Dim row As Int32
Dim cellref, val As String
[COLOR=green]'create excel application and hide it[/COLOR]
Dim ex As Application = New ApplicationClass()
ex.Visible = False
[COLOR=green]'open the workbook[/COLOR]
Dim wb As Workbook = ex.Workbooks.Open("c:\CalcUpDate\yazdayrr.xls")
If wb IsNot Nothing Then
[COLOR=green]'default worksheet is item 1[/COLOR]
Dim ws As Worksheet = DirectCast(wb.Worksheets(1), Worksheet)
Dim UPdate As Date
[COLOR=green]'get date of update[/COLOR]
cellref = Chr(68) & (4)
UPdate = DirectCast(ws.Range(cellref), Range).Value
MsgBox(UPdate) [COLOR=green] 'for test only[/COLOR]
[COLOR=green]'loop thru as many rows/cols as you need[/COLOR]
For row = 0 To 13
[COLOR=green]'build cell reference ie. 0,0 = A1[/COLOR]
cellref = Chr(68) & (row + 6)
[COLOR=green]'value from cell range[/COLOR]
val = DirectCast(ws.Range(cellref), Range).Value
currAry(row) = val
MsgBox(currAry(row), MsgBoxStyle.OkOnly) [COLOR=green]'for test only[/COLOR]
Next
End If
End Sub
System.Runtime.InteropServices.Marshall.ReleaseComObject(..)
GC.Collect(3)