CJD
(Fresh Scripter)
2004-11-17 02:45 PM
Run part of script only on first Monday of month

As the title says, I need to run part of my logon script ONLY on the first Monday of each month (for auditing PCs). Here's what runs right now, and the scheduling is done by the settings in the exe file.

IF INGROUP("Domain Users")
RUN '\\server\xxx.exe'
?Audit is running in the background"
ENDIF

However, the settings for the audit program don't allow you to specifiy something as specific as the first Monday of the month. If anyone has an example of something similar they would like to share, it would really help out. Thanks.


maciep
(Korg Regular)
2004-11-17 02:54 PM
Re: Run part of script only on first Monday of month

haven't given it too much thought, but something like this might work

Code:

if @day = "Monday" and @mdayno < 8
? "First Monday of the month
endif



JochenAdministrator
(KiX Supporter)
2004-11-17 02:55 PM
Re: Run part of script only on first Monday of month

ummm ... will this work ?

Code:


if @wdayno = 1 and @mdayno < 8
"Today is the first monday of this month"
endif




this is only reliable of course if it runs every day of week


JochenAdministrator
(KiX Supporter)
2004-11-17 02:57 PM
Re: Run part of script only on first Monday of month

dang ^~°

Les
(KiX Master)
2004-11-17 03:26 PM
Re: Run part of script only on first Monday of month

Of course if one logs on many times on that Monday, it will run at every logon. Better to write a flag in the registry or an INI file or some other method to see if it had run already.

JochenAdministrator
(KiX Supporter)
2004-11-17 03:29 PM
Re: Run part of script only on first Monday of month

your right Les, I knew there was something fishy with that !

maciep
(Korg Regular)
2004-11-17 03:40 PM
Re: Run part of script only on first Monday of month

yeah it's just a start. and like jochen pointed out, if nobody logs on that monday, it won't run either. so it is definitely lacking some needed logic.

LonkeroAdministrator
(KiX Master Guru)
2004-11-17 03:41 PM
Re: Run part of script only on first Monday of month

nope, it's reliable always.
if a script is said to be run only on first monday, then it must not run otherwise, even though it would not run because of that for years.

the code is reliable.
just that the logic behind the ruling could be worked out a bit.

like, "run once a month" would be neat.
thus it would run on first logon of the month only, no matter what day it is.
something like this:
Code:

If ReadValue('HKCU\Software\KiXtart','lonks_val')<>@monthno
Run "myProggie"
$=WriteValue('HKCU\Software\KiXtart','lonks_val',@monthno,'REG_SZ')
EndIf



LonkeroAdministrator
(KiX Master Guru)
2004-11-17 03:42 PM
Re: Run part of script only on first Monday of month

lol, I wrote little bit too long that Shiat!
to those who wonder, it's reply to the jochens dang post


maciep
(Korg Regular)
2004-11-17 04:19 PM
Re: Run part of script only on first Monday of month

ok. borrowing from jooel, maybe something like this would work

Code:

if ReadValue('HKLM\Software\YourCompany\Audit','Month')<>@monthno
if @day = "Monday" or @mdayno > 7
if ingroup("Domain Users")
run "\\server\xxx.exe"
? "Audit is running in the background"
endif
$=writevalue('HKLM\Software\YourCompany\Audit','Month',@monthno,'REG_SZ')
endif
endif



JochenAdministrator
(KiX Supporter)
2004-11-17 04:23 PM
Re: Run part of script only on first Monday of month

ok,

back to the problem ... implementing Les' suggestion, how about this :

Code:


$sFlagKey = "HKEY_CURRENT_USER\Software\KiXtart\"

if @wdayno = 3 and @mdayno < 8 and not val(readvalue($sFlagKey, "FirstMondayFlag"))
;run your shtuff here!
if @error = 0 ; or whatever it takes
$_ = writevalue($sFlagKey, "FirstMondayFlag", 1, "REG_DWORD")
endif
else
$_ = writevalue($sFlagKey, "FirstMondayFlag", 0, "REG_DWORD")
endif





Les
(KiX Master)
2004-11-17 04:23 PM
Re: Run part of script only on first Monday of month

The prob with HKLM is perms.

I really hate crap like that running at logon. It is this sort of thing that encourages users to never logoff. It should be setup as a sceduled task instead.


JochenAdministrator
(KiX Supporter)
2004-11-17 04:27 PM
Re: Run part of script only on first Monday of month

beaten again
K, I will quit posting for today



**DONOTDELETE**
(Lurker)
2004-11-18 12:41 AM
Re: Run part of script only on first Monday of month

Quote:

Of course if one logs on many times on that Monday, it will run at every logon. Better to write a flag in the registry or an INI file or some other method to see if it had run already.




That part I can take care of. There is an option in the settings for the exe that you select that makes it run only once a day. I've been too busy to try implementing any of the suggestions today, but I'll let you guys know what works. Thanks for the help, and keep the suggestions coming.


Sealeopard
(KiX Master)
2004-11-18 02:49 AM
Re: Run part of script only on first Monday of month

If a script needs to run on mondays then I'd schedule it via the Task Scheduler, especially if it is an audit script. It would even run under a different user account, thus the chance that a user is closing the audit program is minimized. Also, the whole thing could be scheduled via admin script and no changes to a logon script are required.

LonkeroAdministrator
(KiX Master Guru)
2004-11-18 11:02 AM
Re: Run part of script only on first Monday of month

I think your idea of the first monday is still screwed up.
you can never get 100% hit if you limit the audit to single day of the month.

running it once a month is a different thing, and to that you got provided code on silver platter already.