Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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 :)
|
|
| |
|
|
|
|
|