Page 1 of 1 1
Topic Options
#131198 - 2004-12-13 07:19 AM running a script every 45 days
ozraelised Offline
Getting the hang of it

Registered: 2002-12-02
Posts: 59
Loc: Albury
I looked at the options of the date/time and without much success. Is there away to say run this script every 45 days?

Thanks

Top
#131199 - 2004-12-13 11:20 AM Re: running a script every 45 days
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Yup.

Search the forums for the date math routines to convert the date into an internal number. You can use normal math on the date (e.g. add / subtract 45 days) and perform numeric comparisons with the results.

If you have more questions after you've taken a look at these then post again giving more detail about what you are trying to achieve.

Top
#131200 - 2004-12-13 11:28 AM Re: running a script every 45 days
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The GetFileAge() UDF compairs file dates.
Do a check on a control file copied by the script and run it agian when it is 45 or more days old.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#131201 - 2004-12-13 04:50 PM Re: running a script every 45 days
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
using a date 0 marker as of today.. and finding the dates that fall on a 45 day cycle..

this code will generate the dates that occure once every 45 days for the next 10, 45 day cycles.

you need the UDF's CTime() and FlipCTime()

Code:

$date0 = @date,@time
for $i = 1 to 10
? split(ctime(flipctime($date0[0],$date0[1]) + (86400*45)*$i))[0]
next



Bryce

Top
#131202 - 2004-12-13 05:34 PM Re: running a script every 45 days
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Is there not at least one UDF posted that will run a program on a recurring schedule? There was never any mention of a control file in the original request. There is also no mention how this is all supposed to be kicked off.

Is this to be kicked from the logon script? There are several UDFs that can be used to setup a scheduled task that would not require a logon script.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#131203 - 2004-12-14 02:09 AM Re: running a script every 45 days
ozraelised Offline
Getting the hang of it

Registered: 2002-12-02
Posts: 59
Loc: Albury
More information:

The script will be run as part of the logon process.
Server 2000
Clients are win 2000/XP

Thanks

Top
#131204 - 2004-12-14 02:44 AM Re: running a script every 45 days
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Create a key in the reg, perhaps under HKEY_CURRENT_USER\Software\KiXtart\ and write a value there holding @YDayNo when you last ran the program. Then on every logon, compare the current @YDayNo with what is in the reg and if the spread is 45 or more, run the program and update the reg.

How hard can it be, besides having to calculate end of year wrap?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#131205 - 2004-12-14 04:42 AM Re: running a script every 45 days
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Forget wrapping @YDayNo. What was I thinking?
It would be simpler to store the date/time in CTime format and then use the FlipCTime() UDF that Bryce mentioned. Just convert 45 days to seconds (3888000) and Bob's your uncle.

So basically write the CTime to the reg when the app is run and then run it again if the reg value + 3888000 >= now in CTime.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#131206 - 2004-12-14 05:09 AM Re: running a script every 45 days
ozraelised Offline
Getting the hang of it

Registered: 2002-12-02
Posts: 59
Loc: Albury
Yes, I was thinking about the same thing.
So I started to write a script that will create :
HKEY_CURRENT_USER\software\every45 Days

since I don't have alot of experiance(as you can see) I wasn't sure as what type of file to add to the registry I was thinking reg_sz, and the value will be the date the script is run not sure at this moment how to do this.
But my first challange is to write a script that will:
check if the regsitry key is all ready exist and if yes to see the value and run or not run the script. if the key doesn't exist then write the key run the script.

I will keep you with the progress, as I will need some help.

KixTart Kix a....

Top
#131207 - 2004-12-14 07:42 AM Re: running a script every 45 days
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
with new kixtart versions, you don't need to care about the key, as it will be automatically created.
so, for registry you only need readvalue() and writevalue()
_________________________
!

download KiXnet

Top
#131208 - 2004-12-14 10:34 AM Re: running a script every 45 days
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Well before someone FLAMES you... It is KiXtart NOT KixTart

Here is some code that should get you going in the right direction, based upon suggestions by Les.

NOTE: UNTESTED CODE The SetOptions may interfere with other script settings in a larger script. You can remark out lines to prevent them from running by placing a semi-colon at the point where you want the code to be bypassed. However I would recommend that you write your code to support at least these SetOptions.

Code:
Break On

Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')

Dim $SetCounter,$Key,$KeyValue,$Delay
$Delay=3888000
$SetCounter=FlipcTime(@DATE,@TIME)
$Key=KeyExist('HKCU\Software\MyCompany\Schedule\45')
If $Key
$KeyValue=Val(ReadValue('HKCU\Software\MyCompany\Schedule\45','time'))
If $SetCounter > ($KeyValue+$Delay)
; Shell 'application you want to run every 45 days'
; Reset the counter to current time so you can check properly next time
$KeyValue=WriteValue('HKCU\Software\MyCompany\Schedule\45','time',$SetCounter,REG_SZ)
? 'Time is beyond the ' + $Delay + ' day period, going to run app now'
EndIf
Else
? 'Appears to be first time run, now setting registry value... '
$KeyValue=WriteValue('HKCU\Software\MyCompany\Schedule\45','time',$SetCounter,REG_SZ)
; Shell 'application you want to run every 45 days'
Endif


Function FlipcTime($date,$time,optional $tz)
dim $y,$m,$d
$date = split($date,"/")
if ubound($date) <> 2 exit(1) endif
$y=val($date[0]) $m=val($date[1]) $d=val($date[2])
if $m<3
$m=$m+12
$y=$y-1
endif
$Date=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
$time = split($time,":")
select
case ubound($time)=1
redim preserve $time[2]
$time[2]=0
case ubound($time)=2
case 1
exit(1)
endselect
$time = (val($time[0])*3600)+(val($time[1])*60)+val($time[2])
$flipctime = IIF($tz,(($date-719163)*86400 + $time)-($tz*3600),($date-719163)*86400 + $time)
endfunction



FYI ::

FUNCTION FlipcTime()
AUTHOR Bryce Lindsay
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=121394

3,600 seconds per hour
86,400 seconds per day
604,800 seconds per week
2,592,000 seconds per 30 day month
3,888,000 seconds per 45 days

Top
#131209 - 2004-12-15 05:28 AM Re: running a script every 45 days
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why can't the script be fired off through the Task Scheduler or via an admin script?

Or is this for an air traffic control system that needs rebooting every 45 days?

To read this sad story of software development gone awry go to http://www.spectrum.ieee.org/WEBONLY/resource/nov04/1104nair.html

Anybody flying this Christmas?
_________________________
There are two types of vessels, submarines and targets.

Top
#131210 - 2004-12-15 07:43 AM Re: running a script every 45 days
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Running as Task Scheduler or via an admin script has it's own pitfalls and issues as well. I agree that depending on what the task is the Task Scheduler would be a great method.

Not sure why, just seems everyone steered clear of that method, so I provided some code based on an idea by Les.

Top
#131211 - 2004-12-15 09:04 AM Re: running a script every 45 days
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens, that's kinda weird.
doesn't those systems cost like zillions of dollars and then there is simple counter code in the system that nobody at the software provider nor FAA is able to fix?

weird I say...
and, having FAA knowing there is a problem in the system, it should be hold accountable. in court.
_________________________
!

download KiXnet

Top
#131212 - 2004-12-16 10:39 AM Re: running a script every 45 days
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Usually the problem is that you want to run the script at least every 45 days, so if the computer is not switched on it will run when it is next available.

Whether the subsequent runs will be 45 days after the new anniversary or the original anniversary will depend on the requirements.

Top
#131213 - 2005-03-08 05:51 AM Re: running a script every 45 days
ozraelised Offline
Getting the hang of it

Registered: 2002-12-02
Posts: 59
Loc: Albury
Hi,

Than you jfor all your help as you can see it took me a long time to understand what is going on this is appart of the other 100s things I need to do .
So I looked at all your suggetions at try to put it all together. I would appricate if you are abale to help me ant let me know of it will work or if it makes any sens.
Just to reminde you :
windows server envir'
XP SP1 and WIn2000 SP3 envir'
I need to make usre the messagebox comes up every 45 days.
Ok this is the Script:

Code:

Dim $OS, $Msg, $Answer, $RC

$OS=setOption('Explicit','off')
$OS=setOption('NoVarsInString','On')
$OS=setOption('WrapAtEOL','On')

Dim $SetCounter, $Key, $KeyValue, $Delay, $KiXtartSchedule

$Delay=3888000
$SetCounter=FileTime(@Date,@Time)
$KiXtartSchedule="HKEY_CURRENT_USER\Software\LogOnScripts\Schedule\45"
$Key=KeyExist($KiXtartSchedule)
If $Key
$KeyValue=Val(ReadValue($KiXtartScheduale,'time'))
If SetCounter > ($KeyValue+$Delay)
$Answer=MessageBox("what ever need to be said","Reminder",4180)
If $Answer <>6
$Msg=MessageBox("what ever need to be said",4112)
$RC=LogOff(1)
Else
$Msg=MessageBox(What ever need to be said",64,5)
EndIf KeyValue=WriteValue$KiXtartSchedule,'time',$SetCounter,REG_SZ)
If $Answer <>6
$Msg=MessageBox("what ever need to be said",4112)
$RC=LogOff(1)
Else
$Msg=MessageBox(What ever need to be said",64,5)
EndIf
If InGroup("Domain Users")
MapDrive("F:", "jmmes", "Vol1")
MapDrive("G:", "jmmes", "mCalas")
MapDrive("H:", "jmmes", "caldata")
MapDrive("I:", "jmmes", "s6system")
MapDrive("J:", "jmmes", "winapp")
; K: Drive Mapped by OS as Home Share
MapDrive("L:", "jmmes", "abas")
MapDrive("M:", "jmmes", "vol1")
MapDrive("N:", "jmmes", "netapps")
MapDrive("O:", "jmmes", "JMME-FPlan")
MapDrive("P:", "jmmes", "apps")
MapDrive("Q:", "jmmes" ,"NotesMME")
MapDrive("S:", "jmmes", "vol2")
MapDrive("T:", "jmmes", "templates")
MapDrive("Y:", "jmmes", "PWCDll")

Endif

Function MapDrive($Drive, $Server, $Share)
Dim $Drive, $Server, $Share, $shell
Color c+/n

If $Drive<>"" and $Server<>"" and $Share<>""
$LogText="Connecting $Drive to \\$Server\$Share"
? $LogText
USE $Drive /Delete /Persistent
USE $Drive "\\" + $Server + "\" + $Share
If @error=0
color g+/n
$x = " - Success"
$x
If val($DOS) >= 5
$shell=createobject("shell.application")
$shell.namespace($Drive+"\").self.name=$Share + " on '" + $Server + "'"
$shell = 0
Endif
Else
color r+/n
$x = " - Failed: Error " + @error
$x
$ErrorState=1
Endif
EndIf
Else keyValue=WriteValue$KiXtartSchedule,'time',SetCounter,REG_SZ)
Function FlipcTime($date,$time,optional $tz)
dim $y,$m,$d
$date = split($date,"/")
if ubound($date) <> 2 exit(1) endif
$y=val($date[0]) $m=val($date[1]) $d=val($date[2])
if $m<3
$m=$m+12
$y=$y-1
endif
$Date=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
$time = split($time,":")
select
case ubound($time)=1
redim preserve $time[2]
$time[2]=0
case ubound($time)=2
case 1
exit(1)
endselect
$time = (val($time[0])*3600)+(val($time[1])*60)+val($time[2])
$flipctime = IIF($tz,(($date-719163)*86400 + $time)-($tz*3600),($date-719163)*86400 + $time)
endfunction



Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 581 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.067 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org