Public Sub endprocess(ByVal RemotePC As String, ByVal process As String)
Dim objWMIService As Object
Dim colProcessList As Array
Dim objprocess As Object
Dim response As Boolean
objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & RemotePC & "\root\cimv2")
process = "'" & process & "'"
colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " & process)
For Each objprocess In colProcessList
response = MsgBox("End " & process & " on " & pcname & "?", MsgBoxStyle.YesNoCancel)
If response = vbYes Then
objprocess.Terminate()
Else
Exit Sub
End If
Next
End Sub
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] notepadProcs() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName([/SIZE][SIZE=2][COLOR=#800000]"Notepad"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"."[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#008000]'The character (.) equals to this machine's name
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] proc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Diagnostics.Process [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] notepadProcs
proc.Kill()
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE]
This is the way to kill all Notepad processes if found:
VB.NET:[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] notepadProcs() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName([/SIZE][SIZE=2][COLOR=#800000]"Notepad"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"."[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#008000]'The character (.) equals to this machine's name [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] proc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Diagnostics.Process [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] notepadProcs proc.Kill() [/SIZE][SIZE=2][COLOR=#0000ff]Next [/COLOR][/SIZE]
You can change the dot in this line to a machine name to kill Notepad remotely:
System.Diagnostics.Process.GetProcessesByName("Notepad", ".")