Foros aprenderaprogramar.com

Aprender a programar => C, C++, C#, Java, Visual Basic, HTML, PHP, CSS, Javascript, Ajax, Joomla, MySql y más => Mensaje iniciado por: apcs919 en 03 de Marzo 2015, 01:44

Título: apagador remoto para el pc en java (apagar mediante código el ordenador)
Publicado por: apcs919 en 03 de Marzo 2015, 01:44
hola alguien que sepa apagar una pc remotamente mediante un código en java

enrecio se los agradecería   :) :)
Título: Re:apagador remoto para el pc en java (apagar mediante código el ordenador)
Publicado por: Alex Rodríguez en 03 de Marzo 2015, 11:07
Hola puedes probar esto en Windows:

Código: [Seleccionar]
public static void main(String arg[]) throws IOException{
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("shutdown -s -t 0");
System.exit(0);
}

O esto en otros sistemas operativos:

Código: [Seleccionar]
public static void shutdown() throws RuntimeException, IOException {
    String shutdownCommand;
    String operatingSystem = System.getProperty("os.name");

    if ("Linux".equals(operatingSystem) || "Mac OS X".equals(operatingSystem)) {
        shutdownCommand = "shutdown -h now";
    }
    else if ("Windows".equals(operatingSystem)) {
        shutdownCommand = "shutdown.exe -s -t 0";
    }
    else {
        throw new RuntimeException("Unsupported operating system.");
    }

    Runtime.getRuntime().exec(shutdownCommand);
    System.exit(0);
}

Saludos