2017-04-04 1 views
1

Malheureusement, je n'ai pas trouvé de solution qui a fonctionné pour moi dans d'autres threads. J'essaie d'exécuter un script vb à l'aide du planificateur de tâches via un fichier de commandes, les fichiers vbs et bat fonctionnent parfaitement lorsque je les démarre manuellement, mais pas dans le planificateur de tâches. J'ai essayé plusieurs combinaisons (j'ai aussi essayé de démarrer les vbs directement) mais rien ne semble fonctionner. Les deux .bat et .vbs sont directement dans C: \Lancer le script vbs dans le planificateur de tâches en utilisant un fichier batch

fichier 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 

fichier batch:

%windir%\SysWoW64\cmd.exe /C "c:\windows\system32\cscript.exe //B //nologo C:\unlock_doors.vbs" 

exportation Tesk prévue:

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

Vous exécutez la tâche planifiée en arrière-plan? Si tel est le cas, je suis certain que 'SendKeys' ne fonctionnera pas, car il envoie les frappes à la fenêtre active (premier plan). –

Répondre

0

J'ai eu un problème similaire où le planificateur de tâches n'exécuterait tout simplement pas mon vbs. Ce que j'ai fait était de créer un fichier séparé "timer.vbs" qui avait une boucle infinie en vérifiant à quelle heure il était quand il a atteint 6:00 du matin il exécuterait mon script. Vous avez donc quelques options ici, mais dans votre cas, pour que vous n'ayez à réécrire aucun code, vous pouvez probablement créer un fichier timer.vbs, toujours dans le répertoire c: \ root en tant que tel

'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 

Tant que ce script s'exécute sur un hôte activé, il doit s'exécuter à la valeur TimeValue spécifiée. Donc, fondamentalement, ouvrez une invite cmd et exécutez cscript timer.vbs dans cette invite de commande et minimisez cette invite ommand et effectuez vos opérations normales avec cet hôte.