473,657 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

win32 Service: path to .py script

Hi,

I have a testservice.py (see below). I installed the Windows-Service
successfully. (via commandlineopti on install)
The problem is that it runs only when it is in c:\windows\syst em32 or in
the python path.
I added the desired path (Y:\) to the PYTHONPATH environment variable
for the system account and rebooted.
When I start command line python and do a import testservice everything
is fine.
Starting the service with the script only in Y:\ gives the error in the
event log:

Python could not import the service's module

exceptions.Impo rtError: No module named testservice

Thanks for your help.

--
Greg

testservice.py:

import win32serviceuti l, win32service
import servicemanager
import win32api
import win32event
import sys

class TestPipeService (win32serviceut il.ServiceFrame work):
_svc_name_ = "MDE Dispatcher"
_svc_display_na me_ = "MDE-Dispatcher"
_svc_descriptio n_ = "Dispatches machine events from the Siemens ODC
to registrered MDE clients (windows) over the network via XML-RPC"
def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
win32event.SetE vent(self.hWait Stop)
def SvcDoRun(self):
# Write an event log record - in debug mode we will also
# see this message printed.
servicemanager. LogMsg(
servicemanager. EVENTLOG_INFORM ATION_TYPE,
servicemanager. PYS_SERVICE_STA RTED,
(self._svc_name _, '')
)

while 1:
win32api.Sleep( 2)
rc = win32event.Wait ForSingleObject (self.hWaitStop , 2000)
if rc == win32event.WAIT _OBJECT_0:
break
# Write another event log record.
servicemanager. LogMsg(
servicemanager. EVENTLOG_INFORM ATION_TYPE,
servicemanager. PYS_SERVICE_STO PPED,
(self._svc_name _, " TEST ")
)
if __name__=='__ma in__':
win32serviceuti l.HandleCommand Line(TestPipeSe rvice)

Sep 19 '06 #1
2 4404
Gregor Horvath wrote:
Hi,

I have a testservice.py (see below). I installed the Windows-Service
successfully. (via commandlineopti on install)
The problem is that it runs only when it is in c:\windows\syst em32 or in
the python path.
I added the desired path (Y:\) to the PYTHONPATH environment variable
for the system account and rebooted.
When I start command line python and do a import testservice everything
is fine.
Starting the service with the script only in Y:\ gives the error in the
event log:

Python could not import the service's module

exceptions.Impo rtError: No module named testservice

Thanks for your help.

--
Greg

testservice.py:

import win32serviceuti l, win32service
import servicemanager
import win32api
import win32event
import sys

class TestPipeService (win32serviceut il.ServiceFrame work):
_svc_name_ = "MDE Dispatcher"
_svc_display_na me_ = "MDE-Dispatcher"
_svc_descriptio n_ = "Dispatches machine events from the Siemens ODC
to registrered MDE clients (windows) over the network via XML-RPC"
def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
win32event.SetE vent(self.hWait Stop)
def SvcDoRun(self):
# Write an event log record - in debug mode we will also
# see this message printed.
servicemanager. LogMsg(
servicemanager. EVENTLOG_INFORM ATION_TYPE,
servicemanager. PYS_SERVICE_STA RTED,
(self._svc_name _, '')
)

while 1:
win32api.Sleep( 2)
rc = win32event.Wait ForSingleObject (self.hWaitStop , 2000)
if rc == win32event.WAIT _OBJECT_0:
break
# Write another event log record.
servicemanager. LogMsg(
servicemanager. EVENTLOG_INFORM ATION_TYPE,
servicemanager. PYS_SERVICE_STO PPED,
(self._svc_name _, " TEST ")
)
if __name__=='__ma in__':
win32serviceuti l.HandleCommand Line(TestPipeSe rvice)
I believe that your problem is that services run under Local
System account. Normally Local System account would not have
a drive mapping Y:\. You can change the account that a service
runs under in the Service Manager-Log On tab. Normally you
wouldn't run services from mapped drives, they would be
installed on local machine and started from there. If services
need to access mapped drives, you need to put full UNC
pathnames to access them or run the services under an account
that has the drives mapped properly.

-Larry Bates
Sep 19 '06 #2
Larry Bates schrieb:
I believe that your problem is that services run under Local
System account. Normally Local System account would not have
a drive mapping Y:\. You can change the account that a service
You are absolutly correct.
I moved the script to a local drive instead of a mapped network drive,
now it works perfectly.

Thank you a lot.

--
Servus, Gregor
Sep 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14353
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package because of a binary module which has to be compiled with Visual C 6. My scripts start with a '#!/usr/bin/env python' shebang, as God intended. Now, I assume I can make cmd.exe run foo.py by asociating *.py with the python interpreter.
6
3421
by: Laszlo Zsolt Nagy | last post by:
Sorry, I realized that the import zlib was not executed from my (working) service. So here is the question: why can't I use zlib from a win32 service? Is there any way to make it working? >------------- >Python could not import the service's module > File "T:\Python\Projects\NamedConnector\Service.py", line 17, in ? > from Processor import * > File "c:\Python\Projects\NamedConnector\Processor.py", line 35, in ?
1
3396
by: knutsample | last post by:
Hello! I'm trying to associate a file extension to my wxPython script so that all I have to do is double click on the file and my python script will load up with the path of that file. For instance, I've associated all .py files to be opened up with emacs.exe. If I double click on a .py file, emacs.exe would open up with that file in its buffer.
2
4033
by: rbt | last post by:
I have a win32 service written in Python. It works well. It sends a report of the status of the machine via email periodically. The one problem I have is this... while trying to send an email, the script loops until a send happens and then it breaks. Should it be unable to send, it sleeps for 10 minutes with time.sleep(600) and then wakes and tries again. This is when the problem occurs. I can't stop the service while the program is...
2
3274
by: raghavendra | last post by:
Hi, How to run automatically windows service by using setup deployment insatllation script using visual studio 2003.? What i did is :-- 1. created a windows service & tested the same. 2. then i used the windowsservice.exe in setup deployment project.
4
1223
by: Gav | last post by:
Hi all, I have written a program which seriously depends on an environment variable. When I set the env var for the system it caused me major problems unrelated to what I was trying to achieve. So in order to get around this I just used a simple script which would set the variable using the 'set' command and then call my program. This worked and only held the env var for that script session so once my program was finished it was gone and...
3
1939
by: Marshall | last post by:
Hello, I am wondering if it is possible to call a remote web service using ATLAS and if so, how. I have read several docs which show how to call a web service that is within the same project as the ATLAS 'enabled' web page but that is all I have found. In the example below, I would like to call the OpenOnline.SaveToPDF.WebServices.Service web service. I get a javascript error when trying to make the web service call saying that...
2
5547
by: Gregor Mosheh | last post by:
I'm trying to write a Win32 service. The following is straight from Python Programming on Win32 and it doesn't work. Is that book out of date; is there a new way to do services? I searched Google for hours trying to find any other method, and have been beating on this one for 5 more hours. The present error is: C:\Tester>python tester.py debug Debugging service Tester - press Ctrl+C to stop. Error 0xC0000004 - Python could not import...
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.