Page 1 of 1
How can I kill a process with GetProcessesByName ?
Posted: Sun Oct 09, 2016 1:31 pm
by rastek
Hi,
here is my vb code, but when I try to compile Ranorex gives process not foud error, please help me.
Dim proc = Process.GetProcessesByName("RealtimeConnectionsClient.exe")
For i As Integer = 0 To proc.Count - 1
proc(i).CloseMainWindow()
Next i
Re: How can I kill a process with GetProcessesByName ?
Posted: Mon Oct 10, 2016 9:28 am
by odklizec
Hi,
I'm not a VB.Net expert, but the code looks OK to me? Just one thing, use "RealtimeConnectionsClient" instead of "RealtimeConnectionsClient.exe" as the process name and make sure the process name is correct! I believe the processname must be always without the ".exe" extension.
Re: How can I kill a process with GetProcessesByName ?
Posted: Tue Oct 11, 2016 3:53 pm
by Aracknid
GetProcessByName returns an array, and you didn't declare proc as an array.
Try
Dim proc() as process = nothing
proc = Process.GetProcessesByName("RealtimeConnectionsClient")
For i As Integer = 0 To proc.Count - 1
proc(i).CloseMainWindow()
Next I
Re: How can I kill a process with GetProcessesByName ?
Posted: Sat Oct 22, 2016 2:37 pm
by rastek
Thanks Aracknid
I tried your suggestion and Ranorex compiler returned me this error, can you help for this error ?
'Count' is not a member of 'System.Array'. (BC30456)
And here is my full code part for the function, do I miss a library or sth ?
I also tried Host.Local.KillApplication which is comment out in the code.
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Drawing
Imports System.Threading
Imports WinForms = System.Windows.Forms
Imports System.Diagnostics
Imports System.ComponentModel
Imports Ranorex
Imports Ranorex.Core
Imports Ranorex.Core.Testing
Namespace Ras
Public Partial Class Login_Start
''' <summary>
''' This method gets called right after the recording has been started.
''' It can be used to execute recording specific initialization code.
''' </summary>
Private Sub Init()
' Your recording specific initialization code goes here.
End Sub
Sub KillProcess()
''Host.Local.KillApplication("RealtimeConnectionsClient")
Dim proc() as process = nothing
proc = Process.GetProcessesByName("RealtimeConnectionsSV2.exe")
For i As Integer = 0 To proc.Count - 1
proc(i).CloseMainWindow()
Next i
End Sub
Re: How can I kill a process with GetProcessesByName ?
Posted: Sat Oct 22, 2016 6:25 pm
by Aracknid
First, you still have ". Exe" in your string of the process name, which is wrong and leads to no matches found for proc, so proc = nothing, and that is the run time error. Remove ". Exe" and add a line of code to not do the if, if proc is nothing.
Aracknid
Re: How can I kill a process with GetProcessesByName ?
Posted: Sat Oct 22, 2016 9:37 pm
by rastek
Aracknid, my real problem was not 'not finding' because of exe but it was not even compiling..
Ok I just replaced .count with length and it compiled thanks.
My second question is, I have more than one exe to kill, can I add more exe to proc, since its an array ?
Re: How can I kill a process with GetProcessesByName ?
Posted: Mon Oct 24, 2016 2:34 pm
by Aracknid
I think at this point in time, it would be a good idea for you to read the online help available for handling or getting processes. You'll find a lot of useful functions and examples that should help you get through this.
https://msdn.microsoft.com/en-us/librar ... .110).aspx
Aracknid