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>
3
  • Not reading help is what you are doing wrong. var WshShell = WScript.CreateObject("WScript.Shell"); and WshShell.SendKeys ("1{+}"); Commented Jul 14, 2020 at 22:00
  • Sure But the problem of the function not existing is still there. Commented Jul 14, 2020 at 22:38
  • You're missing the <body> tag in your HTML in fact both examples are incorrect examples of HTML. The first sample should either have the <script> tags inside the <body> or inside the <head> depending on how you want them to be loaded. Commented Jul 15, 2020 at 9:39

1 Answer 1

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" />
Sign up to request clarification or add additional context in comments.

8 Comments

Ok, Now the script sources(the three at the top of the html) throw a bunch of errors at line 0 char 0
I posted another question which turned out to be a duplicate of the one here: stackoverflow.com/questions/31086243/…, if that solution is gone, than I am back to square one.
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 for more details.
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 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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.