Using a WScript.shell activeX to execute a command line

According to the following:

http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29.aspx

You should be able to pass the commands directly as part of the strCommand param, you’d probably be better off getting rid of the extra quotes wrapping the entire command and arguments:

function callShellApplication(){
  var objShell = new ActiveXObject("WScript.shell");
  objShell.run('c:\wkhtmltopdf.exe c:\PDFTestPage.html c:\TEST.pdf');
}

Also you should be able to handle spaces in paths by wrapping each item in quotes, like so:

function callShellApplication(){
  var objShell = new ActiveXObject("WScript.shell");
  objShell.run('"C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe" "c:\PDFTestPage.html" "c:\TEST.pdf"');
}

You should also keep in mind whether you want to bWaitOnReturn or not, and which intWindowStyle you need (some executables may benefit from a particular style).

Also just as a cautionary note — it’s been a while since I’ve used WScript.shell — but you may need to escape your backslashes in your paths. So a path may need to look like the following:

objShell.run('"C:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe"');

Leave a Comment