JavaScript won't execute when calling webpage via VBScript using XMLHttpRequest

I have a process where I have created a polling function that executes an XMLHttpRequest via VBScript.

The request gets an ASP Classic page which checks an MSSQL table for newly inserted records and runs some APIs to add users to Azure AD.

I use jQuery for polling, then I use Windows Task Scheduler to run the VBScript every 5 minutes. Here is the code:


set xmlhttp = createobject("microsoft.xmlhttp") "GET", "", false
set xmlhttp = nothing

ASP classic code in the GET request:


action = request("action")
route = request("route")

select case action
    case "create-ad-account" : createADAccount()
    case else : default()
end select

function createADAccount()
''Checks table for new records, add to AD accordingly.

end function

function default()
<script src="//"></script>

        //Get route
        var route = getUrlVars()["route"];

            doPoll('?action=' + route);

        function doPoll(url) {
            var result;

            $.post(url, function(data) {
                result = data;

            .done(function (){
                console.log(result);  //Show results here
                } else {
                   console.log('Task competed');

            .fail(function (jqXHR, textStatus, errorThrown){
                console.log('Error: ' + textStatus);

        function getUrlVars(){
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for(var i = 0; i < hashes.length; i++)
                hash = hashes[i].split('=');
                vars[hash[0]] = hash[1];
            return vars;
end function

The page in the get requests checks for newly added records to a users table which then checks to see if the user exists in AD, if not it adds them via an API call.

It all works fine when loading the page from a browser, when running it from task scheduler it reports back 0x0 meaning successfully executed but nothing is done.

I am assuming the JavaScript in the default() function is not executed when running from the VBScript as I tried running the VBScript directly and nothing is done (i.e. the createADAccount function does not run).


  • This will never work as you expect because the XMLHTTP request doesn't know how to process client-side code, it is not an Internet Browser. It has no concept of a JavaScript Engine, it just sends and receives HTTP in its raw form.

    Tasks such as processing client-side JavaScript and rendering CSS / DOM are built into Internet Browser applications.

    As an XMLHTTP response deals with the raw HTTP response you would need to parse the script and execute it yourself.

    Useful Links