Windows Scheduler问题

问题描述 投票:0回答:1

我试图使用Windows Scheduler运行* .vbs脚本(下面),但没有成功。从我可以看到它是一个旨在发送电子邮件的基本脚本。当手动运行时,它运行正常。为什么这不适用于Windows Scheduler?任务开始和结束没有任何问题,但没有发送电子邮件。

Set OutApp = CreateObject("Outlook.Application")
Set outMail = OutApp.CreateItem(0)

With outMail
    .to = "[email protected]"
    .BCC = ""
    .Subject = "Test - " 
    .Recipients.ResolveAll
    .Send
End With

Set outMail = Nothing
Set OutApp = Nothing

XML for Task

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2017-09-08T14:08:04.8746028</Date>
    <Author>JOLLYES2\Kajan</Author>
  </RegistrationInfo>
  <Triggers>
    <TimeTrigger>
      <StartBoundary>2017-09-08T14:10:00</StartBoundary>
      <Enabled>true</Enabled>
    </TimeTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>JOLLYES2\Kajan</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</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>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\WTD\WTD_Test.vbs</Command>
    </Exec>
  </Actions>
</Task>
vbscript outlook scheduled-tasks scheduler
1个回答
0
投票

任务计划程序作为服务运行 - 不能从服务中使用Office应用程序(包括Outlook)。特别是如果Outlook的另一个实例已经运行--Outlook是单例,那么当您的脚本连接到已经运行的Outlook实例时,COM系统拒绝封送在不同安全上下文中运行的两个进程之间的调用。

© www.soinside.com 2019 - 2024. All rights reserved.