I am trying to create a scheduled task. My objective is to be able to pass the command, start time and days to execute as variables to a sub that builds the task. Below demonstrates what I am doing and in this case just passes the start time as a string. Problem is it keeps failing with error [red]SWbemObjectEx: Type mismatch[/red].
Inserting the same text that the function returns as a string it works. Can anyone spot what I am doing wrong here?
I hope you find this post helpful.
Regards,
Mark
Check out my scripting solutions at
Inserting the same text that the function returns as a string it works. Can anyone spot what I am doing wrong here?
Code:
StartTime = "2400"
StartString = StartTxt(StartTime)
BuildTask(StartString)
Sub BuildTask(StartString)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
("Notepad.exe", StartString, _
False , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated
End Sub
Function StartTxt(StartTime)
'First get the systems time bias
strComputer = "."
wmiQuery = "Select * from Win32_TimeZone"
Set objWMIService = GetObject("winmgmts:\\" & _
strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery(wmiQuery)
For Each objItem in colItems
TimeBias = objItem.Bias
Next
'Now build the time string
StartTxt = Chr(34)& "********" & StartTime & "00.000000" & TimeBias & Chr(34)
End Function
I hope you find this post helpful.
Regards,
Mark
Check out my scripting solutions at