Can I initialize objects written in JScript from VBScript?

2024/2/27 8:50:59

I am trying to write a WSH logon script. Administrators throughout the company need to be able to customize the execution of the script, and execute additional scripts, for specific locations and users. In order to make their jobs easier, I would like to provide an API that the administrators can access in their scripts. If I write my API using JScript, would it be possible to initialize the objects I define through VBScript? For example, consider the following code:

<!-- The WSF logon script file -->
<package><job><script language="JScript">// A demonstration functionfunction OverNineThousand() {return 9001;}// A demonstration "class"function WorkstationClass() {var os = "Windows XP";this.getOperatingSystem = function() {return os;}}</script><script language="VBScript">Dim bigNumber, workstation'// This assignment works properly.bigNumber = OverNineThousand() '// This assignment causes an error. Am I doing it wrong?Set workstation = New WorkstationClass()'// Execution never gets this farWScript.Echo workstation.getOperatingSystem()</script></job>
</package>

Is there any way to accomplish what I'm trying to do?

Answer

VBScript and JScript seem to disagree on how to initialize an object. However, once the object has been initialized it is recognized by both languages. To get around this I had to create the object in JScript and then return it to the VBScript caller, as demonstrated below.

<package><job><script language="JScript">// A demonstration "class"function WorkstationClass() {var os = "Windows XP";this.getOperatingSystem = function() {return os;}}function CreateWorkstation() {return new WorkstationClass();}</script><script language="VBScript">Dim workstation'// This assignment causes an error.'// Set workstation = New WorkstationClass()'// This works!Set workstation = CreateWorkstation()'// Prints "Windows XP"WScript.Echo workstation.getOperatingSystem()</script></job>
</package>
http://en.ppmy.cn/q/41536.html

Related Q&A

Detect real screen resolution (ignoring browser zoom etc.)

I need to get the real screen resolution using JavaScript (client-side at least), but having issues with both IE and Firefox as they tend to change this when you use the browsers built-in zoom.How can …

Change CSS Link Property onClick with Javascript/JQuery?

So for example i have two links:<a onClick="doColorChange()">Link 1</a> <a onClick="doColorChange()">Link 2</a>I want it so that when I click Link 1, Link 1 …

How to make a On/Off button in Ionic

I need to put a button in Ionic that stays activated after its been pressed, and only deactivates after its been pressed again.There is a similar question but it only applies to icon buttons. (How to a…

How to add a CSS class to an element on click - React

How do you add a CSS class to an existing REACT element on click? I have a JSFiddle created: https://jsfiddle.net/5r25psub/In the fiddle, the code only works if I have the statement: this.setState({co…

Adding Quality Selector to plyr when using HLS Stream

I am using plyr as wrapper around HTML5 video tag and using Hls.js to stream my .m3u8 video . I was going around a lot of issues on plyr to enable quality selectors and came arounf multiple PRs which h…

Mousehold event in Jquery

Basically, I have this image with left and right arrow button. This image, by default is the first frame I have extracted from some gif, the original gif contains 31 frames. My goal is when the users c…

Uncaught TypeError: $(...)[index].hide/show is not a function

I am creating a jQuery search script for my site but I am getting the following errors:Uncaught TypeError: $(...)[index].hide is not a function (search.js:9) Uncaught TypeError: $(...)[index].show is n…

How to add space between DIVs?

I have a WordPress generated page where I want to place AdSense below the header of the page. See image at https://i.stack.imgur.com/DTOQB.jpgI want to create some white space between the header and t…

How to convert UUID/GUID to OID/DICOM UID in JavaScript?

How can I convert an UUID/GUID value like 8348d2c5-0a65-4560-bb24-f4f6bcba601d (that I genreated with uuid v4) in to OID/DICOM UID like 2.25.174506987738820548334170905323706671133? I would prefer the…

JavaScript Depth-first search

I am trying to implement DFS in JavaScript but I am having a little problem. Here is my Algorithm class:"use strict";define([], function () {return function () {var that = this;this.search = …