Search code examples
filenameshta

VbScript hta - Open a new hta by link and retrieve correct filename


I have two files; "1.hta" and "2.hta".

"1.hta" contains a simple link to file "2.hta"

<a href="2.hta">2.hta</a>

"2.hta" contains a script to determine its own filename

FullName = replace(oApp.commandLine,chr(34),"")  'oApp = HT Application ID
arrFN=split(FullName,"\")  
FileName = arrFN(ubound(arrFN))  
SourceDir=replace(FullName,FileName,"")

"2.hta" works perfectly when started "stand-alone" --> FileName = 2.hta

However, starting "2.hta" via link from "1.hta" I get --> FileName = 1.hta

I need a way to determine the correct filename, or does hta always retrieve the filename of the first/starting instance?


Solution

  • You can try like this :

    <html>
    <head>
    <title>HTA Launch another HTA</title>
    <HTA:APPLICATION
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
    >
    </head>
    <SCRIPT Language="vbscript">
    Sub Execute(File)
     Dim ws
     Set ws = CreateObject("wscript.shell")
     ws.run chr(34) & File & chr(34)
    End sub
    </SCRIPT>
    <body>
    <h1>This is test hta 1 ONE</h1>
    <a href="#" onClick="Call Execute('2.hta')">Start the HTA2</a>
    </body>
    </html>