Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista Tutorial - scheduling a task and renaming it

Reply
 
Old 06-25-2009   #1 (permalink)
Mr L
Guest


 
 

scheduling a task and renaming it

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



My System SpecsSystem Spec
Old 06-25-2009   #2 (permalink)
Pegasus [MVP]
Guest


 
 

Re: scheduling a task and renaming it


"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
Old 06-25-2009   #3 (permalink)
Cary Shultz
Guest


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
window scheduling Vista General
scheduling script PowerShell
corrupted scheduled task after renaming machine Vista General
Scheduling Tasks vs UAC Vista security
SyncToy Scheduling Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46