Use JS and Scheduled tasks to process

Source: Internet
Author: User
js| Timing

To do the timing, the first thing we think about is to write a program ourselves and then deploy the program to win's scheduled task.
This program can be a simple batch processing dat file, or it can be a JS file. Of course, more complicated dll,exe can also be.
Considering the convenience, easy maintenance, I recommend the use of JS files.

Here is a simple JS sample file.
His function is: visit a page, if found this page abnormal restart the IIS service.
By deploying it to a scheduled task, you can monitor your Web site.

if (! Checkurl ())
{
WScript.Echo ("IISReset");
var s = new ActiveXObject ("Wscript.Shell");
S.run ("iisreset");
}
Else
{
WScript.Echo ("OK");
}


function Checkurl ()
{
Try
{
var xh=new activexobject ("Microsoft.XMLHTTP");
Xh.open ("Get", "http://localhost/quickstart/aspplus/doc/businessobjs.aspx", false);
Xh.send ("");
return xh.status = = 200;
}
catch (X)
{
return false;
}
}

The above use Microsoft.XMLHTTP if a site does not respond, he will always wait. This problem can be avoided by changing into msxml2.serverxmlhttp. Refer to the following function:

function Checkurl ()
{
Try
{
With this, you can set the timeout time without waiting.
var xmlserverhttp = new ActiveXObject ("Msxml2.serverxmlhttp");
var lresolve = 5 * 1000;
var lconnect = 5 * 1000;
var lsend = 15 * 1000;
var lreceive = 15 * 1000;
Xmlserverhttp.settimeouts (Lresolve, Lconnect, Lsend, lreceive);
Xmlserverhttp.open ("Get", "http://localhost/quickstart/aspplus/doc/businessobjs.aspx", false);
Xmlserverhttp.send ();
return xmlserverhttp.status = = 200;
}
catch (X)
{
return false;
}
}


If you want to access a page that requires authentication.
Please refer to:
Oxmlhttprequest.open (method, Url, Async, User, Password)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.