无法在Ruby中创建Outlook.Application实例

无法在Ruby中创建Outlook.Application实例,ruby,windows,outlook,win32ole,Ruby,Windows,Outlook,Win32ole,我有以下ruby脚本,在登录时可以正常工作: require 'win32ole' outlook = WIN32OLE.new('Outlook.Application') ns = outlook.GetNamespace("MAPI") ns.Logon("Outlook","password",false,true) #Here goes the code that sends the e-mail 我还有一个批处理文件,每天由计划任务运行。我登录时一切正常。当我注销Windo

我有以下ruby脚本,在登录时可以正常工作:

require 'win32ole'

outlook = WIN32OLE.new('Outlook.Application')

ns = outlook.GetNamespace("MAPI")

ns.Logon("Outlook","password",false,true)

#Here goes the code that sends the e-mail
我还有一个批处理文件,每天由计划任务运行。我登录时一切正常。当我注销Windows时,Ruby无法运行第二行代码。换句话说,无法创建“Outlook.Application”的新实例。有什么办法解决这个问题吗


我正在使用Windows Server 2003、Ruby 1.9.3和Outlook 2010。

计划任务在Windows服务的上下文中运行。服务中不能使用包括Outlook在内的Office应用程序

如果我登录到Windows,脚本将由调度程序运行,电子邮件发送时不会出现问题。当我注销时,问题就出现了。当我注销时,上下文是否更改?是的。登录后,会有一个交互式Windows会话。