Is it possible to run any type of file (like,. mp3, doc, exe..) with a Vbscript file at a specific time?
I looked in many places but there were no success..
Asked
Active
Viewed 4,285 times
0

Hackoo
- 18,337
- 3
- 40
- 70

user152435
- 113
- 2
- 7
-
2Depends on what you mean by "open". – Ansgar Wiechers Nov 05 '17 at 20:22
-
Yes, its possible. – Pankaj Jaju Nov 06 '17 at 07:40
-
You can take a look at this [Run code at specific time](http://www.tek-tips.com/viewthread.cfm?qid=1696402) – Hackoo Nov 07 '17 at 08:58
-
So, @Hackoo, which of those codes should I use? And, how to put the time I need and the file's path? And by 'open', I meant to run a file, like play an mp3, play a video, open a picture etc. – user152435 Nov 08 '17 at 11:05
-
@user152435 Check my answer ! – Hackoo Nov 09 '17 at 08:15
2 Answers
2
Give a try for this example that can schedule Notepad to be executed everyday at 10:00 AM
So, you need just to modify those 3 arguments in this script to yours :
- TaskName
- App_FullPath
- strTime
Option Explicit
Dim TaskName,App_FullPath,strTime
TaskName = "Execute_Notepad"
App_FullPath = "C:\windows\notepad.exe"
strTime = "10:00"
Call CreateTask(TaskName,App_FullPath,strTime)
'*****************************************************************
Sub CreateTask(TaskName,App_FullPath,strTime)
Dim ws,strtask,exitcode
Set ws = CreateObject("Wscript.Shell")
strtask = "schtasks /create /sc Daily /tn "& qq(TaskName) & _
" /tr "& qq(App_FullPath) & _
" /st " & strTime & " /f"
exitcode = ws.Run(strtask, 0, True)
If exitcode <> 0 Then
WScript.Echo "External command failed: " & Hex(exitcode)
Else
wscript.echo "Success !"
End If
End Sub
'*****************************************************************
Function qq(str)
qq = chr(34) & str & chr(34)
End Function
'*****************************************************************
Edit : Batch file to show or delete a numbered task names
@echo off
Mode 100,3 & color 0A
Title Delete Tasks with their time tasks execution by Hackoo 2017
:Menu
Mode 100,3 & color 0A
cls & echo(
echo Type the time with this format "hh:mm" or a task name to show or delete for scheduled Tasks
set /a "count=0"
set /p "strTime="
cls & echo(
echo Please wait a while ... looking for a scheduled Tasks for "%strTime%"
Setlocal EnableDelayedExpansion
@for /f "tokens=1 delims=," %%a in ('schtasks /query /fo csv ^| find /I "%strTime%"') do (
set /a "Count+=1"
set "TaskName[!Count!]=%%~a"
)
Rem Display numbered Task Names
Mode 90,30 & cls & echo(
@for /L %%i in (1,1,%Count%) do (
set "Task=[%%i] - !TaskName[%%i]:~1!"
echo !Task!
)
If not defined Task (
Mode 90,3 & Color 0C
echo(
echo No Scheduled Tasks found with this criteria
Timeout /T 3 /nobreak >nul & goto Menu
)
echo(
Rem Asking user if he wants to delete or not the numbered task names
echo Type the number of the task to delete !
set /p "Input="
@for /L %%i in (1,1,%Count%) Do (
If "%INPUT%" EQU "%%i" (
schtasks /delete /tn "!TaskName[%%i]:~1!"
)
)
echo(
echo Type any key to show and delete another task !
Pause>nul
Goto Menu

Hackoo
- 18,337
- 3
- 40
- 70
-
Forgive me I'm completely noob to coding, can you explain what the .bat file would do? – user152435 Nov 09 '17 at 15:53
-
@user152435 did you executed the vbscript ? and what did you get as response ? a msgbox with success or not ? if yes , the notepad will be executed everyday at 10:00 ! For the batch file is used to show or delete this task if you want when you type 10:00 ! – Hackoo Nov 10 '17 at 07:39
-
0
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 https://technet.microsoft.com/en-us/library/bb490996.aspx
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
'*****************************************************************

Hackoo
- 18,337
- 3
- 40
- 70