
{filelink=23}
public class RedemarrerPC
{
/*
* Le programme Redémarre le PC automatiquement
*/
public static void main (String[] args) throws Exception
{
String commande;
String operatingSystem = System.getProperty("os.name");
System.out.println(operatingSystem);
// Sous Windows
if (operatingSystem.startsWith("Windows"))
{
commande = "shutdown -r";
}
// Sous Linux
else if (operatingSystem.startsWith("Linux"))
{
commande = "reboot";
}
// Sous Mac
else if (operatingSystem.startsWith("Mac OS"))
{
commande = "shutdown -r now";
}
else
{
throw new RuntimeException("Impossible de redémarrer cet ordinateur");
return;
}
Runtime.getRuntime().exec(commande);
System.exit(0);
}
}