[python-win32] Service fails on mapped network drive
Larry Bates
lbates at syscononline.com
Mon Mar 15 12:25:57 EST 2004
Martijn,
This is because services are not run under a context (user)
that knows about your mapped network drives. You will
probably have to run your service as a user that has the
network drives mapped.
-Larry Bates
Message: 8
Date: Mon, 15 Mar 2004 13:40:59 +0100
From: Martijn Ras <ras at holmes.nl>
Subject: [python-win32] Service fails on mapped network drive
To: python-win32 at python.org
Message-ID: <4055A45B.7000006 at holmes.nl>
Content-Type: text/plain; charset=us-ascii; format=flowed
Heya Folks,
Since i updated my script so it can be run as service, it fails to work
on files that are located on mapped network drives.
1) Share the root of your drive C.
2) Map the network drive.
3) Create the following three files in the root of your drive C
Note: Replace the following in the python script files:
<LOCALHOST> with the name of your machine,
<SHARE> with the share name you specified in step 1),
<MAPPEDDRIVE> with the drive you specified in step2).
4) Run 'python execfile_test.py', it will print "dit is een test" three
times, as expected.
5) Install the service 'python execfile_test_server.py install'.
6) Open the services control panel:
a) change the logon so the service run under an account that has
sufficient rights on the mapped network drive.
b) start the service.
7) Open the EventViewer, select the Application log.
You'll notice "dit is een test" has been logged twice and the third
loggin an IOError 'No such file or directory'.
Any suggestions on getting this service functioning one mapped network
files?
Mazzel,
Martijn.
::::::::::::::
config.txt
::::::::::::::
config = 'dit is een test'
::::::::::::::
execfile_test.py
::::::::::::::
config = {}
execfile('C:\\config.txt', config)
print str(config['config'])
execfile('\\\\<LOCALHOST>\\<SHARE>\\config.txt', config)
print str(config['config'])
execfile('<MAPPEDDRIVE>:\\config.txt', config)
print str(config['config'])
::::::::::::::
execfile_test_server.py
::::::::::::::
import exceptions
import os
import pywintypes
import win32api
import win32con
import win32event
import win32file
import win32pipe
import win32security
import win32service
import win32serviceutil
class execfile_test_server(win32serviceutil.ServiceFramework):
_svc_name_ = 'execfile_test_server'
_svc_display_name_ = 'execfile_test_server'
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.overlapped = pywintypes.OVERLAPPED()
self.overlapped.hEvent =
win32event.CreateEvent(None,0,0,None)
self.thread_handles = []
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
import servicemanager
# Write an event log record indicating we have started
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, ''))
config = {}
execfile('C:\\config.txt', config)
msg = str(config['config'])
servicemanager.LogInfoMsg(msg)
execfile('\\\\<LOCALHOST>\\<SHAREDFOLDER>\\config.txt',
config)
msg = str(config['config'])
servicemanager.LogInfoMsg(msg)
execfile('<SHAREDFOLDER>:\\config.txt', config)
msg = str(config['config'])
servicemanager.LogInfoMsg(msg)
# Write another event log record we have stopped
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_, ''))
if __name__=='__main__':
win32serviceutil.HandleCommandLine(execfile_test_server)
------------------------------
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
End of Python-win32 Digest, Vol 12, Issue 12
********************************************
More information about the Python-win32
mailing list