"Mr L" <l@xxxxxx> wrote in message
news:OCJjOtX9JHA.4560@xxxxxx
Quote:
> Hi
>
> I need to script a scheduled task on a number of servers, and would like
> to give it an easy to understand name. But, by default they're given a
> name on the form at1 or at2 etc. How can this easilly be achieved?
>
> The script I'm using is as follows:
>
> Dim strComputer
> Dim args
>
> Set args = Wscript.Arguments
> strComputer = args.Item("0")
>
> If (strComputer = "") then
> Usage
> Else
> Sheduler
> End if
>
> sub sheduler (strComputer)
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> JobID = "PendingInfoCheck"
>
> Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
>
> errJobCreated = objNewJob.Create _
> ("C:\config\PendingInfo\PendingInfoV3.vbs",
> "********040000.000000-000", _
> True , 1 OR 2 OR 4 OR 8 OR 16 OR 32 OR 64, , , JobID)
> Wscript.Echo errJobCreated
>
> End sub
>
I suspect that there is no option to name your jobs when you use the the
WMIService object. You can get around the problem by using schtasks.exe
instead. It has a very rich set of switches. Note also the following:
- Your code uses the line
strComputer = args.Item("0").
To make the code robust, you could change it to
if args.count = 0 then Usage
or perhaps to:
If WScript.Arguments.Count = 0 then Usage
strComputer = WScript.Arguments(0)
Otherwise the program will terminate with an error message when no
parameter is supplied.
- There is a problem with your subroutine parameter count. First you write
Else
Sheduler
End If
and then you write
Sub sheduler (strComputer)
I suspect you know this already, which leads to another recommendation:
When posting code, only post what you have previously tested. This avoids
posting code with obvious errors.