且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在宏VBA中将操作参数传递给SchTasks

更新时间:2022-02-04 00:49:54

请勿在家尝试...请参阅以下原因::

使用双引号-""是必需的,以便转义单引号":

The usage of double quotes - "" is needed, in order to escape the single quote ":

Sub WithParams()

    Dim command As String
    Dim wsShell As Object

    command = "schtasks /create /tn HasanChTesst /tr ""PowerShell.exe Out-File Hello.txt""  /sc weekly /d wed /st 13:00:00"
    Set wsShell = CreateObject("WScript.Shell")
    wsShell.Run (command)

End Sub

因为这样,您将需要此:

为了从预定任务中删除任务,这是代码:

And in order to remove the task from the scheduled tasks, this is the code:

Sub RemoveTask()

    Dim wsShell As Object
    Set wsShell = CreateObject("WScript.Shell")
    wsShell.Run ("powershell -noexit Unregister-ScheduledTask -TaskName ""HasanChTesst""")

End Sub