Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2004, 10:03 AM
Authorized User
 
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Automating ASP Scripts

Hi

I need to have asp script/s run automatically on the server without we having to go to a webpage to run the script for eg: email all my clients in a database at midnight.

I know it can also be done using Windows Scripting Host. Unfortunately my server host wont do this for me.

Can I do this some other way, like using DTS or Jobs in SQL Server 2000?

your comments would be greatly appreciated.
 
Old September 20th, 2004, 10:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Save this code to a file with a js extension after modifying the two UPPER CASE variables at the top. You can then schedule it to run from any PC that could have accessed the page via the browser. You can check messages in event viewer later.
Code:
var BASE_URL = "http://www.google.com"; //Url to access
var LOG_PREFIX = "Google fetch";  //Prefix to identify messages in event log.

var _oHttpReq = null;
var _oShell = null;

var EVENT_INFORMATION = 4;
var EVENT_ERROR = 1;

function getHttpReq()
{
  if (_oHttpReq == null)
  {
    _oHttpReq = new ActiveXObject("Msxml2.XmlHttp.3.0");
  }
  return _oHttpReq;        
}

function getShell()
{
  if (_oShell == null)
  {
    _oShell = new ActiveXObject("WScript.Shell");
  }
  return _oShell;  
}

function logEvent(Message, Type)
{
  var oShell = getShell();
  var sMessage = LOG_PREFIX + ": " + Message
  oShell.logEvent(Type, sMessage);
}

function main()
{
  var oHttpReq = getHttpReq();
  var sFullUrl = BASE_URL;
  logEvent("Beginning auto fetch on '" + sFullUrl + "'.", EVENT_INFORMATION);
  try
  {
    oHttpReq.open("GET", sFullUrl, false);
    //WScript.echo(sFullUrl);
    oHttpReq.send();
    var iType = EVENT_INFORMATION;
    if (oHttpReq.status != 200)
    {
      iType = EVENT_ERROR);    
    }
    logEvent("Page accessed - " + oHttpReq.status + " (" +  oHttpReq.statusText + ")", iType);
  }
  catch(e)
  {
    logEvent("Error occurred accessing '" + sFullUrl + "'.\n" + e.message, EVENT_ERROR);
  }
  logEvent("Finished.", EVENT_INFORMATION);
}

main();
You will need to have MS xml parser version 3 installed, if not download version 4 and change version number in line 14.

--

Joe
 
Old September 20th, 2004, 02:04 PM
Authorized User
 
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

THanks, however with this code don't you have to access the page befor it runs, is this correct?

I need it to run without physically being accessed.


 
Old September 21st, 2004, 02:29 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There is no need to access the page first. As long as you could open Internet Explorer and type in the URL and it would show then the script will work.

--

Joe
 
Old September 21st, 2004, 04:08 AM
Authorized User
 
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe

But that means someone still has to physically type in the url. I dont want any human interaction at all

Ryan

 
Old September 22nd, 2004, 04:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Then you got to check out for SQL mail and set that up, so that it run at any time set, without any manual work needed, other than setting it up. But I am not sure if you have all the data put up in the database(like emailids, content, etc to be picked from the database before sending out emails).

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old September 23rd, 2004, 03:43 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by Ryanvdm
 Hi Joe

But that means someone still has to physically type in the url. I dont want any human interaction at all

Ryan
NO!!!
Just run the script and you'll see, check the event log afterwards.



--

Joe (Co-author Beginning XML, 3rd edition)





Similar Threads
Thread Thread Starter Forum Replies Last Post
running asp.net scripts owoade .NET Web Services 3 August 27th, 2007 08:06 PM
HOWTO run WSH scripts from ASP?? fhameed Classic ASP Professional 1 July 2nd, 2006 10:55 AM
I cant run asp scripts majc Classic ASP Basics 4 December 3rd, 2005 06:14 AM
running Wmi Scripts in ASP.NET Looney Javascript How-To 3 May 20th, 2005 01:30 PM
cannot run ASP scripts -Dman100- Classic ASP Databases 7 April 13th, 2004 11:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.