使用Python检查Outlook是否已打开(如果尚未打开) [英] Check with Python if Outlook is already open, if not open it
问题描述
我写了一个Python脚本,该脚本经常通过Outlook发送邮件.问题是,如果我没有打开Outlook,将不会发送任何邮件. (我使用Outlook 2013) 现在,我想检查脚本的开头是否已打开Outlook,否则请使用python打开它以避免错误.
I wrote a python script which often sends mails via Outlook. The problem is if I don't have Outlook open, no mails will be send. (I use Outlook 2013) Now I want to check at the beginning of my script if Outlook is already open, and if not I want to open it with python to avoid the errors.
如何检查Outlook是否已通过Python 2.7运行?要启动Outlook,我将使用简单的代码:
How do I check if Outlook is already running via Python 2.7 ? To start Outlook I would use the simple code:
import os
os.startfile("outlook")
感谢您的帮助!
推荐答案
由于OP要求检查Outlook,因此我猜测这是针对Windows而非Unix的.以前在另一个问题中已解决了该问题您可以找到更多详细信息.
Since the OP asks about checking for Outlook, i'm guessing this is for windows and not unix. The issue has been covered before in another question where you can find further details.
我尝试了以下代码段,该代码段在python 3.4上运行良好.我只需要通过pip install pypiwin32
安装win32软件包.
I have tried the following snippet which works fine on python 3.4. I only had to install the win32 package via pip install pypiwin32
.
def outlook_is_running():
import win32ui
try:
win32ui.FindWindow(None, "Microsoft Outlook")
return True
except win32ui.error:
return False
if not outlook_is_running():
import os
os.startfile("outlook")
这篇关于使用Python检查Outlook是否已打开(如果尚未打开)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!