How to open a pdf with WScript.Shell

落爺英雄遲暮 提交于 2019-12-05 08:00:48

问题


I'm creating a HTA application that needs to open PDF document. I cannot assum that the user will have acrobat installed on his PC as in this example

The WScript (documentation) allow you to run a command line application. But what I would like, is for the WScript to simulate a double click on the file.

I would like to be able to do something like

var wshShell = new ActiveXObject("WScript.Shell");
wshShell.Exec(pdfFilePath); // That does not work

回答1:


In cmd, you can open a file like this: start c:\path\to\file.pdf

Maybe this works

wshShell.Exec("start " & pdfFilePath); //do you do string concat like this in wscript?



回答2:


If pdfFile contains space, you must be add " and " into start and end of pdfFilePath Change to: wshShell.Run('cmd /C start '+ '\"' + pdfFile + '\"' ,1,false)




回答3:


The way to do this is:

new ActiveXObject("WScript.Shell").Run(pdfFile,1,false);


来源:https://stackoverflow.com/questions/7027698/how-to-open-a-pdf-with-wscript-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!