Unable to automate sending of email from remote Windows 10 desktop at startup (via Task Scheduler)

huangapple go评论67阅读模式
英文:

Unable to automate sending of email from remote Windows 10 desktop at startup (via Task Scheduler)

问题

当 Windows 10 远程桌面重新启动时,任务计划程序(设置为在用户登录或不登录时执行)会保存一个文件并发送一封(空)电子邮件。

重新启动后电子邮件发送不起作用。仅在手动启动或由任务计划程序触发时才起作用。

我怀疑这与机器重新启动时的状态有关 - 它从未真正恢复用户会话。这可能与防止无人参与会话有关吗?

我曾认为可以通过自动登录来解决这个问题。但根据 https://learn.microsoft.com/en-us/troubleshoot/windows-server/user-profiles-and-logon/turn-on-automatic-logon 修改注册表并没有起作用,它原则上暴露了凭据 - 该桌面由多个用户使用。

编辑:示例 Python 代码,当从任务计划程序手动启动时可以工作,但在启动时由任务计划程序启动时无法工作。

import win32com.client as win32
from datetime import datetime

o = win32.dynamic.Dispatch('Outlook.Application')
Msg = o.CreateItem(0)
Msg.To = "name@mail.com"
Msg.Subject = datetime.now().strftime('%Y%m%d-%H%M%S')
Msg.Send()
英文:

When Windows 10 remote desktop is rebooted, Task Scheduler (set up for execution when user is logged on or not) saves a file and sends an (empty) email.

The email sending does not work after reboot. It works only when launched manually or triggered by user from Task Scheduler.

I suspect it is related to state into which the machine is rebooted - it never really recovers user session. Could it be related to control against unattended sessions? https://support.microsoft.com/en-us/topic/considerations-for-server-side-automation-of-office-48bcfe93-8a89-47f1-0bce-017433ad79e2

I thought it can be be worked around by automated logon. Modifying the registries following https://learn.microsoft.com/en-us/troubleshoot/windows-server/user-profiles-and-logon/turn-on-automatic-logon however did not work and it in principle exposes credentials - desktop is used by several users.

Edit: sample python code which works when launched manually from Task Scheduler but not when launched by Task Scheduler at startup.

import win32com.client as win32
from datetime import datetime

o = win32.dynamic.Dispatch('Outlook.Application')
Msg = o.CreateItem(0)
Msg.To = "name@mail.com"
Msg.Subject = datetime.now().strftime('%Y%m%d-%H%M%S')
Msg.Send()

答案1

得分: 1

Task Scheduler 是一个服务,而 Outlook 无法从服务中使用,即使用户身份是交互用户的身份。Outlook 需要一个具有配置的 Outlook 配置文件的本地用户已登录。

英文:

Task Scheduler is a service, and Outlook cannot be used from a service, even if the user identity is that of an interactive user. Outlook needs a local user with configured Outlook profile to be logged in.

huangapple
  • 本文由 发表于 2023年5月10日 18:37:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217394.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定