You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已登录用户状态下,Windows任务计划程序无法运行VBScript通过Outlook发邮件

问题:任务计划程序运行Outlook VBS脚本挂起

我已查阅相关讨论并尝试所有建议方案,当前需求是通过Windows任务计划程序运行VBScript脚本,实现用Outlook发送带附件的邮件。该脚本在命令提示符、批处理文件中直接运行或双击执行均正常,但在任务计划程序中执行时出现挂起。

相关代码

Email-9Y.vbs

On Error Resume Next

AutoEmail

Sub AutoEmail()

    'config variable
    email = "email@dsaw.com"
    name = "Test"
    subject = "9Y Recon"
    docName = "9Y.xlsx"
    docAddress = "F:\Apps\Scripts\Recon 9Y\"
    
    
    ' create outlook app and account object
    Set xOutApp = CreateObject("Outlook.Application")
    ' create mail item
    Set xOutMail = xOutApp.CreateItem(0)
    'construct the mail item
    With xOutMail
        .to = email
        .CC = ""
        .BCC = ""
        .subject = subject
        .BodyFormat = 2
    '.Textbody = "Test"
        '.HTMLBody = GetHTMLBody(name, "document", phone, docName, inq)
        .SentOnBehalfOfName = "email@dsaw.com"
        .Attachments.Add docAddress & docName
        '.display
        .Send
        End With
End Sub

email.bat

wscript.exe "%~dp0Email-9Y.vbs" >> "%~dp0log.txt"
exit

已尝试的操作

  • 操作系统为Windows 10,已勾选任务计划程序中的“仅当用户登录时运行”和“使用最高权限运行”选项
  • 分别尝试使用cscript和wscript执行脚本
  • 手动创建了文件夹C:\Windows\System32\config\systemprofile\Desktop和C:\Windows\SysWOW64\config\systemprofile\Desktop
  • 尝试通过命令cmd /c start cscript //nologo "W:\Pathto with spaces\VBScript.vbs"执行脚本

内容的提问来源于stack exchange,提问作者Bernhard Moser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 01:08:21