Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scheduling a Task to Run Once every 6months using AT Command and VBScript

Posted on 2008-10-08
9
Medium Priority
?
460 Views
Last Modified: 2012-05-05
I currently have the code below that removes and old task on my XP machines and adds a new and if Vista is the OS detected it skips the removal portion and simply adds a task. This works well and dandy my only issue is the scheduling portion.

I currently have it set in the code so it scans on the 28th of each month. However I'd only like it to scan once every 6 months so If I could select only January and June I'd be happy, however I cannot seem to find how to schedule a task like this to only run on the 28th of the two months I want.

Can anyone offer me some advise on how to do this or if it's possible?


Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For each objOperatingSystem in colOperatingSystems 
 
If left(ObjOperatingSystem.version,1) >=6 Then 
Call Add_Job
Else
    strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set objInstance = objWMIService.Get("Win32_ScheduledJob.JobID=1")
 
err = objInstance.Delete
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
     ("c:\Progra~1\Identi~1\IdentityFinder.exe /jobmode /inifile=\\SERVERADDRESS\idf$\ini\cph.ini"  , "********000000.000000-420", _
        True ,  , 134217728 , , JobID=1)
 
 
End If
Next
 
 
Sub Add_Job()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
    ("c:\Progra~1\Identi~1\IdentityFinder.exe /jobmode /inifile=\\SERVERADDRESS\idf$\ini\cph.ini"  , "****06**000000.000000-420", _
        True ,  ,134217728 , , JobID=1)
End Sub

Open in new window

0
Comment
Question by:lotharpenguin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 33

Expert Comment

by:MikeKane
ID: 22668798
Good question.   I went searching for this one, I looked at both the AT command as you requested and also at the Win32_scheduledJob Class.    

In each case you can not specify a date for the scheduled item.  Each will only accept a weekday, or day of the month.  

Looking at the msdn:
http://msdn.microsoft.com/en-us/library/aa394399(VS.85).aspx

Quote on the STARTTIME:
UTC time to run the job, in the form of "YYYYMMDDHHMMSS.MMMMMM(+-)OOO", where "YYYYMMDD" must be replaced by "********". The replacement is necessary because the scheduling service only allows jobs to be configured to run one time, or run on a day of the month or week. A job cannot be run on a specific date.

Basically, doesn't look like you can do this via script.
0
 

Author Comment

by:lotharpenguin
ID: 22668883
^^ That's what I had found also. But it makes no sense since you can choose a month in the task scheduler itself.
0
 
LVL 33

Accepted Solution

by:
MikeKane earned 1000 total points
ID: 22668983
It must be early or I would have thought of this before....  

Try using the shell command schtasks  instead of AT or the Win32_scheduledJob Class.

the schtasks /create has a /MO option to specify weeks of the year numbered 1-52.   That should take care of your issue.  

Sample:
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.run("cmd /c schtasks.exe /create /SC DAILY /ST 15:00:00 /TN Backup /RU domain_name\user ID /RP password /TR c:\backup.vbs")

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lotharpenguin
ID: 22669131
For some reason I think I had tried that in the past and there was an issue with the UNC path or something I shall try it again and see what happens.
0
 

Author Comment

by:lotharpenguin
ID: 22669208
Yep with the list of switches I have to use with the app to get it to do what I need it to do schtask bawks at me and fails to add the job in the script. Outside of the script it functions but written as such.

It assumes /jobmode is a switch on schtasks not the IDF application.

Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.run("cmd /c schtasks.exe /create /SC MONTHLY /ST 15:00:00 /TN IDF /TR c:\Progra~1\Identi~1\IdentityFinder.exe /jobmode /inifile=\\ph-home.public-health.uiowa.edu\idf$\ini\cph.ini ")

Open in new window

0
 
LVL 33

Expert Comment

by:MikeKane
ID: 22669423
Here's a workaround:

Create 1 batch file with the line,
c:\Progra~1\Identi~1\IdentityFinder.exe /jobmode /inifile=\\ph-home.public-health.uiowa.edu\idf$\ini\cph.ini

Then use the schtask to call the batch file.....  

0
 

Author Comment

by:lotharpenguin
ID: 22669506
^^ Yep decided to just use a vbscript to call my scheduled command in a .bat file. Seems to work ok and is now scheduled for JUN and JAN 1st. Thanks Mike!
0
 

Author Closing Comment

by:lotharpenguin
ID: 31504207
Great help on this subject.
0
 

Author Comment

by:lotharpenguin
ID: 22669561
In case anyone needs to do something like this in the future:


#VBS FILE TO CALL BAT FILE AND ELIMINATE VISTA BOXES FOR ERROR ISSUES:
 
On Error Resume Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For each objOperatingSystem in colOperatingSystems 
 
If left(ObjOperatingSystem.version,1) >=6 Then 
Call Add_Job
Else
    strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set objInstance = objWMIService.Get("Win32_ScheduledJob.JobID=1")
 
err = objInstance.Delete
 
Set oShell = CreateObject("WSCript.shell") 
 
sCmd = "\\BATFILELOCATION\schtask.bat"
oShell.Run sCmd, 0, False
 
End If
Next
 
Sub Add_Job()
Set oShell = CreateObject("WSCript.shell") 
 
sCmd = "BATFILELOCATION\schtask.bat"
oShell.Run sCmd, 0, False
End Sub
 
 
#BAT FILE CONTENTS:
 
cmd /c schtasks.exe /create /SC MONTHLY /m JUN,JAN /ST 15:00:00 /TN IDF /TR "c:\Progra~1\Identi~1\IdentityFinder.exe /jobmode"

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question