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
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..
Try
Runtime.getRuntime().exec("shutdown -s");
Edited part:
Use this.
shutdown /s /m <Computer_Name>
To shutdown a remote PC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.