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
Try
Runtime.getRuntime().exec("shutdown -s");
Edited part:
Use this.
shutdown /s /m <Computer_Name>
To shutdown a remote PC
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