Can I initialize objects written in JScript from VBScript?

前端 未结 1 1356
时光说笑
时光说笑 2021-01-13 06:37

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

相关标签:
1条回答
  • 2021-01-13 07:08

    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>
    
    0 讨论(0)
提交回复
热议问题