2017-04-04 30 views
1

残念ながら、他のスレッドではうまくいきませんでした。バッチファイルを使用してタスクスケジューラでvbsスクリプトを起動します。

タスクスケジューラを使用してバッチファイルでvbスクリプトを実行しようとしていますが、vbsファイルとbatファイルは両方とも手動で起動してもタスクスケジューラではうまく動作しません。私は複数の組み合わせを試しました(私はまた、直接vbsを開始しようとしましたが)何も動作するようです。 .BATと.VBSの両方がCに直接、次のとおりです。

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" 

スケジュールテスクエクスポート:

VBSファイル\

<?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

スケジュールされたタスクをバックグラウンドで実行していますか?もしそうなら、 'SendKeys'は、キーストロークをアクティブな(フォアグラウンド)ウィンドウに送るので、私はかなり確信しています。 –

答えて

0

私はタスクスケジューラが自分のvbsを実行しない同様の問題がありました。私がしたのは、スクリプトを実行する午前6時になったときに何時になったかを無限ループでチェックしていた、別々の "timer.vbs"ファイルを作成することでした。だからここにいくつかのオプションがありますが、コードを書き直す必要がないようにするには、おそらくc:\ rootにあるtimer.vbsファイルを

'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で実行する必要があります。

基本的には、コマンドプロンプトを開き、コマンドプロンプトでcscript timer.vbsを実行し、そのプロンプトを最小限に抑えて、そのホストで通常の操作を行ってください。

関連する問題