Shutdown Remote Computer in Java- Cannot initiate shutdown but no errors

浪子不回头ぞ 提交于 2019-12-08 01:46:39

问题


I am learning about the Runtime class in java, and am testing the use of command line instructions in it. I am trying to remotely shutdown a computer using Runtime.getRuntime().exec(...); When I run this, there are no errors, but the specified machine does not shut down. I don't know why.

Code:

import java.io.IOException;

class shutdownVirus {
    public static void main(String[] args) throws IOException {
        Runtime.getRuntime().exec("shutdown -m \\\\T12-LEOPARDIJ -s -t 10");
    }
}

Any help will be greatly appreciated. Thanks


回答1:


Try

Runtime.getRuntime().exec("shutdown -s");

Edited part:

Use this.

shutdown /s /m <Computer_Name> To shutdown a remote PC




回答2:


It probably does not work because the VM you are running the Java class with is started from a user that does not have shutdown rights. The process would inherit these access restrictions and therefore no be allowed to shut down.

Arguably thats a good thing..



来源:https://stackoverflow.com/questions/11183441/shutdown-remote-computer-in-java-cannot-initiate-shutdown-but-no-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!