Run any file with vbs at a specific time

后端 未结 2 1351
日久生厌
日久生厌 2021-01-17 03:12

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..

2条回答
  •  -上瘾入骨i
    2021-01-17 03:49

    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 :

    1. TaskName
    2. App_FullPath
    3. 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
    

提交回复
热议问题