0

I found a small script on https://www.webdeveloper.com/d/49920-how-to-call-a-javascript-from-vbscript/5 that says you call simply call a VB script function in JavaScript. It also gave this example:

    <HTML>
<Head>
</head>
<Script Language=JavaScript>
function callVB(){

    setTimeout(function(){KeepAwake();}, 5000);

}   
</Script>
<Script Language=VBScript>
    Function KeepAwake()
    set WshShell = CreateObject("WScript.Shell")
            WshShell.SendKeys "{ENTER}"
    End Function
</Script>
<Body>
<input type=button value="Call VB" onclick="callVB()">
</Body>
</HTML>

It works great. After 5 seconds it presses enter. So I put it in my own code. The hta says that the VBS function is undefined despite the VBS code being the same. Error Message

I played around with it for a while but it still wouldn't work and all I could find the internet was the same thing I was doing.

What Am I doing wrong?

Here is my own code

<!DOCTYPE html>

<html>
<head>
<title>The Amazing Nanny Helper</title>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script>
</head>

<p id="retrunValue"></p>

<label for="myfile" id="label" name="label">Select a file:</label>
<input type="file" id="myfile" name="myfile" multiple>
<label for="Start">Start Row:</label>
<input type="number" id="Start" min="0"> 
<button type="button" onclick="do5();">Do 5</button>
<button type="button" onclick="do25();">Do 25</button>
<button type="button" onclick="do100();">Do 100</button>
<button type="button" onclick="do1000();">Do 1000</button>
<button type="button" onclick="do10000();">Do 10000</button>



     <Script Language=JavaScript>
//A bunch of unimportant functions

function do5() {
    FileInput(5);
}
function do25() {
    FileInput(25);
}
function do100() {
    FileInput(100);
}
function do1000() {
    FileInput(1000);
}
function do10000() {
    FileInput(10000);
}
function FileInput(times) {
KeepAwake(); // attempt to call VBS function

// Big loop driven by setTimeouts and functions calling functions that call the calling function
}
//A few more unimportant functions
     </Script>
<Script Language=VBScript>
    Function KeepAwake()
    set WshShell = CreateObject("WScript.Shell")
            WshShell.SendKeys "{ENTER}"
    End Function
</Script>

  </body>


</html>
  • Not reading help is what you are doing wrong. `var WshShell = WScript.CreateObject("WScript.Shell");` and `WshShell.SendKeys ("1{+}");` –  Jul 14 '20 at 22:00
  • Sure But the problem of the function not existing is still there. – Nick Knacks Jul 14 '20 at 22:38
  • You're missing the `` tag in your HTML in fact both examples are incorrect examples of HTML. The first sample should either have the ` – user692942 Jul 15 '20 at 09:39

1 Answers1

0

The problem is with this tag:

<meta http-equiv="x-ua-compatible" content="ie=edge" />

Here you state that the content should be run with the latest available IE engine. That choice apparently does not support VBScript. You can get support for VBScript with a value like:

<meta http-equiv="x-ua-compatible" content="ie=ie11" />
trincot
  • 317,000
  • 35
  • 244
  • 286
  • Ok, Now the script sources(the three at the top of the html) throw a bunch of errors at line 0 char 0 – Nick Knacks Jul 14 '20 at 22:28
  • I posted another question which turned out to be a duplicate of the one here: https://stackoverflow.com/questions/31086243/filereader-readasbinarystring-is-not-support-ie-10-11, if that solution is gone, than I am back to square one. – Nick Knacks Jul 14 '20 at 22:48
  • 1
    `content="ie=edge"` doesn't make mshta.exe to use Microsoft Edge, it just makes the app to use the latest IE version available. Check [this answer](https://stackoverflow.com/a/19570684/1169519) for more details. – Teemu Jul 15 '20 at 08:29
  • @teemu, corrected. Still, there must be something more to it, as there is no later version of IE than IE11, and VBScript is available with that setting, yet it is not with the "ie=edge" setting. – trincot Jul 15 '20 at 10:27
  • 1
    It's really hard to find any documentation of these deprecated features. I'd recall "IE11" was not a valid value for `X-UA content`, "edge" was used to use the latest available version, and other values (IE<11) to downgrade the app. Hence "IE11" would drop the app to Quirks mode, and VBScript is allowed again. However, I'd also recall, that running VBScript with file protocol or in HTA should work, it's only web environment, where it is obsoleted. Not my downvote, though. – Teemu Jul 15 '20 at 10:28
  • 1
    @Teemu yeah Microsoft seem to think that hiding VBScript, WScript and MSHTA references from search engines is the way to go. You have to really dig to find anything that resembles "official" documentation. From what I remember the last engine supported by `MSHTA.exe` was IE9. – user692942 Jul 15 '20 at 11:07
  • trincot I deleted it because it was my first question, and everyone hated it, also I didn't think I needed it again. – Nick Knacks Jul 15 '20 at 20:01
  • http://download.microsoft.com/download/winscript56/Install/5.6/W982KMeXP/EN-US/scrdoc56en.exe is VBScript and WScript documentation. HTAs https://learn.microsoft.com/en-us/previous-versions/ms536495%28v%3Dvs.85%29 –  Jul 15 '20 at 21:17