Killing processes in vb.net -


what trying kill common processes. ex: chrome, firefox etc.

what looking forward : ' kill processes except [needed ones ' ". want replace bit of code here.

 private sub button1_click(sender object, e eventargs) handles button1.click     button1.enabled = false     label3.forecolor = color.green     timer1.start()      if progressbar1.value = 100         messagebox.show("done", "kill successfull")     end if  end sub   private sub button2_click(sender object, e eventargs) handles button2.click     button1.enabled = true     label3.forecolor = color.red     timer2.stop()     progressbar1.value = 0 end sub  private sub timer1_tick(sender object, e eventargs) handles timer1.tick     each prog process in process.getprocesses         timer2.start()         progressbar1.increment(30)         if prog.processname = "chrome"             prog.kill()         end if         if prog.processname = "notepad"             prog.kill()         end if         if prog.processname = "firefox"             prog.kill()         end if         if prog.processname = "codeblocks"             prog.kill()         end if         if prog.processname = "cmd"             prog.kill()         end if         if prog.processname = "photoshopcs6"             prog.kill()         end if         if prog.processname = "utorrent"             prog.kill()         end if         if prog.processname = "ccleaner"             prog.kill()         end if         if prog.processname = "notepad++"             prog.kill()         end if         if prog.processname = "lightshot"             prog.kill()         end if         if prog.processname = "ccleaner"             prog.kill()         end if     next end sub 

i think better approach killing process don't need. reason being there many processes needed if kill them accident, potentially result in crash.

try maintaining list of programs typically have open , process names be, change code iterate through array. later, can add controls program allow make changes array later. makes easier read code in future if need add programs want kill.

dim lstoprograms string() = {      "chrome",      "notepad",      "firefox",      "codeblocks"} '' etc. until have program names each prog process in process.getprocesses         timer2.start()         progressbar1.increment(30)         each nm string in lstoprograms            if prog.processname = nm                prog.kill()                exit            end if         next next 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -