
{filelink=23}
public class EteindrePC
{
/*
* Le programme éteint 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.exe -s -t 0";
}
// Sous Linux ou Mac
else if (operatingSystem.startsWith("Linux") || operatingSystem.startsWith("Mac OS X"))
{
commande = "shutdown -h now";
}
else
{
throw new RuntimeException("Impossible d'éteindre ce PC");
}
Runtime.getRuntime().exec(commande);
System.exit(0);
}
}