【问题标题】:can .vbs file be a scheduled script?.vbs 文件可以是预定脚本吗?
【发布时间】:2012-12-14 17:54:50
【问题描述】:

我编写了一个 .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")

谢谢,

【问题讨论】:

标签: vbscript scheduled-tasks windows-shell wsh


【解决方案1】:

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

c:\windows\system32\cscript.exe PATH_TO_YOUR_VBS

【讨论】:

  • 但是如何安排这个命令呢?它又需要手动点击右键运行吗?
  • 我刚离开task scheduler page 有点困惑,要安排任务,我需要将我的.vbs 放在C:\` drive or I can put the same to any of the full directory. And one more thing Can I do such manual settings via script,so that once any user first time RUN` .vbs 脚本中,然后.vbs 将被永远安排. - 这样我认为我们可以更多地帮助非技术人员。那么有没有?
  • 您可以将 VBS 文件放在执行计划任务的用户可访问的任何位置。您必须将 VBS 文件的完整路径传递给 cscript.exe。如果你想让你的脚本作为计划任务自动安装,那将涉及更多。如果您扩展您的原始问题以描述您的脚本的什么以及为什么,您可能会得到其他解决方案,这些解决方案采用更合适的不同方法。
  • 这根本没有帮助。您没有解释(文字,而不是代码)什么任务需要完成 - 只是必须运行一组脚本。
【解决方案2】:

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

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

【讨论】:

  • 我希望用户可以通过以下方式提示用户 - 他们会按计划喜欢这个 .vbs 文件(任务)还是希望每次都手动运行?根据他们的反应,脚本的行为将被确定。
  • 取决于你在做什么。我的大部分 VBS 工作都是在服务器上进行的,并且有时在无人时运行。如果有人在那里,我想你可以使用提示...只要知道在有人与提示交互之前代码不会完成(根据您的要求,这可能是您想要的,也可能不是您想要的)。跨度>
  • 我能有这样的代码供您使用吗?或者您也可以edit我的代码?
【解决方案3】:

在 Windows 8 上:触发具有消息框的 VBScript 的 Windows 任务将仅在 Windows 任务在真正登录机器的同一用户下运行并且如果 Windows 任务配置为“运行”时显示消息框仅当用户登录时” 我认为这在 Windows 8 上发生了变化,因为在 Windows 7 上我不必以这种方式配置任务

【讨论】:

    【解决方案4】:

    试试这个

    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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多