Recurring Message Box VbScript

2

1

I have a vbs file whose content is :

MsgBox "some thing here",vbOkOnly,"some other thing"

I have set it to run periodically using Windows Scheduler. It indeed is running periodically (which i verified by looking at the processes in task manager). Also when i double click the vbs file it shows up.

Problem:

I am not getting the message box. i.e the message box doesn't appear at all.

Note: I don't know vbs.

rimalonfire

Posted 2020-01-24T07:50:01.357

Reputation: 121

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

Answers

1

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.

Hackoo

Posted 2020-01-24T07:50:01.357

Reputation: 589