可以.vbs文件是一个预定的脚本?

时间:2012-12-29 23:39:10

标签: vbscript scheduled-tasks windows-shell wsh

我编写了一个.vbs脚本,目前由用户手动运行。如何在第一次手动执行Windows XP和Windows 7时,在任务计划程序中自动安排此脚本(自动每天在固定时间运行)?

修改

    Option Explicit

    Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
    Dim FSO : set FSO = CreateObject("Scripting.FileSystemObject") 
    Dim StartTime,Elapsed 

    'msgBox(oShell.CurrentDirectory)
    'MsgBox(FSO.GetFile(Wscript.ScriptFullName).ParentFolder )
    oShell.CurrentDirectory = FSO.GetFile(Wscript.ScriptFullName).ParentFolder

    StartTime = Timer

    oShell.run "ParentChildLinkFinal.vbs", 1, True
    oShell.run "Parent_Child_Merge_final.vbs", 1, True
    oShell.run "CycleTime.vbs", 1, True
    oShell.run "Baddata.vbs", 1, True
    oShell.run "Matrixrefresh.vbs", 1, True

    Elapsed = Timer - StartTime

    MsgBox("Total time taken to finish this task:" & Elapsed & "in Seconds")

谢谢,

4 个答案:

答案 0 :(得分:2)

创建计划任务以运行以下命令:

c:\windows\system32\cscript.exe PATH_TO_YOUR_VBS

答案 1 :(得分:0)

您当然可以将vbs文件作为计划任务。

但需要注意的是,您希望没有提示用户......没有输入,没有消息框,什么都没有。确保你已经处理并记录了你的异常,或者你发现自己的任务永远不会完成(或者更糟糕的是,由于凌晨3点弹出了一个消息框并停止了生产过程,因此操作会愤怒地打电话给你)

答案 2 :(得分:0)

在Windows 8上的

:触发带有消息框的VBScripts的Windows任务只有在Windows任务在真正登录到计算机的同一用户下运行且Windows任务配置为“运行”时才会显示消息框仅当用户登录时“ 我认为这在Windows 8上有所改变,就像在Windows 7上我没有必要以这种方式配置任务

答案 3 :(得分:-3)

试试这个

X=MsgBox("Take the Quiz!")

name=inputbox("Name")

q1=inputbox("Question 1 - How many days are there in a leap Year?")

q2=inputbox("Question 2 - How many Suns does Neptune have?")

q3=inputbox("Question 3 - What is your name?")

q4=inputbox("Question 4 - What did one computer say to the other?")

q5=inputbox("Question 5 - Why did the chicken cross the road?")

msgbox("Answers!")

msgbox("Q1 - How many days are there in a leap Year?, you answered ") + q1 + (" ,the correct answer is 366")

msgbox("Q2 - How many Suns does Neptune have?, you answered ") + q2 + (" ,the correct answere is one, our sun.")

msgbox("Q3 - What is your name?, you answered ") + q3 + (", the correct answer is ") + name + (" or is it?")

msgbox("Q4 - What did one computer say to the other?, you answered ") + q4 + (", the correct answer is, 011100110111010101110000 (Binary code for sup)")

msgbox("Q5 - Why did the chicken cross the road?, you answered ") + q5 + (", the correct answer is To get to the other side")

msgbox("Well done, ") + name + (" you have completed the quiz")