Using WSH to schedule work schedules (from: learnasp)

Source: Internet
Author: User
Tags command line
Making use of WSH to schedule work schedules

A very common ASP question: "How do I schedule a job to perform a Web?", most of this is because managers may use an ASP Web site to do the activities of the library maintenance, such as backup ... And so on, on the Windows NT platform there's a way to do the job scheduling, which is at instruction + Schedule service, but unfortunately you don't have the means to execute the ASP Web on the command line (command-line)

Of course, you can execute IE on the command line and tell it to perform a Web page, for example: C:\Program files\internet Explorer\iexplore.exe Http://localhost/mypage.asp, This is definitely not the way most web site managers want to go, because this has to open the browser and spend a lot of system resources, no good! In addition, there is a lack of time to perform ASP Web pages (Timeout), and if you want to perform a number of scheduling tasks, you may want to change Timeout time, wow! It's too troublesome! No good!

In this article, we will introduce a solution using the WSH (Windows scripting Host)

WSH's installation


Windows WSH, Windows Watts, IIS 4.0 already contains
WSH included in IE version 5.0
If you are a Windows 95 user, you can download an installation program to the Microsoft Web site.
Http://www.microsoft.com/msdownload/vbscript/scripting.asp
Examples

Suppose you now have a flick system, you want to check out the expiration date this work is automated every morning, that is, when a period of time is passed, the ad is changed to inactive, let's take a look at the data table Adinfo

Adid Advertising Int
Adname advertising VarChar (64)
Validtodate Advertising Expiration Date DateTime
Adstatus Advertising State Int (0 is deactivated, 1 is progressing)


Let's see what the ASP does.

<%
Set oconn = Server.CreateObject ("Adodb.connection")
oConn.Open yourconnstring
sSQL = "Update Adinfo set Adstatus=0" _
& "where validtodate<=" & Date & "'"
Oconn.execute (sSQL)
Oconn.close
Set oconn = Nothing
%>

Take a look at how to use WSH, basically with the ASP's writing is the same except

No need to add ASP separator <%%>
The file's name is. vbs
Since the Asp.dll is not used, there is no ASP's object pattern and is not suitable for
Cannot use the servo-side inclusion, so some ADO constants need to be declared by themselves

' Please don't use Server.CreateObject
Set oconn = CreateObject ("Adodb.connection")
oConn.Open yourconnstring
sSQL = "Update Adinfo set Adstatus=0" _
& "where validtodate<=" & Date & "'"
Oconn.execute (sSQL)
Oconn.close
Set oconn = Nothing

Save the file as C:\scripts\updateadstatus.vbs, WSH has two versions, one for the window (Wscript.exe), one for the command list (cscript.exe), in this case we will use (cscript.exe), You can execute it under the DOS command column.

C:\>cscript C:\scripts\updateadstatus.vbs

Then you can check with Query Analyzer to see if the data is updated, in practical applications, it is recommended that you use this to work in different times, as if I were to create a batch file called Dailytask.bat to perform all the daily routine work, so All I need to do is to put all my daily script files into this batch, and then use the at Command or SQL Server Agent to perform daily dailytask.bat

Strong advice to use the SQL Server Agent is more efficient and stable than using the at Command! To set the SQL Server Agent you can perform Enterprise Manager, and you will see this after the exhibition.



Mouse Right click Jobs, choose New Job
Choose Step Press New
Specify step Name, Type Select the operating System command, and set the command for the Execute
Select Schedule to set your schedule
Hopefully this article will help you!




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.