vb.net - Open and Close App with VB .NET -


i have 1 project in vb.net , project have function open , close program calculator. have opened calc.exe code this:

private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click     shell("c:\windows\system32\calc.exe") end sub 

but when try create function close program dont't know how write code. function useful closing programs have been opened button1.

anyone can me make function close program?

instead of shell can use process

dim p process = process.start("c:\windows\system32\calc.exe")  threading.thread.sleep(10000)  ' terminate after 10 seconds p.kill() 

if need trigger killing process somewhere needs access process handle p.

or if want kill old process have not started need process.getprocessesbyname() give array of process can lop through , kill relevant one.

here example

   dim myprocesses() process     dim myprocess process      myprocesses = process.getprocessesbyname("nameofprocessasstring")      try          if myprocesses.length > 0             each myprocess in myprocesses                 if myprocess isnot nothing                     myprocess.kill()                 end if              next         end if     catch ex exception           message.show(ex.message)     end try 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -