Solved not able to run VBScript from task scheduler

April 30, 2020 at 12:34:14
Specs: Windows 10
I have created .vbs file and trying to run through task scheduler. But it is not working. When I run vbs file manually, it works fine. However, it is not working for scheduled time.

See More: not able to run VBScript from task scheduler

Reply ↓  Report •

#1
April 30, 2020 at 13:15:08
Hi !
Can you post what did you tried as code until now ? i mean the source code of your vbscript !

Reply ↓  Report •

#2
April 30, 2020 at 16:26:42
Make sure you submit the fully-qualified path of the vbscript to the scheduler. Don't depend on "default" paths or current directory. scheduler needs exact full path. also
any files included in the vbscript should be qualified as well.

Reply ↓  Report •

#3
May 1, 2020 at 03:55:07
✔ Best Answer
@OP since you didn't provide us any code to understand your issue, here is an example posted here ==>
https://stackoverflow.com/questions...

In this vbscript you can change 4 arguments :

TaskName
AppFullPath
StartTime
Frequency

Option Explicit
Dim TaskName,AppFullPath,StartTime,Frequency
'************* Four params can be changed here********************
TaskName = "Execute Notepad by Hackoo"
AppFullPath = "C:\windows\notepad.exe"
StartTime = "10:00"
Frequency = "Minute"
REM The value of frequency can be taken 
Rem as "MINUTE", "HOURLY", "DAILY", "WEEKLY" or "MONTHLY"
REM <a href="https://technet.microsoft.com/en-us/library/bb490996.aspx" target="_blank" rel="nofollow">https://technet.microsoft.com/en-us...</a>
REM Don't change anything under this line
'************************** Main *********************************
Call CreateTask(TaskName,AppFullPath,StartTime,Frequency)
'*****************************************************************
Sub CreateTask(TaskName,AppFullPath,StartTime,Frequency)
Dim ws,strtask,exitcode
Set ws = CreateObject("Wscript.Shell")
strtask = "schtasks /create /sc "& Frequency &" /tn "& qq(TaskName) & _
          " /tr "& qq(AppFullPath) & _
          " /st " & StartTime & " /f"

exitcode = ws.Run(strtask, 0, True)

If exitcode <> 0 Then
  WScript.Echo "External command failed: " & Hex(exitcode)
Else
    wscript.echo "The Task "& qq(TaskName) & " is created successfully !"& vbcrlf &_
    "to be run "& qq(Frequency) &" with a StartTime at " & qq(StartTime) & ""
End If
End Sub
'*****************************************************************
Function qq(str)
    qq = chr(34) & str & chr(34)
End Function
'*****************************************************************


Reply ↓  Report •
Related Solutions


Ask Question