billymcqueary
asked on
adding a task to scheduled tasks with a .vbs logon script that calls another .vbs file locally
This is the code I'm using now to test adding a scheduled task to a users system. I tested it by running the script manually to add it to schedule tasks and also adding it to their logon script. Both seem to give me the same result, at the scheduled time it says that it runs but nothing happens. When I manually execute the outlookpstbackup.vbs file it works fine. Also all the options on the task are greyed out if that makes a difference. Any ideas?
Option Explicit
Dim oShell, currentOS
Set oShell = CreateObject("WScript.Shel l")
Dim objService, objNewJob, JobID, errJobCreated, objShell, objFolder, objFolderItem, strComputer, objWMIService, colDisks, objDisk, defragHour
Const system32_folder = &H25&
set objShell = CreateObject("Shell.Applic ation")
set objFolder = objShell.Namespace(system3 2_folder)
Set objFolderItem = objFolder.Self
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk")
Set objNewJob = objWMIService.Get("Win32_S cheduledJo b")
errJobCreated = objNewJob.Create("c:\outlo okpstbacku p.vbs", "********064500.000000-360 ", True, 1 or 2 or 4 or 8 or 16, , , JobID)
If errJobCreated <> 0 Then
Wscript.Echo "Error on task creation"
Else
Wscript.Echo "Task created: " & JobID
End If
wscript.quit
Option Explicit
Dim oShell, currentOS
Set oShell = CreateObject("WScript.Shel
Dim objService, objNewJob, JobID, errJobCreated, objShell, objFolder, objFolderItem, strComputer, objWMIService, colDisks, objDisk, defragHour
Const system32_folder = &H25&
set objShell = CreateObject("Shell.Applic
set objFolder = objShell.Namespace(system3
Set objFolderItem = objFolder.Self
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk")
Set objNewJob = objWMIService.Get("Win32_S
errJobCreated = objNewJob.Create("c:\outlo
If errJobCreated <> 0 Then
Wscript.Echo "Error on task creation"
Else
Wscript.Echo "Task created: " & JobID
End If
wscript.quit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.