-
How to create a schedule task
Hi all.. i need help and its very urgent
Actually, i want to develop an application that can run "shctasks" under WinXP. I already develop it but there is a problem that the task will show as running but nothing happens. If I don’t end the task it continues to show status of running until the default 72 hours expires. If I open up Task Manager, click on Process tab, I can see the job (what the schedule task is suppose to run) is running but its showing CPU usage as zero. Here i paste my full source code, please help me, thanks.
code: application_lock.java
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class application_lock extends JFrame implements ActionListener
{
JLabel lb1;
JLabel lb2;
JPasswordField tx1;
JComboBox tx2;
JButton b1;
JButton b2;
JButton b3;
char c='"';
application_lock()
{
super("Neural Application Lock Configuration Tool");
//getContentPane().setBackground(Color.white);
getContentPane().setLayout(null);
setLocation(200,100);
setVisible(true);
setSize(500,200);
setResizable(false);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
}
});
lb1=new JLabel("Enter Your Windows Account Password");
lb1.setForeground(Color.black);
lb1.setBounds(20,30,250,30);
getContentPane().add(lb1);
tx1=new JPasswordField(20);
//tx1.setEchoChar('*');
tx1.setForeground(Color.black);
tx1.setBackground(Color.lightGray);
tx1.setBounds(270,35,150,20);
getContentPane().add(tx1);
lb2=new JLabel("Select Idle Time (max 999 minutes)");
lb2.setForeground(Color.black);
lb2.setBounds(50,70,250,30);
getContentPane().add(lb2);
tx2=new JComboBox();
for(int k=1;k<=999;k++)
{
String text=String.valueOf(k);
tx2.addItem(text);
}
tx2.setForeground(Color.black);
tx2.setBackground(Color.lightGray);
tx2.setBounds(270,75,150,20);
getContentPane().add(tx2);
b1=new JButton("Activate");
b1.setBackground(Color.red);
b1.setForeground(Color.white);
b1.setBounds(30,120,150,20);
getContentPane().add(b1);
b1.addActionListener(this);
b2=new JButton("Deactivate");
b2.setForeground(Color.black);
b2.setBackground(Color.gray);
b2.setBounds(200,120,150,20);
getContentPane().add(b2);
b2.addActionListener(this);
b3=new JButton("Exit");
b3.setBackground(Color.lightGray);
b3.setForeground(Color.gray);
b3.setBounds(370,120,80,20);
getContentPane().add(b3);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String ac=e.getActionCommand();
if (ac.equals("Activate"))
{
String pw=tx1.getText();
String idle=String.valueOf(tx2.getSelectedItem());
//System.out.println(pw+" "+idle);
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cmd /c schtasks /Delete /tn "+c+"%username%"+c+" /f");
proc.waitFor();
}
catch(Exception et){}
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cmd /c schtasks /Create /ru "+c+"%username%"+c+" /rp "+c+pw+c+" /sc ONIDLE /i "+idle+" /tn "+c+"%username%"+c+" /tr "+c+"C:/Neural_Entrypad/Neural_Entrypad_Application_Lock.bat"+c);
proc.waitFor();
}
catch(Exception et){}
tx1.setText("");
tx2.setSelectedIndex(0);
JOptionPane.showMessageDialog(this,"Neural Entrypad Application Lock Activated","Neural Entrypad Application Lock Tool", JOptionPane.INFORMATION_MESSAGE);
}
if (ac.equals("Deactivate"))
{
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cmd /c schtasks /Delete /tn "+c+"%username%"+c+" /f");
proc.waitFor();
}
catch(Exception et){}
JOptionPane.showMessageDialog(this,"Neural Entrypad Application Lock Deactivated","Neural Entrypad Application Lock Tool", JOptionPane.INFORMATION_MESSAGE);
}
if (ac.equals("Exit"))
{
System.exit(1);
}
}
public static void main(String[] args)
{
new application_lock().show(true);
}
}
Similar Threads
-
Replies: 17
Last Post: 04-04-2003, 04:55 PM
-
By Ken in forum VB Classic
Replies: 3
Last Post: 09-24-2002, 06:03 AM
-
By John Lee in forum Enterprise
Replies: 0
Last Post: 07-24-2002, 07:51 PM
-
By Scott in forum ASP.NET
Replies: 1
Last Post: 08-30-2001, 02:39 AM
-
By Sherlyn in forum Database
Replies: 3
Last Post: 05-11-2001, 06:04 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks