In my java application I use
Runtime.getRuntime().exec("taskkill /F /IM " + explorer.exe).waitFor();
to close Windows Explorer. This part works because Explorer realy stops working for me.
Unfortunately, when I use
Runtime.getRuntime().exec("explorer.exe");
Windows Explorer doesn't restart at all. How should I restart it properly?
I don't know the reason why that is not working for you, since you are executing an external program from java, I think it is not Java's fault that it is not restarting, maybe there is something wrong in the way you restart. I will give you an alternative:
Instead of using Runtime.exec()
, try ProcessBuilder.start()
for starting the process and
use the method destroy()
from the class Process
to kill the process.
It should work ok, just use the builder to create an object that represent explorer and assign it to a variable of type Process
.
The only reason I think maybe it is easier if you use the ProcessBuilder is because it takes arguments as separate Strings, and maybe that makes it easier to configurate your scripts.
Example:
List<String> params = java.util.Arrays.asList("C:\myProgram.exe", "-arg1", "-arg2");
ProcessBuilder pb = new ProcessBuilder(params);
Process process = pb.start();
Give it a try I think it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With