3

Im currently coding a program, but i need to make it execute a vbs file. TempDir.vbs. However, the directory to this file contains spaces. Unfortunally, all other topics dont work when the directory contains spaces. In my case: C:\\Users\\"the user"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup

the code im currently using is:

Runtime.getRuntime().exec("wscript.exe " + "\"\"\"" + path + "\"\"\"" + "TempDir.vbs");

So, how can i execute the file TempDir.vbs.

fabian
  • 80,457
  • 12
  • 86
  • 114
Br4m3000
  • 53
  • 1
  • 2
  • 6
  • Please provide the code by which you're attempting to execute the VBS from Java. As long as the path is properly quoted and/or escaped, there is no reason why this can't work. – ziesemer Oct 25 '15 at 19:05
  • I edited the post, hopefully it is better now. not reallu sure.... – Br4m3000 Oct 25 '15 at 19:10

1 Answers1

1

Instead of using Runtime.exec(String), use Runtime.exec(String[]):

Runtime.getRuntime().exec(new String[] {
    "wscript.exe",
    path + "TempDir.vbs"
});

As mentioned in a comment to a now deleted answer by ziesemer, if the .vbs file is a console script, you might need to use cscript.exe. See this for explanation: Difference between wscript and cscript

Community
  • 1
  • 1
Andreas
  • 154,647
  • 11
  • 152
  • 247