I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
Hvis du har rimelig kontrol over serveren kan du blot lave nogle WSH (Windows Scripting Host) filer som du kører på bestemte tidspunkter via Schedule. Det er naturligvis ikke helt ASP, men du kan benytte både JavaScript og VBScript i koden (og dermed kalde objekter etc., men du har ikke Response, Request osv. Jeg har ofte benyttet en sådan ting til at sende nyhedsbreve ud...
Hvis det har interesse kan jeg vende tilbage i aften med et eksempel... Ellers kig på http://msdn.microsoft.com/scripting - der er masser af info omkring WSH, WSC og andre sjove teknologier ;-)
Nedenstående er en artikel, som jeg har liggende på min disk fra PowerASP:
(Jeg kan tilpasse den, hvis du ønsker)
Using the global.asa to schedule ASP code execution.
Have you ever had some asp code that needed to execute every once in a while but, you just didn't know how to do it.
There is a solution that doesn't involve running any scheduling or scripting software on the server and is actually very easy to get working.
You see... there is thing called the "global.asa". Most ASP newbies probably wonder what the heck it even is. The Global.asa file is event driven. It can contain four event procedures: Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd.
The global.asa is basically loaded into memory the first time any user views a page on your Web application. There are event procedure stubs that can contain script you want to be executed when the application starts or ends, or when the session starts or ends.
With some tricky coding you can use this file to schedule code to execute. At least around the time you need it to, this won't be able to make it execute at exactly a certain time.
Here is the 1st example. It simply keeps track of how many visitors have been to your site and after 100 it resets the count back to 0 and executes whatever code you need to run. Obviously you'll need to adjust the "100" to whatever makes sense for the amount of visitors your site receives.
Contents of the global.asa are below.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart Application("SessionCount") = 0 End Sub
' Here you would put any code you need to run ' do not surround the code with <% %> tags ' For example you might run a database query that checks for expired accounts
End if
End Sub
</SCRIPT>
Now lets say you want something to execute 4 times a day. You can store the date & time in a text file and check it periodically. When the date and time get to be more than 6 hours old the code will write the new date & time to the text file and then execute the code you want to run. You could change the "6" to whatever you want and therefore execute the code more or less often,
This is a pretty slick solution though it requires correct permissions to the text file for reading & writing. If not you'll get an error.
In this example we are checking the text file every 15 visitors. You can adjust this amount or remove the "check" completely so that it checks the file every time, but why check the file every time when you have a very busy site ? That would just be a waste of server resources ,but it is up to you how far you want to take this.
In this example you need to start the text file off with a valid date& time or else you will get an error because the script will read in an empty value the 1st time.
EXAMPLE: put 6/30/99 6:58:45 PM in the 1st line of the text file.
You could add code to check for that and handle the error, but I didn't really care at the time so I didn't do that. As long as there is a date there when it starts it will keep working.
Contents of the global.asa are below.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart Application("SessionCount") = 0 End Sub
Set ObjMyFile = CreateObject("Scripting.FileSystemObject") Set OpenMyFile = ObjMyFile.OpenTextFile(Server.MapPath("last-update.txt")) MyFileValue = OpenMyFile.ReadLine OpenMyFile.Close
If DateDiff("h",MyFileValue,NOW) > 6 Then
' Here you would put any code you need to run ' do not surround the code with <% %> tags ' For example you might run a database query that checks for expired accounts
Set WriteMyFile = ObjMyFile.CreateTextFile(Server.MapPath("last-update.txt")) WriteMyFile.WriteLine(NOW) WriteMyFile.Close
Ej, det bliver lidt for ustabilt, det svinger jo hele tiden hvor mange besøgende man har. Desuden tror jeg jeg har fundet en smartere måde. Man kunne vel hver gang folk besøgte siden tjekke hvad klokken var på serveren og hvis den så var f.eks. 15:30 så sendte den beskeden, og skrev selvfølgelig at den var blevet sendt sådan at den ikke bliver sendt flere gange.... lyder det ikke smart?
Det bedste er at køre en AT kommando som kan indstilles via WSH - men det kræver at du har de fornødne rettiheder på serveren.
Faktisk er Cron-funktionerne en meget vanskelig størrelse under NT hvis ikke man sidder lige ved maskinen.
Du kunne evt. sætte din egen maskine op derhjemme så den selv ringede op til din ISP og loggede ind på en ASP side - gerne med et kryptisk navn, så folk ikke gættede det - som kunne bruge CDONTS (eller whatever) til at sende SMS'ene ud.
Nu er det her godt nok et forholdsvist gammelt spg. , men ricardo, jeg står i samme problem, uden så mange besøgende, og vel også gerne være lidt mere præcis. Kan du poste det der AT kode til WSH'en? Jeg har nemlig fuld adgang. (fjern-admin via net-op)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.