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 - Rename schedule task

Reply
 
Old 03-14-2009   #1 (permalink)
Alesandro


 
 

Rename schedule task

Hi,

when creating a scheduled task with vbscript is there a way to give it a
name without having the system assign it a generic name ATx?


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objNewJob = objWMIService.Get("Win32_ScheduledJob")

errJobCreated = objNewJob.Create _
("Defrag.exe c: -f", "********010000.000000-420", _
True , cntSam, , ,1)
If errJobCreated <> 0 Then
MsgBox "Error"
Else
MsgBox "Succes"
End If


My System SpecsSystem Spec
Old 03-14-2009   #2 (permalink)
James Whitlow


 
 

Re: Rename schedule task

"Alesandro" <Alesandro@xxxxxx> wrote in message
news:5CDCC218-F144-43A5-BC29-83DF98CB9B42@xxxxxx
Quote:

> Hi,
>
> when creating a scheduled task with vbscript is there a way to give it a
> name without having the system assign it a generic name ATx?
>
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
>
> errJobCreated = objNewJob.Create _
> ("Defrag.exe c: -f", "********010000.000000-420", _
> True , cntSam, , ,1)
> If errJobCreated <> 0 Then
> MsgBox "Error"
> Else
> MsgBox "Succes"
> End If
I don't think (but not certain) this can be done with WMI. You can shell
out to 'schtasks.exe', though:

sTaskName = "Defrag C"
Set oWSH = CreateObject("WScript.Shell")
iRtn = oWSH.Run("schtasks.exe /Create /TN """ & sTaskName _
& """ /RU System /ST 02:00:00 /SC Once /TR ""Defrag.exe c: -f""", 0, True)
If iRtn = 0 Then
MsgBox "Succes"
Else
MsgBox "Error"
End If


My System SpecsSystem Spec
Old 03-14-2009   #3 (permalink)
Alesandro


 
 

Re: Rename schedule task

Thank you for the answer James.

It's ashame it possibly can't be done through full vbscript. I didn't want
to call an external program but anyhow, the code you provided works and
that's what counts


"James Whitlow" wrote:
Quote:

> "Alesandro" <Alesandro@xxxxxx> wrote in message
> news:5CDCC218-F144-43A5-BC29-83DF98CB9B42@xxxxxx
Quote:

> > Hi,
> >
> > when creating a scheduled task with vbscript is there a way to give it a
> > name without having the system assign it a generic name ATx?
> >
> >
> > strComputer = "."
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> >
> > Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
> >
> > errJobCreated = objNewJob.Create _
> > ("Defrag.exe c: -f", "********010000.000000-420", _
> > True , cntSam, , ,1)
> > If errJobCreated <> 0 Then
> > MsgBox "Error"
> > Else
> > MsgBox "Succes"
> > End If
>
> I don't think (but not certain) this can be done with WMI. You can shell
> out to 'schtasks.exe', though:
>
> sTaskName = "Defrag C"
> Set oWSH = CreateObject("WScript.Shell")
> iRtn = oWSH.Run("schtasks.exe /Create /TN """ & sTaskName _
> & """ /RU System /ST 02:00:00 /SC Once /TR ""Defrag.exe c: -f""", 0, True)
> If iRtn = 0 Then
> MsgBox "Succes"
> Else
> MsgBox "Error"
> End If
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Pulling out Remote Schedule Task PowerShell
Schedule a task with Vista task Scheduler wakes up computer and mo Vista General
schedule a task with WMI? PowerShell
Schedule Task Vista performance & maintenance
schedule task in powershell PowerShell


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