python script under windows

J

Jan Gregor

Hello

I run python script on another computer and want to "survive" that
script after my logout. the script also uses drive mapping to network drive.

Can you help me ? Or better is there some info for unix person how
to survive with python on windows ;-)

thanks,
jan gregor
 
H

Harlin Seritt

Hi Jan,

Unfortunately you will have to register it as a service. I am almost
certain there is no other way to do it. However, setting up an
executable as a true Windows Service is extremely tedious. You can try
this utility that I use. You can get it here:
http://www.seritt.org/pub/srvinst13b.exe. I'm probably not supposed to
distribute it, but the site and owners that used to host it have gone
belly up best that I can tell. As with anything, use it at your own
risk. I found it as freeware a few months back.

If you want a decent cheap solution, FireDaemon is pretty good. I think
it's like 30USD but it does a great job and adds a few extra features.

HTH,

Harlin Seritt
Internet Villa: www.seritt.org
 
L

Larry Bates

Making a Python program into a service isn't all that "tedious".
Get a copy of Mark Hammonds "Python Programming on Win32" which
contains excellent examples on how to do this. I've written
several and after the first one, it is quite easy to do.

-Larry Bates
 
R

Roger Upole

You can use the Task Scheduler to run a script persistently if you
don't need the capabilities of the service framework.

Roger
 
G

Grig Gheorghiu

Jan,

Here's what I did to run a Python script (let's call it myscript.py) as
a service:

1. Install Win2K Resource Kit.

2. Run instsrv to install srvany.exe as a service with the name
myscript:

C:\Program Files\Resource Kit\instsrv myscript "C:\Program
Files\Resource Kit\srvany.exe"

3. Go to Computer Management->Services and make sure myscript is listed
as a service. Also make sure the Startup Type is Automatic.

4. Create a myscript.bat file with the following contents in e.g.
C:\pyscripts:

C:\Python23\python C:\pyscripts\myscript.py

5. Create new registry entries for the new service.
- run regedt32 and go to the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\myscript entry
- add new key (Edit->Add Key) called Parameters
- add new entry for Parameters key (Edit->Add Value) to set the
Application name => Name should be Application, Type should be
REG_SZ, Value should be path to myscript.bat, i.e.
C:\pyscripts\myscript.bat
- add new entry for Parameters key (Edit->Add Value) to set the working
directory => Name should be AppDir, Type should be
REG_SZ, Value should be path to pyscripts directory, i.e. C:\pyscripts

6. Test starting and stopping the myscript service in Computer
Management->Services.
 
M

Marco Aschwanden

Can you help me ? Or better is there some info for unix person how
to survive with python on windows ;-)

Use py2exe to transform your app into a service...
 
C

cg

I ran into a similar issue a couple of months back, the solution on
Windows is to run it as a service. It is very simple, you need Mark
Hammond's Win32 extensions. For path you have to use absolute filepath
for all local files and for network drive use the UNC path i.e.
\\servername\folder-filename\ . All these steps will let your machine
running the program survive logouts after a login. If your machine is
part of windows network and there is domain login then in order for it
to work after a machine restart you need to goto the Service panel (in
Control Panel) find the Python service you registered, right-click and
goto its properties, goto the "Log On" panel, select a domain user for
"This account" by clicking the Browse button, note the selected user
has access to windows domain and admin access to that particular
machine. Enter user network password, hit Apply, OK and there u go. All
this requires admin access to machine. You can configure a couple of
things about the service in the Services panel.

The code itself is simple:
#------------------------------------------------------------------
import win32service, win32serviceutil

class MyService(win32serviceutil.ServiceFramework):
"""NT Service."""

_svc_name_ = "MyServiceName"
_svc_display_name_ = "A Little More Descriptive"

def SvcDoRun(self):
#do your stuff here, call your main application code.

def SvcStop(self):
#the following line is not really needed, basically put here
any code that should execute
#before the service stops
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(MyService)
#------------------------------------------------------------------
After this if you have python in your path and Win32 extensions
installed, goto command prompt and run:
c:\> MyService.py -startup=auto install

Trying to have your service have Network access after a machine restart
is a bit tricky. This thing works but somehow I feel there is more to
it. If anyone has a better way, please post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,005
Latest member
ChasityFan

Latest Threads

Top