I'm evaluating Advanced Installer for a purchase. I'm adding a program to the scheduled task and its working as expected. However, I need to add a delay on start-up. Any one is successful?
Unfortunately, we don't have predefined support to specify a delay for the created scheduled tasks. However, as a workaround you can create an EXE wrapper over your application, which will launch the application with a desired delay. Then, you can create the scheduled task for the EXE wrapper.
Here are two vbscript that I use to create and remove schelued task.
Here is the code I use to Create a scheduled task:
'==========================================================================
'
'
'
' Name: Create Scheduled task
'
'==========================================================================
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
("SELECT * FROM Win32_ScheduledJob")
For Each objJob in colScheduledJobs
If objJob.Command ="c:\MY EXE.exe" Then
WScript.Quit
End If
Next
RUN_REPEATEDLY =False
'DaysOfMonth = 32 Or 128
InteractWithUser =True
'
heure = Right (Now + TimeSerial (00,03,00)+ TimeSerial (-01,00,00),8) 'détermine l'écart de temps à ajouter heures, minutes, secondes ** determines the time difference to add hours, minutes, seconds
'heure = Time + TimeSerial (00,30,00) 'détermine l'écart de temps à ajouter heures, minutes, secondes ** determines the time difference to add hours, minutes, seconds
'heure = heure + TimeSerial (-01,00,00) 'ajustement heure avancé ** Daylight time adjustment
heure = Replace (heure, ":","")
'==========================================================================
'
'
' NAME: Remove Scheduled task
'
'==========================================================================
'Replace "PATH TO THE EXE\MY EXE.exe" below with the appropriate info to identify the scheled task to delete
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
("SELECT * FROM Win32_ScheduledJob")
For Each objJob in colScheduledJobs
If objJob.Command ="PATH TO THE EXE\MY EXE.exe" Then
JobNumber = objJob.JobID
strComputer = "."
Set objService = GetObject("winmgmts:\\" & strComputer)
Set objInstance = objService.Get("Win32_ScheduledJob.JobID=" & JobNumber )
objInstance.Delete
End If
Next