![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||