是否可以在特定时间使用Vbscript文件运行任何类型的文件(例如,。mp3,doc,exe ..)? 我看了很多地方,但没有成功..
答案 0 :(得分:1)
试试这个可以安排记事本每天上午10点执行的例子
因此,您只需将此脚本中的3个参数修改为您的:
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
'*****************************************************************
编辑:用于显示或删除编号的任务名称的批处理文件
@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
答案 1 :(得分:0)
在这个vbscript中你可以改变4个参数:
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
'*****************************************************************