首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > 技巧与经验 >
    7i24 .Com  
  用ASP来构建NT服务(英文,高手看吧)

7i24.Com不停为您服务


SUMMARY

This tutorial will guide you through the steps of setting up and configuring a Windows NT Server or Workstation to execute an ASP script as a service. This will let you execute an ASP script without a user being logged on to the server, thus allowing you to use the ASP technology as a tool for automatic file processing or similar.

REQUIREMENTS

For this setup to work, the server must have the following software installed:


An ASP compliant web server. For instance, Microsoft Internet Information Server (IIS) version 3.0 or higher.
A webbrowser. For instance, Microsoft Internet Explorer.
The Windows NT Ressource Kit or at least the ServAny/InstSrv utilities available separately.
When doing all the following, you must be logged on as Administrator.

THE SCRIPT

The ASP script you want to run as a service should be written as plain ASP as you would normally do.
Although, in case you want the script to "loop", you should make sure, that you output the appropriate HTML to initiate a reload of the script. This should look something like this:

 <%
   [ Perform whatever task you need ]
 %>

 <html>
 <head>
 <meta http-equiv="refresh" content="60; url=myScript.asp">
 </head>
 <body>
 ...
 </body>
 </html>

Generally, you would not generate any output, as the script will run in the background, not having anything to present to a user.

The HTML above assumes that the name of the script is myScript.asp and will reload the script (execute it) every 60 seconds.

Copy the script file to your webserver so it is accessible within the webserver namespace. From now on, I assume that you put it in the webserver root directory, so it is accessible via
http://localhost/myScript.asp

Eventually, test it using the webbrowser to make sure everything works as planned.

INSTALLING THE SERVICE

Setting up the service is pretty straight-forward if you follow the guideline provided with the NT Ressource Kit. Anyway, the following will guide you through just the nessecary steps.

We need the following files from the NT Ressource Kit:

 instsrv.exe    Utility to install Windows NT services
 srvany.exe    A service that will run any application

Although its optional, I recommend putting both files in your System32 directory. Now, start up a command prompt and execute this:

 instsrv myAspService srvany.exe

A new service named "myAspService" is now available through the Control Panel -> Services applet. Of course, you can provide any name you like.

CONFIGURING THE SERVICE

Now we need to configure the newly installed service to actually execute the script. As seen above, we need some host application to make the HTTP request - namely a webbrowser. In other words, we need to configure the service to execute the webbrowser with the appropriate URL as a parameter.

To configure the service, first open the Services applet in Control Panel. Locate the new service, double-click it, and make sure it is set to "Automatic" startup. Close the Control Panel applet.

Start up the registry editor (either regedit.exe or regedt32.exe).

Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

Locate the name of your new service. Under this key, create a new key called "Parameters".

Under this new key, create the following two value/data pairs, both of type String/REG_SZ.

Value name: Application
Data:    c:\Program Files\Plus!\Microsoft Internet\iexplore.exe

Value name: AppParameters
Data:    http://localhost/myScript.asp

Of course, you must do any appropriate changes to paths and names in order to fit your system setup and installations paths.

Close the registry editor.

TESTING THE SERVICE

To test the entire setup, reboot the server. Afterwards, go to Control Panel -> Services and verify, that the service is running. This means, that the ServAny utility is running.

Start TaskManager (taskmgr.exe) and click the Processes pane. Verify that there is an Image Name called "IEXPLORE.EXE". If there is, then the script is being requested at least once. It does not guarantee, that your script is error-free. If your script has stalled with an error you will not be able to see that! So be sure to test your script before using this.

At any time, you can - of course - update the script in the webserver root directory to apply any changes to the script. If you do so, I recommend stopping and starting the service through the Control Panel to make sure, that the new script is loaded proberly.

INSTALLING MULTIPLE SERVICES

If you for some reason want to have multiple scripts running as services, you should simply follow this tutorial top-down for each service, providing a unique name for each service you install.

USAGE EXAMPLE

Personally, I use this technique as part of a web system where another server provides raw data files via FTP for presentation on a webserver. On the webserver I have installed an ASP script (as a service) that processes all incoming data files and writes the data to a local database. This database is then accessed through the public web service where the data is proberly formatted and pres



  2002年1月14日  阅读 1554 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:

上一篇: 设定你的ASP程序的执行次数
下一篇: 再谈在asp聊天室里实现房间功能和用户显示
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利