Here is a simple Example to start and stop windows process using Java Program
To start a process we get a RunTime object through Runtime class method getRuntime().Now we invoke the exec() method through this object that returns an object of started process.
This object can be used to stop the process by calling destroy() method of it.
import java.io.IOException; public class StartAndStopProcess{ public static void main(String[] args) throws IOException, InterruptedException { Runtime run = Runtime.getRuntime(); //start process Process pro = run.exec("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); Thread.sleep(5000); //stop process pro.destroy(); }
}
Nice article!!!
ReplyDeleteThanks.