If you want to create a scheduled task with a vbscript, you must first execute it as administrator.
You can make something like that to create a vbscript scheduled task that will run every hour for example :
Option Explicit
Dim FilePath,TaskName,Repeat_Task
'Run this vbscript as Admin
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute DblQuote(WScript.FullName) _
, DblQuote(WScript.ScriptFullName) & " /elevate", "", "runas", 1
WScript.Quit
End If
FilePath = WScript.ScriptFullName
TaskName = "MyTask"
Repeat_Task = 60 '60 minutes = 1 Hour
Call Create_Schedule_Task(Repeat_Task,TaskName,FilePath)
MsgBox "some thing here that be repeated every hour !",vbInformation,"some other thing"
'-------------------------------------------------------------------------
Sub Create_Schedule_Task(Repeat_Task,TaskName,FilePath)
Dim Ws,Task,Result
Set Ws = CreateObject("WScript.Shell")
Task = "CMD /C Schtasks /Create /SC DAILY /ST 08:00 /F /RI "&_
Repeat_Task &" /DU 24:00 /TN "& TaskName &" /TR "& FilePath &""
Result = Ws.run(Task,0,True)
End Sub
'-------------------------------------------------------------------------
Function Dblquote(str)
Dblquote = chr(34) & str & chr(34)
End Function
'-------------------------------------------------------------------------
And if you want to check if your task is created successfully, you should open a command line and type this command :
schtasks /query /tn "MyTask"
where MyTask
is the name that you set it before in the vbscript above.
try using this instead MsgBox "some thing here",vbSystemModal,"some other thing" – SQLTemp – 2020-01-24T08:12:45.597
what user is it running as when scheduled? – Smock – 2020-01-24T14:30:12.143
the same user who created it – rimalonfire – 2020-01-24T14:48:01.110
Only programs run with the setting Run Only When User Logged In will be visible. You may not interrupt the logged on user with other stuff. – Mark – 2020-01-26T04:00:42.797