[RESOLVED] Scheduled Task "Could Not Start"
Hi
Ive written some code that basically creates a scheduled task on a load of remote machines.
This is the code that im using
Code:
Dim strTime As String
Dim strDate() As String
Dim vntWeek() As Variant
Dim intCounter As Integer
Dim intWeekCounter As Integer
Dim strdyz As String
strdyz = "M,T,W,TH,F,S,SU"
vntWeek = Array("M", "T", "W", "TH", "F", "S", "SU")
With udtAtInfo
' Change the format of the time
strTime = Format("00:10", "hh:mm")
' Change the time to one used by the api
.JobTime = (Hour(strTime) * 3600 + Minute(strTime) * 60) * 1000
' Set the Date parameters
If Val(strdyz) > 0 Then
' Set the task to run on specific days of the month i.e. 9th & 22nd of the month
strDate = Split(strdyz, ",")
For intCounter = 0 To UBound(strDate)
.DaysOfMonth = .DaysOfMonth + 2 ^ (strDate(intCounter) - 1)
Next
Else
' Set the task to run on sepecific days of the week i.e. Monday & Thursday
strDate = Split(strdyz, ",")
For intCounter = 0 To UBound(strDate)
For intWeekCounter = 0 To UBound(vntWeek)
If UCase(strDate(intCounter)) = vntWeek(intWeekCounter) Then
.DaysOfWeek = .DaysOfWeek + 2 ^ intWeekCounter
Exit For
End If
Next
Next
End If
' Set the interactive property
'If Check1.Value = vbUnchecked Then
.Flags = .Flags Or JOB_NONINTERACTIVE
'End If
' Set to run periodically
'If Option2.Value = True Then
.Flags = .Flags Or JOB_RUN_PERIODICALLY
'End If
' Set the command to run
.Command = StrConv("MyApp.exe", vbUnicode)
End With
now if I set it to run Notepad it all works fine but if I set it to open up a VB6 App Ive created it just comes up with "Could Not Start" in the schedule list? Now its finding the app as it is setting the Scheduled Items Icon to the Apps Icon but it just won't run!
Am I missing something really stupid on this one?
Re: Scheduled Task "Could Not Start"
It is rarely wise to specify a file name without also specifying the full path to it, because it is likely to fail in some way (even if it has worked before), and the likelihood of that happening depends on the circumstances.
This is one of the cases where leaving out the path virtually guarantees failure.
Re: Scheduled Task "Could Not Start"
yeh the full path was there and it wasn't working but I think I may have figured it out.
I have moved the file to be run, to the root of C and it seems to work when I put the full file path in. I think the problem may have actually been that It was originally being run from a folder with spaces in the folder name and that is where the problem was.
im gonna look into it and see if that was the problem just to be sure.
Re: Scheduled Task "Could Not Start"
OK Just tried it and it always errors when there is a space in the folder name.
Well that was annoying
Re: Scheduled Task "Could Not Start"
Quote:
Originally Posted by
ooKmonkey
yeh the full path was there ...
It wasn't in your code above, which is all we have to go on.
Quote:
OK Just tried it and it always errors when there is a space in the folder name.
If we'd seen the actual code we may have spotted that.
The simplest solution is to simply put the file+path name inside quotes, eg:
Code:
strApp = """C:\path with spaces\MyApp.exe"""
If that doesn't work, you will need to get the short version of the file name instead.