How to open a pdf with WScript.Shell

2019-04-02 17:34发布

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

3条回答
时光不老,我们不散
2楼-- · 2019-04-02 18:17

The way to do this is:

new ActiveXObject("WScript.Shell").Run(pdfFile,1,false);
查看更多
仙女界的扛把子
3楼-- · 2019-04-02 18:18

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?
查看更多
三岁会撩人
4楼-- · 2019-04-02 18:22

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)

查看更多
登录 后发表回答