How do you force a computer shut-down in Java?

I was just wondering if there was a way to force a computer to shut down using a command line in javascript, and if you could tell me it, so I can add it onto the end of a doccument (for a prank).

Thanks in advance,
George

Comments

  • : I was just wondering if there was a way to force a computer to shut
    : down using a command line in javascript, and if you could tell me
    : it, so I can add it onto the end of a doccument (for a prank).
    :
    : Thanks in advance,
    : George
    :
    The following class has a number of shutdown methods for the various windows versions and linux:
    [code]
    public class Shutdown {

    private Shutdown() { }

    private static void runCommand(String file, String params) {
    ParamArray pa = params.split(" ");
    Runtime.exec(file, pa);
    }

    public static void shutdownWinpreXP() {
    runCommand("RUNDLL32.EXE", "user32,ExitWindowsEx");
    }

    public static void shutdownWinXP() {
    runCommand("shutdown.exe", "-s -t 01");
    }

    public static void shutdownWindows() {
    try {
    shutdownWinXP();
    catch (IOException e) {
    shutdownWinpreXP();
    }
    }

    public static void shutdownLinux() {
    runCommand("shutdown", "now");
    }

    }
    [/code]
    This code hasn't been tested. I don't know the command to shutdown a Mac or other platforms.
    The usage is quite straight forward:
    [code]
    Shutdown.shutdown[OSName]();
    [/code]
    where [OSName] is the OS to shutdown.

    And always remember: (Java != Javascript);
  • : : I was just wondering if there was a way to force a computer to shut
    : : down using a command line in javascript, and if you could tell me
    : : it, so I can add it onto the end of a doccument (for a prank).
    : :
    : : Thanks in advance,
    : : George
    : :
    : The following class has a number of shutdown methods for the various
    : windows versions and linux:
    : [code]:
    : public class Shutdown {
    :
    : private Shutdown() { }
    :
    : private static void runCommand(String file, String params) {
    : ParamArray pa = params.split(" ");
    : Runtime.exec(file, pa);
    : }
    :
    : public static void shutdownWinpreXP() {
    : runCommand("RUNDLL32.EXE", "user32,ExitWindowsEx");
    : }
    :
    : public static void shutdownWinXP() {
    : runCommand("shutdown.exe", "-s -t 01");
    : }
    :
    : public static void shutdownWindows() {
    : try {
    : shutdownWinXP();
    : catch (IOException e) {
    : shutdownWinpreXP();
    : }
    : }
    :
    : public static void shutdownLinux() {
    : runCommand("shutdown", "now");
    : }
    :
    : }
    : [/code]:
    : This code hasn't been tested. I don't know the command to shutdown a
    : Mac or other platforms.
    : The usage is quite straight forward:
    : [code]:
    : Shutdown.shutdown[OSName]();
    : [/code]:
    : where [OSName] is the OS to shutdown.
    :
    : And always remember: (Java != Javascript);


    Thanks a lot, but I'm a bit unsure as to which bit to copy and paste into my webpage to get an automatic shutdown for Windows XP.

    Thanks again,
    George.
  • : : : I was just wondering if there was a way to force a computer to shut
    : : : down using a command line in javascript, and if you could tell me
    : : : it, so I can add it onto the end of a doccument (for a prank).
    : : :
    : : : Thanks in advance,
    : : : George
    : : :
    : : The following class has a number of shutdown methods for the various
    : : windows versions and linux:
    : : [code]: :
    : : public class Shutdown {
    : :
    : : private Shutdown() { }
    : :
    : : private static void runCommand(String file, String params) {
    : : ParamArray pa = params.split(" ");
    : : Runtime.exec(file, pa);
    : : }
    : :
    : : public static void shutdownWinpreXP() {
    : : runCommand("RUNDLL32.EXE", "user32,ExitWindowsEx");
    : : }
    : :
    : : public static void shutdownWinXP() {
    : : runCommand("shutdown.exe", "-s -t 01");
    : : }
    : :
    : : public static void shutdownWindows() {
    : : try {
    : : shutdownWinXP();
    : : catch (IOException e) {
    : : shutdownWinpreXP();
    : : }
    : : }
    : :
    : : public static void shutdownLinux() {
    : : runCommand("shutdown", "now");
    : : }
    : :
    : : }
    : : [/code]: :
    : : This code hasn't been tested. I don't know the command to shutdown a
    : : Mac or other platforms.
    : : The usage is quite straight forward:
    : : [code]: :
    : : Shutdown.shutdown[OSName]();
    : : [/code]: :
    : : where [OSName] is the OS to shutdown.
    : :
    : : And always remember: (Java != Javascript);
    :
    :
    : Thanks a lot, but I'm a bit unsure as to which bit to copy and paste
    : into my webpage to get an automatic shutdown for Windows XP.
    :
    : Thanks again,
    : George.
    :
    You can use the entire class and then call either the shutdownWinXP() or the shutdownWindows() method.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion