Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Scheduling a task with vbscript

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Scheduling a task with vbscript
  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 >>
 Scheduling a task with vbscript - 3/15/2005 3:27:20 AM   
  jide

 

Posts: 5
Score: 0
Joined: 3/15/2005
From:
Status: offline
Hi every1,

Does someone know how to create a scheduled task (far in the time for example two months later) with a vbscript?
I cannot set a specific date, I just can schedule a task for this week or for this month...

Has someone an idea?

Thx in advance.

JiDe
 
 
Post #: 1
 
 Re: Scheduling a task with vbscript - 3/15/2005 5:01:01 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Could you post your codes so eveyrone can get a chance to look at it and offer suggetions.

(in reply to jide)
 
 
Post #: 2
 
 Re: Scheduling a task with vbscript - 3/15/2005 5:16:03 AM   
  tnoonan

 

Posts: 364
Score: 0
Joined: 12/14/2004
From:
Status: offline
This is what I use to schedule task on list of pc's forget where i found it.

'This script loops through an input list of machines, pings them one by one,
'waiting 10 seconds before moving on to the next.
'Separate logs are written for those machines pinged successfully
'and those that are unreachable.
'If the machine is reachable, then the AT scheduler is used to schedule execution of a
'pre-defined script that exists on a remote UNC share.
'WARNING: Separate verification is necessary to ensure that the intended
'command actually executed on the listed machines. These two logs only
'indicate which machines were initially reached.
'The default input list is c:\pcs.txt
'Otherwise, the only required modifcation is to change the UNC path in the
'line containing "\\ServerName\ShareName\FileName" below.
'Optionally the timing of the scheduling may be delayed by editing the line that
'contains strStartTime = DateAdd("n",60, Now) ' Adds 60 minutes to now

Option Explicit
'On Error Resume Next
Dim strComputer,objFSO,machines,objFailed,objSuccess,WshShell
Dim strDate,IsConnectible,objWMIService
Dim strStartTime,strAtCommand,strBatchFile

' --- BEGIN CONFIGURATION SECTION ---
'Let's start the mass scheduling to begin an hour from now
strStartTime = DateAdd("n",5, Now) ' Adds 60 mins to now

'Modify the path below to point to your batch file
strBatchFile = "cscript \\l01wmsi\c$\dfd.vbs"
' --- END CONFIGURATION SECTION ---



'Set the input file path. Default is c:\pcs.txt
machines = ("c:\pcs.txt")
machines = inputbox("Enter the Path\FileName of PC list or Cancel to exit.", _
"PC File List",machines)
if machines = "" then
wscript.quit
end if

'Format the date stamp for the log files.
strDate = replace(Date, "/","-")
strDate = replace(strDate, "20","")

'Create the log files
set objFSO=createobject("scripting.filesystemobject")
set objFailed=objFSO.createtextfile("c:\failed" & strDate & ".txt")
set objSuccess=objFSO.createtextfile("c:\success" & strDate & ".txt")

set machines=objFSO.opentextfile(machines)

'Start looping through the machine names in the file
Do While not machines.AtEndOfLine
strComputer = machines.ReadLine
if Pingable(strComputer, 2, 750) Then
'Let's wait ten seconds
wscript.sleep 10000 : ' add 10 second wait


strAtCommand = "AT \\" & strComputer & " " & Hour(strStartTime) & _
":" & Minute(strStartTime) & " " & strBatchFile

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run strAtCommand

objSuccess.WriteLine strComputer & " was successful"
Else
objFailed.Writeline strComputer & " is unreachable"
End If
loop



Function Pingable(strComputer,iPings,iTO)
' Needs at least WSH 5.6 and will flash a command screen
' because it uses the Exec metod
' strComputer is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used

Dim objShell,objExCmd
If iPings = "" Then
iPings = 2
End if
If iTO = "" Then
iTO = 750
End if

Set objShell = CreateObject("WScript.Shell")
Set objExCmd = objShell.Exec("ping -n " & iPings _
& " -w " & iTO & " " & strComputer)

Select Case InStr(objExCmd.StdOut.Readall,"TTL=")
Case 0 Pingable = False
Case Else Pingable = True
End Select
End Function

(in reply to jide)
 
 
Post #: 3
 
 Re: Scheduling a task with vbscript - 3/15/2005 5:49:41 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
you can also use schtasks on windows 2003/XP, this is especially handy in a domain since AT tasks only run as a local user. this code checks for a previously created task, then creates one with a random time if it doesnt already exist.

Set fso = CreateObject("Scripting.FileSystemObject")
Sub chkSched()
'checks for pre-existing tsmasr job
If Not fso.fileExists("c:\windows\tasks\jobname.job") then
'creates it if it doesnt exist
genTime
schedule = "SCHTASKS /Create /SC daily /TN jobname /TR ""program"" /ST " & runTime & " /RU username /RP ""password"""
return = WshShell.Run(schedule, 1, True)
WScript.echo schedule

If return = 0 Then
WScript.Echo "the task was successfully created"
Else
WScript.Echo "there were problems creating the task"
End If
Else
WScript.Echo "Job already exists"
End If
End Sub

random time generation,
Function genTime
Randomize ' Initialize random-number generator.
intHour = Int((6 * Rnd))
minutes = Int((59 * Rnd) + 1) ' Generate random value between 1 and 6.
If Len(minutes) = 1 Then minutes = "0" & minutes
runTime = "0" & intHour & ":" & minutes & ":00"
End Function 'genTime

(in reply to jide)
 
 
Post #: 4
 
 Re: Scheduling a task with vbscript - 3/15/2005 7:29:49 PM   
  jide

 

Posts: 5
Score: 0
Joined: 3/15/2005
From:
Status: offline
here is the code (this code can be found on many sites)


      

I've read that the "********" must be set like this. These * represent the Year, Month and Date (YYYYMMDD) but I can't change them, if I write this : "20050413133100.000000-000", the script return an error 21 (which means that I've entered bad parameters or something like this). Is there another way to schedule a task with a specific date? (we can schedule a task with a specific date the Scheduled Task Wizard, so I think that I can do this with a script...)

(in reply to jide)
 
 
Post #: 5
 
 Re: Scheduling a task with vbscript - 3/16/2005 5:13:54 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Do you want to run the task repeatedly ? In the code, you specified that the script is to be run at the day 20 of each month, and yet you set it to run only once.

Also, you can't schedule it run at a specific date, it can only be a certain day within a week, or a certain day within a month.

(in reply to jide)
 
 
Post #: 6
 
 Re: Scheduling a task with vbscript - 3/16/2005 8:13:59 AM   
  nashvillemike

 

Posts: 41
Score: 0
Joined: 1/26/2005
From:
Status: offline
I use schtasks on Windows 2000 also, but I had to change the file with a hex editor. Works perfect now. Here's the details on how to do it:

http://www.windowsitpro.com/windowsnt20002003faq/Article/ArticleID/25186/windowsnt20002003faq_25186.html

quote:
Originally posted by kirrilian

you can also use schtasks on windows 2003/XP, this is especially handy in a domain since AT tasks only run as a local user. this code checks for a previously created task, then creates one with a random time if it doesnt already exist.


(in reply to jide)
 
 
Post #: 7
 
 Re: Scheduling a task with vbscript - 3/16/2005 8:25:10 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
oh wow thanks!! that will help with one of my projects in fact :)

quote:
Originally posted by nashvillemike

I use schtasks on Windows 2000 also, but I had to change the file with a hex editor. Works perfect now. Here's the details on how to do it:

http://www.windowsitpro.com/windowsnt20002003faq/Article/ArticleID/25186/windowsnt20002003faq_25186.html

quote:
Originally posted by kirrilian

you can also use schtasks on windows 2003/XP, this is especially handy in a domain since AT tasks only run as a local user. this code checks for a previously created task, then creates one with a random time if it doesnt already exist.




(in reply to jide)
 
 
Post #: 8
 
 Re: Scheduling a task with vbscript - 3/16/2005 8:55:10 AM   
  nashvillemike

 

Posts: 41
Score: 0
Joined: 1/26/2005
From:
Status: offline
kirrilian - I'm not sure if you'll get it or not, but I emailed you the file I use so you don't have to do the editing. Maybe that will help you out.

quote:
Originally posted by kirrilian

oh wow thanks!! that will help with one of my projects in fact :)

quote:
Originally posted by nashvillemike

I use schtasks on Windows 2000 also, but I had to change the file with a hex editor. Works perfect now. Here's the details on how to do it:

http://www.windowsitpro.com/windowsnt20002003faq/Article/ArticleID/25186/windowsnt20002003faq_25186.html

quote:
Originally posted by kirrilian

you can also use schtasks on windows 2003/XP, this is especially handy in a domain since AT tasks only run as a local user. this code checks for a previously created task, then creates one with a random time if it doesnt already exist.






(in reply to jide)
 
 
Post #: 9
 
 Re: Scheduling a task with vbscript - 3/16/2005 9:13:27 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
i already did it, it wasnt that bad. i already had a hex editor, and that reshacker is pretty slick :)

(in reply to jide)
 
 
Post #: 10
 
 Re: Scheduling a task with vbscript - 4/29/2005 2:56:56 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
How can I use the initial code given to be used on a recurring basis (strStartTime = DateAdd("n",5, Now) ' Adds 60 mins to now)?

(in reply to jide)
 
 
Post #: 11
 
 Re: Scheduling a task with vbscript - 4/30/2005 8:18:43 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Again, cross-posting only wastes people's time and will not get your answser any faster.

See other posts.

http://www.visualbasicscript.com/topic.asp?TOPIC_ID=2841

(in reply to jide)
 
 
Post #: 12
 
 Re: Scheduling a task with vbscript - 4/30/2005 11:41:53 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
My fault on the cross posting. Disregard my question. It was answered on the other posting. :-)

(in reply to jide)
 
 
Post #: 13
 
 Re: Scheduling a task with vbscript - 4/30/2005 12:26:37 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Cheers :)

(in reply to jide)
 
 
Post #: 14
 
 
 
  

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 >> Scheduling a task with vbscript 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