Does anyone know why these two statements result in the shown exception?
Runtime.getRuntime().exec("assoc .vlan=\"file type description\"");
Runtime.getRuntime().exec("ftype \"file type description\"=" + System.getProperty("user.home")+ "\\folder 1\\folder 2\\my executable.exe\" /inject \"%1\"");
And Here's the Exception.
java.io.IOException: Cannot run program "assoc": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
All right, I've changed this but still the association is not made whereas the very same command is executable and working under the cmd command prompt.
Runtime.getRuntime().exec("cmd.exe /c assoc .vlan=\"file type description\"");
Runtime.getRuntime().exec("cmd.exe /c ftype \"file type description\"=\"" + System.getProperty("user.home") + "\\folder 1\\folder 2\\my executable.exe\" /inject \"%1\"");
Any complementary suggestion? Thank you!
As it turns out, assoc
and ftype
are built-in shell commands and NOT executable files. The same is true for copy
, dir
, etc. What you can do instead is launch cmd.exe
using the /c
parameter to pass a command line string, e.g. cmd.exe /c assoc ...
.
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