#131198 - 2004-12-13 07:19 AM
running a script every 45 days
|
ozraelised
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
|
|
|
|
#131201 - 2004-12-13 04:50 PM
Re: running a script every 45 days
|
Bryce
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
|
|
|
|
#131203 - 2004-12-14 02:09 AM
Re: running a script every 45 days
|
ozraelised
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
|
|
|
|
#131206 - 2004-12-14 05:09 AM
Re: running a script every 45 days
|
ozraelised
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
|
|
|
|
#131208 - 2004-12-14 10:34 AM
Re: running a script every 45 days
|
NTDOC
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
|
|
|
|
#131213 - 2005-03-08 05:51 AM
Re: running a script every 45 days
|
ozraelised
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 581 anonymous users online.
|
|
|