0

I've been able to create a windows service using Python and following this tutorial: http://ryrobes.com/python/running-python-scripts-as-a-windows-service/

However I tried to implement a script in this that opens up a new Outlook mail via COM. This script works outside of the service but I seem to have traced the problem back to this line:

obj = win32com.client.Dispatch("Outlook.Application")

on looking into this further, it seems that with UAC in Vista and Windows 7, came blocking of services interacting with users. More Info - http://msdn.microsoft.com/en-us/library/windows/desktop/ms683502%28v=vs.85%29.aspx

So my question is: what's the best way around this? I have a python script that works when I ensure to turn it on, but leaving a batch/cmd file in the startup directory seems kinda wrong.

Thanks in advance for any ideas!

Windows 7 x64 (I'm also bound by Enterprise Group policy. I have local admin rights only)

TheDavil
  • 706
  • 2
  • 7
  • 22
  • Why do you need a Windows service? Can't you have an application that runs when the user is logged? You can configure the service to be able to interact with desktop, but that can be blocked by the NoInteractiveServices registry key (on my Windows 8 PC, it's set to 1). – Simon Mourier Apr 04 '13 at 07:53
  • I don't really "need" a windows service, but being able to "set and forget" would be nice, and not have to worry about making sure the program is running. Plus it's a learning exercise for me to get a service up and running and log info the the event log etc. – TheDavil Apr 04 '13 at 11:39
  • Interactive Services are more and more discouraged. You can also write a Windows Service plus another "regular" interactive application that communicate with this service (using various mechanism, HTTP, COM, IPC, Socket, etc.). In the case of Outlook, that could be an outlook add-in that polls the service regularly for something to do. – Simon Mourier Apr 04 '13 at 12:30
  • Okay. I was trying to cut out the Sockets / HTTP bit if possible, not add another layer of same. I understand. When writing services I'll stick to non-interactive stuff. I might just get the service to check if my main Python script is running and alert me if not. or something similar. Thanks. – TheDavil Apr 05 '13 at 10:39
  • with regards to add-ins. I'm also learning C# and VS at the moment and I have a basic add-in built so I might be able to leverage that. – TheDavil Apr 05 '13 at 10:46

1 Answers1

0

Your 'more info' link describes two techniques that might, maybe, be achievable:

  • "Display a dialog box in the user's session using the WTSSendMessage function"
  • "Create a separate hidden GUI application and use the CreateProcessAsUser function to run the application within the context of the interactive user. ..."

But as mentioned in these answers and Simon Mourier's comment, the most straightforward solution is probably service + background-process-in-user-session + IPC.

Moreover, if you're trying to create a new email via Outlook, you probably want/need something running in the user's session anyway to have proper context.

Community
  • 1
  • 1
patricktokeeffe
  • 1,058
  • 1
  • 11
  • 21