Using Java to control the operation of an application (take NetEase cloud Music as an example), the steps are as follows
1, the establishment of BAT file is Start.bat (control program Operation) and Kill.bat (control program end);
The Start.bat content is as follows, the function is to run the Program:
cmd/c start f:\\00 NetEase Cloud Music \\CloudMusic\\cloudmusic.exeexit
Depending on the situation, you can rewrite the installation path for your Application.
The Kill.bat content is as follows, the function is to end the program Process:
Taskkill/f/im "cloudmusic.exe" exit
Note: two files to be in the same directory as the Application's directory
2. Find the installation directory of NetEase cloud or other application my is F:\00 NetEase cloud music \cloudmusic\;
3, Write Java code Control application operation such as (let the application run, run a period of time after a sudden end, a while good, so repeated) the program start time and end time interval to small, is not a spoof of the small program, so that your small partner is very vexed ah, listen to the song when the Break. La La la
4, attach the code, the key parts have Notes.
Package Haowan;import Java.io.ioexception;import Java.util.timer;import Java.util.timertask;public class Haowan { public void Runbat (string Batname) {//start netease cloud music String cmd = "cmd/c start f:\\00 netease Cloud Music \\CloudMusic\\" + Batname + ". bat";//netease Music installation directory E:/wyyyy/cloudmusic/try {Process PS = runtime.getruntime (). exec (cmd); Ps.waitfor (); } catch (ioexception Ioe) {ioe.printstacktrace (); } catch (interruptedexception E) {e.printstacktrace (); } System.out.println ("open NetEase cloud music"); } public void Shutbat (string Batname) {//turn off NetEase cloud music String cmd = "cmd/c start f:\\00 netease Cloud Music \\CloudMus ic\\ "+ batname +". bat ";//netease Music installation directory E:/wyyyy/cloudmusic/try {Process PS = runtime.getruntime (). E Xec (cmd); Ps.waitfor (); } catch (ioexception Ioe) {ioe.printstacktrace (); } catch (interruptedexception E) { E.printstacktrace (); } System.out.println ("turn off NetEase Cloud music"); } public static void main (string[] Args) {timer timer = new Timer ();//time controller timer.schedule (new timertask () { public void Run () {haowan Haowan = new Haowan (); Haowan.runbat ("start"); }}, 3000, 300000);//3 Second start running NetEase cloud music every 5 minutes seconds to restart the timer timer2 = new Timer ();//time Controller Timer.schedule (new timertask () { public void Run () {haowan Haowan = new Haowan (); Haowan.runbat ("kill"); }}, 295000, 300000);//4 minutes 55 seconds off run NetEase cloud music closed every 5 minutes}}
A Java spoof applet