转换脚本以允许按计划任务运行

时间:2013-12-30 17:17:31

标签: vbscript scheduled-tasks

我一段时间写了一篇VBScript,让任务变得更容易。它工作,但它不会作为计划任务运行,因为它需要一个命令窗口进行交互。如何更改脚本以允许它作为计划任务运行?

dim filesys
Set objShell = WScript.CreateObject("WScript.Shell")
set filesys=CreateObject("Scripting.FileSystemObject") 

WScript.Sleep 2000  
objShell.SendKeys"dsdbutil"  
WScript.Sleep 2000 
objShell.SendKeys("{Enter}")  
WScript.Sleep 2000 
objShell.SendKeys("activate instance wap")
WScript.Sleep 2000 
objShell.SendKeys("{Enter}")
WScript.Sleep 2000 
objShell.SendKeys("ifm")
WScript.Sleep 2000 
objShell.SendKeys("{Enter}")
WScript.Sleep 2000 
objShell.SendKeys("create full c:\adldsbackup")
WScript.Sleep 2000 
objShell.SendKeys("{Enter}")
WScript.Sleep 30000 
objShell.SendKeys("quit")
WScript.Sleep 2000 
objShell.SendKeys("{Enter}")
WScript.Sleep 2000 
objShell.SendKeys("quit")
WScript.Sleep 2000 
objShell.SendKeys("{Enter}")
WScript.Sleep 2000 


filesys.MoveFile "c:\adldsbackup\adamntds.dit", "\\vash\ibts_ts\Networking\Backups\ADLDS\adamntds_" & DatePart("m",Now()) & "_" & DatePart("d",Now()) & "_" & DatePart("YYYY",Now()) & ".dit"

objShell.SendKeys("exit")
WScript.Sleep 2000 
objShell.SendKeys("{Enter}")

1 个答案:

答案 0 :(得分:0)

我做了类似的事情,安排了一个vbs。解决方案很简单!

创建批处理文件以运行vbs文件并安排此批处理文件。我更喜欢在批处理文件中使用cscript:

cscript.exe //nologo <ScriptNameWithFullPath>