python script under windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan Gregor

    python script under windows

    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
  • Harlin Seritt

    #2
    Re: python script under windows

    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

    Comment

    • Benji York

      #3
      Re: python script under windows

      Jan Gregor wrote:[color=blue]
      > I run python script on another computer and want to "survive" that
      > script after my logout.[/color]

      Start at http://www.python.org/windows/win32/#NTServices.
      --
      Benji York

      Comment

      • Larry Bates

        #4
        Re: python script under windows

        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

        Harlin Seritt wrote:[color=blue]
        > 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
        >[/color]

        Comment

        • Roger Upole

          #5
          Re: python script under windows

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

          Roger

          "Jan Gregor" <gregor.jan@NOS PAM.quick.cz> wrote in message news:dfrdds$l4m $1@ns.felk.cvut .cz...[color=blue]
          > 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[/color]



          ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
          http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
          ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

          Comment

          • Grig Gheorghiu

            #6
            Re: python script under windows

            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\pyt hon C:\pyscripts\my script.py

            5. Create new registry entries for the new service.
            - run regedt32 and go to the
            HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices\myscrip t 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\my script.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.

            Comment

            • Marco Aschwanden

              #7
              Re: python script under windows

              > Can you help me ? Or better is there some info for unix person how[color=blue]
              > to survive with python on windows ;-)[/color]

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

              Comment

              • cg

                #8
                Re: python script under windows

                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\fo lder-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, win32serviceuti l

                class MyService(win32 serviceutil.Ser viceFramework):
                """NT Service."""

                _svc_name_ = "MyServiceN ame"
                _svc_display_na me_ = "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.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)

                if __name__ == '__main__':
                win32serviceuti l.HandleCommand Line(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.

                Comment

                • chanchal

                  #9
                  Re: python script under windows

                  typo, the correct command is:
                  c:\>python MyService.py -startup=auto install

                  Comment

                  Working...