2

I need to create a launcher for an autorun CD that creates buttons that opens files(pdfs, videos etc.) from on the CD using VBScript.

I have in the .HTA the following code

shell = new ActiveXObject("WScript.Shell").Run('My eBooks\Triniscene Link Me Campaign.pdf',1,false);

and the button is

<a href="javascript:void(0)" id="link_id">pdf 1</a>

However on clicking the link Internet Explorer opens instead of the file( it doesn't event show the pdf)

I want to be able to trigger the opening of the file with whatever the default application the system has

Kendall
  • 5,065
  • 10
  • 45
  • 70
  • You seem to have JavaScript code only. In JS you need to escape backslashes like so: `\\\`, and include doublequotes when the path contain spaces. You need also to make sure, that the working directory is correctly set when using a relative path. Just on curiosity, what is the address of the page opened by IE? – Teemu Jan 08 '15 at 15:51
  • @Teemu the address opened was "javascript:void(0)". I was doing some research and was wondering if HTA is compatible with windows 8...? – Kendall Jan 08 '15 at 20:37
  • the opened page was "blank". Just out of curiosity is HTA file compatible with IE10 and 11? – Kendall Jan 08 '15 at 20:38
  • You can [run HTA with IE10 - 11](http://stackoverflow.com/a/19570684/1169519), though it is deprecated since IE10. Some of the actual HTA properties are not working in those browsers (the attributes in `HTA:APPLICATION` tag). – Teemu Jan 09 '15 at 05:11
  • Hmmmmm...thanks I thinking i should just go back to Flash for this one – Kendall Jan 09 '15 at 14:21

1 Answers1

2

Try this HTA with Vbscript :

<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="Run Some Files"
BORDER="THIN"
BORDERSTYLE="NORMAL"
ICON="Explorer.exe"
INNERBORDER="NO"
MAXIMIZEBUTTON="NO"
MINIMIZEBUTTON="NO"
SCROLL="NO"
SELECTION="NO"
SINGLEINSTANCE="YES"/>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<title>Run Some Files</title>
<SCRIPT LANGUAGE="VBScript">
'************************************************************************************
Option Explicit
Sub window_onload()
    CenterWindow 400,360
End Sub
'************************************************************************************
Sub CenterWindow(x,y)
    Dim iLeft,itop
    window.resizeTo x,y
    iLeft = window.screen.availWidth/2 - x/2
    itop = window.screen.availHeight/2 - y/2
    window.moveTo ileft,itop
End Sub
'************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'************************************************************************************
Sub Run(MyFile)
    Dim ws,return
    Set ws = CreateObject("wscript.Shell")
    On Error Resume Next
    return = ws.run(DblQuote(MyFile),False)
    If Err <> 0 Then
        MsgBox "An unknown error occurred",VbCritical,"An unknown error occurred"
    End If
End Sub
'************************************************************************************
</script>
</head>
<BODY text=white bgcolor="DarkOrange" TOPMARGIN="1" LEFTMARGIN="1">
<p>In Links List :</p>
<ol>
<li><a href="#" onClick="Call Run('My eBooks\Triniscene Link Me Campaign.pdf')"> Triniscene Link Me Campaign 1</a></li>
<br><br>
<li><a href="#" onClick="Call Run('My eBooks\MyPDF File 2.pdf')"> Triniscene Link Me Campaign 2</a></li>
</ol>
<p>In Buttons List :</p>
<center><button onclick="Call Run('My eBooks\Triniscene Link Me Campaign.pdf')"> Triniscene Link Me Campaign 1</button>
<br><br>
<center><button onclick="Call Run('My eBooks\MyPDF File 2.pdf')"> Triniscene Link Me Campaign 2</button>
</body>
</html>
Hackoo
  • 18,337
  • 3
  • 40
  • 70