Run any file with vbs at a specific time

后端 未结 2 1364
日久生厌
日久生厌 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条回答
  •  遥遥无期
    2021-01-17 03:50

    In this vbscript you can change 4 arguments :

    1. TaskName
    2. AppFullPath
    3. StartTime
    4. 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
    '*****************************************************************
    

提交回复
热议问题