Perl file (.pl) file with arguments as windows service


  1. Posts : 5
    Windows 7 64 Bit
       #1

    Perl file (.pl) file with arguments as windows service


    I am running Windows 7 32-bit. I have a perl script which i want to start everytime computer starts. Setting it as service will be a good option as i can start and restart the service from command line.

    In windows XP I was using srvany.exe but that is not a good solution. Is there any way I can make this Perl Script which takes in some command line arguments as windows service. Tried using sc.exe, with that service is created but it fails to start.

    To run that perl script i run on command line:
    perl PesrSclipt.pl --arg1 Hello --arg2 Buddy --arg3 Good
    .

    Any help will be highly appreciated.


    Thanks.
      My Computer


  2. Posts : 1,454
    Windows 7 ultimate x64
       #2

    If the script is already created in services .... then right click on the service > properties > Stop the service and then on Start Parameters you can add your arguments..

    Let me know.
      My Computer


  3. Posts : 5
    Windows 7 64 Bit
    Thread Starter
       #3

    Getting this Error:

    Windows could not start the udp_server service on Local Computer.
    Error 1053: The service did not respond to the start or control request in a timely fashion.
      My Computer


  4. Posts : 1,454
    Windows 7 ultimate x64
       #4

    udp_server ??? is that the one you created ??? Your perl script is trying to call on a dependent udp_server.. it has to be started before you can run your script
      My Computer


  5. Posts : 5
    Windows 7 64 Bit
    Thread Starter
       #5

    centaur78 said:
    udp_server ??? is that the one you created ??? Your perl script is trying to call on a dependent udp_server.. it has to be started before you can run your script
    udp_server is just a name of Perl Script. In other words, I am trying to create a service using SC:

    sc create udp_server binpath= C:\Perl\bin\perl.exe type= own start= auto
    So udp_server is just a name and nothing else.
      My Computer


  6. Posts : 2,465
    Windows 7 Ultimate x64
       #6

    Generally speaking, you can't put an arbitrary executable as a Windows service (gives the error you say when starting), as it requires to call an specific interface with the OS to work as a service and respond to the service manager request, which the Perl runner obviously doesn't do. That's what srvany.exe do, provides that interface and runs your arbitrary program in turn. sc.exe is fine for creating the service entry itself.

    Why you don't want to use srvany.exe?
    I don't think there is another way to run a non-service .exe as a service, unless you make some other program to replace it, or modify the script to call the Windows services API (no idea if that's easy or even possible).
      My Computer


  7. Posts : 1,454
    Windows 7 ultimate x64
       #7

    You can download the Windows 2003 Resource Kit from MS directly and then follow the below step

    1. Copy INSTSRV (Allows you to installs and removes system services) and SRVANY (Allows any Windows application to run as a service.) to the System32 folder under Windows.

    2. Run from the cmd as administrator from the C:\Windows\System32 folder

    Run MS-DOS command prompt as an administrator as shown below, and run the following command:

    INSTSRV <Service Name> C:\Windows\System32\SRVANY.EXE
    For example: INSTRV UDP_SERVER C:\Windows\System32\SRVANY.EXE


    3. Go to Services menu. and right click on your perl service and set the "Logon As" to Local System Account in the service properties.

    4. Go to Regedit, then under

    HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Services > UDP_SERVER

    Add the new Key: Parameters
    Select Parameters
    Add the String Value: Application
    String: C:\PERL\bin\perl.exe (your path to the perl.exe program)

    Add the String Value: AppParameters
    String: C:\DIR_To_Perl\perl_script.pl (your path to the perl script ... this is where you add your extra arguments)

    and Close REGEDIT

    5. Go back to services and start your UDP_SERVER service.

    Let me know if this works
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:42.
Find Us