-1

I want to make a simple update application in vb.net,but,it cant update the file,cause the file is running.So,i want to find all processes called "seemta helper(this is how Task m. show it's name)"and,if,a process is running with that name,indicating to the user with a msgbox that the process is running,and,when the user press the OK button,then killing the process.

P.S. Sorry for bad english. :(

  • Welcome to StackOverflow! What have you tried so far and where did you get stuck? Your question is a little too broad as it asks for a complete solution and not only a _single_ problem. Start with [`Process.GetProcessesByName()`](https://msdn.microsoft.com/en-us/library/z3w4xdc9(v=vs.110).aspx) and come back if you have a _specific_ problem implementing your solution. – René Vogt Aug 30 '16 at 09:12
  • Yea,i have,i dont know how to use Process.GetProcessByName,in an IF statement.so this is where i stuck currently. – Ntohing_Trolll Aug 30 '16 at 09:17
  • So,if a process is running with the name "seemta helper"then it need to be indicated to user,and,when the user press the OK button in the msgbox,then killing the process. – Ntohing_Trolll Aug 30 '16 at 09:24

2 Answers2

1

Try this:

Dim Processes() As Process = Process.GetProcessesByName("seemta helper")

For Each process As Process In Processes
     process.Kill()
Next

You may need administrator elevation to kill a process

theBugger
  • 441
  • 3
  • 14
1

You can do this like this:

For Each p As Process In Process.GetProcessesByName("seemta helper")
    If MessageBox.Show("Kill " + p.ProcessName + "(" + p.Id + ")?", "Kill", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
        p.Kill()
    End If
Next

GetProcessesByName() returns an array of running Process instances with the specified name.

Then you show a message box to ask the user if the process should be killed and if Yes is clicked, you call Kill() on that process's instance.

René Vogt
  • 43,056
  • 14
  • 77
  • 99
  • Just a question,how can i implement code like you did? – Ntohing_Trolll Aug 30 '16 at 09:37
  • @Ntohing_Trolll Sorry, I don't understand that question. You mean, how to copy and paste? It sounds like you rather need some basic vb tutorials before asking on SO. – René Vogt Aug 30 '16 at 09:41
  • It throw's me an erorr: Conversion from string "Kill" to type 'Integer' is not valid. – Ntohing_Trolll Aug 30 '16 at 09:47
  • No,i mean,how can i paste the code like you,i know how to paste,and copy :D – Ntohing_Trolll Aug 30 '16 at 09:48
  • You mean the formating on StackOverlow? Simply add four spaces at the beginning of the line. – René Vogt Aug 30 '16 at 09:50
  • `It work :D` Thumbs up for you :D Thanks for your help ;D – Ntohing_Trolll Aug 30 '16 at 09:51
  • Yes, that's for inline code formating. But for code blocks you add 4 spaces at the beginning of the line (google for markdown syntax). – René Vogt Aug 30 '16 at 09:53
  • I will,thanks a lot,but,just a question,what if multiple processes are running with the same name? – Ntohing_Trolll Aug 30 '16 at 09:54
  • The code I show opens a message box _for each_ process found with that name (and kills it if yes is clicked). You may consider to ask only once and kill all or add a cancel button and break the loop if the user wants to cancel. – René Vogt Aug 30 '16 at 09:57
  • Just a question,what if there are no process with that name?The msgbox will not open? – Ntohing_Trolll Aug 30 '16 at 12:42
  • Correct, since the _For Each_ loop is not entered if there's no element in the returned array. – René Vogt Aug 30 '16 at 12:43
  • I got a little problem,and the probelm is:I want to use your code,to stop the user,to start multiple times the application,but,the application wont start because,it detects itself as the application. – Ntohing_Trolll Aug 30 '16 at 14:15
  • So,i need some source of code,stop the user to open the application multiple times called "seemta helper". – Ntohing_Trolll Aug 30 '16 at 14:18
  • @Ntohing_Trolll This is a completely different topic and you should ask a new question for that. But please use google first as there are a lot of resources about that on the web. And note that SO is not a free coding service, you'll have to show at least some research effort and the code you have tried so far. – René Vogt Aug 30 '16 at 14:21