So I am creating an application that allows users to send basic keystrokes to end certain processes. But I am running into some issues. I know the code I have will work the problem is I do not know where to put the following code to execute the commands:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Keys.ControlKey + Keys.I Then
Try
KillProcess("chrome.exe")
Catch ex As Exception
MessageBox.Show("Process May Not Be Running", "Error Closing Chrome.exe", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
Also I am wondering how to let the user add commands themselves and end them using the keystrokes that they choose. Thanks and help would be greatly appreciated!
My Entire Coding Class:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Keys.ControlKey + Keys.I Then
Try
KillProcess("chrome.exe")
Catch ex As Exception
MessageBox.Show("Process May Not Be Running", "Error Closing Chrome.exe", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
Public Sub KillProcess(ByVal processName As String)
On Error GoTo ErrHandler
Dim oWMI
Dim ret
Dim sService
Dim oWMIServices
Dim oWMIService
Dim oServices
Dim oService
Dim servicename
oWMI = GetObject("winmgmts:")
oServices = oWMI.InstancesOf("win32_process")
For Each oService In oServices
servicename = LCase(Trim(CStr(oService.Name) & ""))
If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
ret = oService.Terminate
End If
Next
oServices = Nothing
oWMI = Nothing
ErrHandler:
Err.Clear()
End Sub
End Class
Also, here is a screenshot of the application so you can see what I am working with:
[IMG]http://screensnapr.com/e/S0oLwA.png[/IMG]
Thanks again!
-Chris