Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTA script won't work if folder name contains a space

I'm looking for some help as to why my simple HTA application won't work if a folder in the file path has a space in its name.

My HTA has a simple button to launch a text file within a sub folder.

The HTA has a script which finds the root folder of the HTA file.

If the location of my HTA file is the path below the button works:

c:\Users\%MyUser%\Desktop\htatest2

If the folder name is changed to "hta test2" the button doesn't work.

c:\Users\%MyUser%\Desktop\hta test2

here is my code below.

<html>
<head>
    <title>Application Executer</title>
    <HTA:APPLICATION ID="oMyApp" 
        APPLICATIONNAME="Application Executer" 
        BORDER="no"
        CAPTION="no"
        SHOWINTASKBAR="yes"
        SINGLEINSTANCE="yes"
        SYSMENU="yes"
        SCROLL="no"
        WINDOWSTATE="normal">

        <script type="text/javascript" language="javascript">
            var shell = new ActiveXObject("WScript.Shell");
            var rootdir = shell.currentDirectory;

            function RunFile() {
                WshShell = new ActiveXObject("WScript.Shell");
                WshShell.Run(rootdir+"/txt/text.txt", 1, false);
            }
        </script>

</head>
<body>
    <input type="button" value="Run Notepad" onclick="RunFile();" class="button" />
</body>
</html>
like image 926
callum Avatar asked Dec 03 '25 15:12

callum


1 Answers

Run executes its first argument as it was written to command line. You've to include double quotes in the argument. Use single quotes for the concatenation to prevent conflicting quotes, like so:

WshShell.Run('"' + rootdir + '/txt/text.txt' + '"', 1, false);
like image 89
Teemu Avatar answered Dec 06 '25 04:12

Teemu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!