Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Perl file (.pl) file with arguments as windows service


01 Jan 2013   #1

Windows 7 64 Bit
 
 
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:
Quote:
perl PesrSclipt.pl --arg1 Hello --arg2 Buddy --arg3 Good
.

Any help will be highly appreciated.


Thanks.

My System SpecsSystem Spec
.

01 Jan 2013   #2

Windows 7 ultimate x64
 
 

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 System SpecsSystem Spec
01 Jan 2013   #3

Windows 7 64 Bit
 
 

Getting this Error:

Quote:
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 System SpecsSystem Spec
.


01 Jan 2013   #4

Windows 7 ultimate x64
 
 

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 System SpecsSystem Spec
01 Jan 2013   #5

Windows 7 64 Bit
 
 

Quote   Quote: Originally Posted by centaur78 View Post
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:

Quote:
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 System SpecsSystem Spec
01 Jan 2013   #6

Windows 7 Ultimate x64
 
 

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 System SpecsSystem Spec
02 Jan 2013   #7

Windows 7 ultimate x64
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools




Our Sites

Site Links

About Us

Find 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 11:19 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33