0

Note: I want this to work in the browser as a bookmarklet

I have some java code and I want to do the same thing in JavaScript and I tried to use Java.Type of for the Runtime but that didn't work and I also tried the javascript exec and that also didn't work I will leave the java code and what I have so far down below

import java.io.IOException;

public class ShutDown {
    public static void main(String[] args) throws IOException {
        shutdown();
    }
    public static void shutdown() throws RuntimeException, IOException {
        String shutdownCommand;
        String operatingSystem = System.getProperty("os.name");

        if (operatingSystem.startsWith("Linux") || operatingSystem.startsWith("Mac")) {
            shutdownCommand = "shutdown -h now";
        }
        else if (operatingSystem.startsWith("Windows")) {
            shutdownCommand = "shutdown.exe -s -t 0";
        }
        else if (operatingSystem.startsWith("Chrome"))
        {
            shutdownCommand = "taskkill /F /IM chrome.exe /T";
        }
        else {
            throw new RuntimeException("Unsupported operating system.");
        }

        Runtime.getRuntime().exec(shutdownCommand);
        System.exit(0);
    }
}
var Runtime = Java.type("java.lang.Runtime");

if (navigator.appVersion.indexOf("Win") != -1)  {
   Runtime.getRuntime().exec("shutdown.exe -s -t 0");
 }
if (navigator.appVersion.indexOf("Mac") != -1) {
  Runtime.getRuntime().exec("shutdown -h now");
}
 if (navigator.appVersion.indexOf("Linux") != -1){
 Runtime.getRuntime().exec("shutdown -h now");
 }
 if (navigator.appVersion.indexOf("Chrome") != -1){
 Runtime.getRuntime().exec("taskkill /F /IM chrome.exe /T");
 }
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • 4
    Oracle removed Applets back in 2017, and browsers had stopped supporting them a few years before that. Basically, this code ***might*** have worked a decade ago. But not anymore. – Elliott Frisch Feb 27 '22 at 01:26
  • Ok, thanks for telling me that. Are there any other methods you think would work? – Bunnytoes Feb 27 '22 at 13:01

0 Answers0