Reputation: 3433
we have a java application, which is running as windows service. Actually we need to call a batch file to start windows 'calculator' application. But we can't. If we start java application not as a windows service, it is working fine. I have read a post about the same on Calling a batch file from a windows service and done the below configuration.
"first install the service with giving appropriate path to the batch file or exe file then go to run->services.msc->right click on the service ->properties->logon->check enable service to interact with desktop-make it enable "
After that we got a partial success, as it first prompts a permission window as below:
Upvotes: 0
Views: 2960
Reputation: 918
May I suggest that instead of opening a batch file, you just open the calc.exe file instead?
Runtime.getRuntime().exec("c:\\windows\\System32\\calc.exe", null, new File("c:\\windows\\System32\\calc.exe"));
EDIT: If you still want to run it as a batch file, use this:
Runtime.getRuntime().exec("cmd /c start nameOfTheBatchFile.bat");
Please note that the second variable in the exec method is to set up the directory that you want to be calling the program from.
Upvotes: 1