View Single Post
Old 06-25-2009   #3 (permalink)
Cary Shultz


 
 

Re: scheduling a task and renaming it

And, if I might chime in.......

When creating the jobs with the utility schtasks (which I actually just
started doing last week) please note that you will have to use this utility
to check them.

Now, what does that mean? I *thought* that I could create the jobs with the
schtasks utility and then write a script using WMI to check
everything......STOP!!!!!

Not gonna happen! Those two (schtasks and WMI) use different APIs that do
not play so nicely. But, the good thing is that you can use schtasks to
check each server (or workstation or whatever) for *ALL* scheduled
tasks....no matter how they were created. And, a side benefit to that is
that with schtasks you will actually see the Logon Account used.....WMI does
not offer that piece of information!


"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:ummIuyY9JHA.1492@xxxxxx
Quote:

>
> "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.
>
My System SpecsSystem Spec