Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


run once a month

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,41965
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> run once a month
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 run once a month - 1/11/2007 9:29:18 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
Hi
Please could someone help in getting this to run once a month.
I can do it as below once a day and I can do it so it only runs once, how do I do it so it will run once a month?

'Now Create a registry value so if this is run it wont run again today
varToday = Cleanmgr
   varToday = Weekday(Date)

Verify = "HKLM\SOFTWARE\MyInstallsAndFixes\"

'Check if scan has run today and if so exit
On Error Resume Next
LastRunDate = WshShell.RegRead(Verify & "Cleanmgr")
If LastRunDate =  cstr(Date) Then
     WScript.Quit
Else
    WshShell.RegWrite Verify & "Cleanmgr",Date,"REG_SZ"
End If
 
 
Post #: 1
 
 RE: run once a month - 1/12/2007 12:06:34 AM   
  TNO


Posts: 1397
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
I suggest doing something like this:

Dim Current
Current = Month(Now)

If(Current <> LastRunDate) Then
   'Run or do whatever
   'Update registry to hold the new LastRunDate which equals Month(Now)
Else
   'Do Nothing or whatever
End If

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to gdewrance)
 
 
Post #: 2
 
 RE: run once a month - 1/12/2007 12:20:08 AM   
  mbouchard


Posts: 1923
Score: 16
Joined: 5/15/2003
From: USA
Status: online
I would use somesort of tag file of reg entry to help determine the lat run time for the script. This way, if the PC is off on the day it should have run, it can run after it logs on.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to gdewrance)
 
 
Post #: 3
 
 RE: run once a month - 1/12/2007 12:31:01 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
Thanks TNO
To mbouchard
Yip thats what I'm trying to do

Would this work it writes a registry entry just havn't tested it fully, I suppose I could change the system clock


      

(in reply to mbouchard)
 
 
Post #: 4
 
 RE: run once a month - 1/12/2007 1:21:58 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
I have this but not working


      

(in reply to TNO)
 
 
Post #: 5
 
 RE: run once a month - 1/12/2007 1:35:01 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
I have created scripts that
run once and if value exists will never run again
run on specific days of the week
run every day once a day

but this month thing has me snookered

(in reply to gdewrance)
 
 
Post #: 6
 
 RE: run once a month - 1/12/2007 2:04:19 AM   
  dm_4ever


Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If you're using Month(Now) you're going to get a value of 1-12 and I'm not sure how you would make your script think that 1 is greater than 12 when the next year comes.  I'm not sure what you think, but if you use the current date and the DateDiff function you can check for lets say every 30 days or so.


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to gdewrance)
 
 
Post #: 7
 
 RE: run once a month - 1/12/2007 2:50:25 AM   
  Country73


Posts: 735
Score: 10
Status: offline
Would something like this work out for you?

      
My registry key was tested with the string of 12/1/2006; 1/1/2007; 2/1/2007 and it worked like it should.
(Added future month incase you happen to run on a machine that has a future date setup on it)

P.S. Just tried to lay this script out in the most basic way possible (In the habit from working with individuals here at my work)

(in reply to gdewrance)
 
 
Post #: 8
 
 RE: run once a month - 1/14/2007 6:07:25 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
Thanks to all
dm_4ever yours was close but did not work, but I managed to get it working.

Option Explicit

Dim WshShell : Set WSHShell = CreateObject("WScript.Shell")
Dim Inventory, varToday, Verify, LastRunDate

'Now Create a registry value so if this is run it wont run again for a Month
varToday = (Date)

Verify = "HKLM\SOFTWARE\MyInstallsAndFixes\"

'Check if scan has run today and if so Exit
On Error Resume Next
LastRunDate = WshShell.RegRead(Verify & "Inventory")
On error goto 0
If DateDiff("d", LastRunDate, varToday) < 30 Then
  WScript.Quit
Else
WshShell.RegWrite Verify & "Inventory",Date,"REG_SZ"
End If

(in reply to dm_4ever)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> run once a month Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts