不幸的是,我无法找到适用于其他线程的解决方案。
我正在尝试通过批处理文件使用任务调度程序运行vb脚本,当我手动启动它们时,vbs和bat文件都工作正常,但在任务计划程序中却没有。我尝试了多种组合(我也尝试直接启动vbs)但似乎没有任何效果。 .bat和.vbs都直接在C:\
中VBS文件:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set Word = CreateObject("Word.Application")
Set Tasks = Word.Tasks
For Each Task in Tasks
If Task.Visible Then
if inStr(Task.name, "(Formal module) - DOORS") then
WshShell.AppActivate Task.name
WshShell.SendKeys "^s"
WScript.Sleep 2000
WshShell.SendKeys "%e"
WScript.Sleep 200
WshShell.SendKeys "e"
WScript.Sleep 200
WshShell.SendKeys "r"
WScript.Sleep 200
WshShell.SendKeys "%e"
WScript.Sleep 100
WshShell.SendKeys "e"
WScript.Sleep 100
WshShell.SendKeys "r"
WScript.Sleep 100
Else
End If
End If
Next
Word.Quit
Set Word = CreateObject("Word.Application")
Set Tasks = Word.Tasks
For Each Task in Tasks
If Task.Visible Then
if inStr(Task.name, "(Formal module) - DOORS") then
WshShell.AppActivate Task.name
WshShell.SendKeys "^s"
WScript.Sleep 2000
WshShell.SendKeys "%e"
WScript.Sleep 200
WshShell.SendKeys "e"
WScript.Sleep 200
WshShell.SendKeys "r"
WScript.Sleep 200
WshShell.SendKeys "%e"
WScript.Sleep 100
WshShell.SendKeys "e"
WScript.Sleep 100
WshShell.SendKeys "r"
WScript.Sleep 100
Else
End If
End If
Next
Word.Quit
批处理文件:
%windir%\SysWoW64\cmd.exe /C "c:\windows\system32\cscript.exe //B //nologo C:\unlock_doors.vbs"
预定的Tesk导出:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2017-04-04T12:38:00.000</Date>
<Author>CCANET\tczimmer</Author>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2017-04-04T00:00:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>CCANET\tczimmer</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
<RestartOnFailure>
<Interval>PT5M</Interval>
<Count>2</Count>
</RestartOnFailure>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\unlock_doors.bat</Command>
<WorkingDirectory>C:\</WorkingDirectory>
</Exec>
</Actions>
</Task>
答案 0 :(得分:0)
我有一个类似的问题,任务调度程序只是不会执行我的vbs。我所做的是创建一个单独的&#34; timer.vbs&#34;具有无限循环的文件检查它到达早上6点的时间它将执行我的脚本。所以你在这里有几个选项,但在你的情况下,为了你不必重写任何代码,你可以创建一个timer.vbs文件,仍然在c:\ root中这样
'timer.vbs
Set objShell = Wscript.CreateObject("Wscript.Shell")
Do
Wscript.Sleep 1000
If Time() = TimeValue("12:00:01 AM") Then 'Or modify to the time you need
objShell.Run "c:\windows\system32\cscript.exe /B /nologo C:\unlock_doors.vbs"
End If
Loop
只要此脚本在打开的主机上运行,它就应该在指定的TimeValue上执行。
因此,基本上打开一个cmd提示符并在该命令提示符下运行cscript timer.vbs
并最小化该ommand提示符并继续执行该主机的正常操作。