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

anshumangoyal

New member
Local time
12:06 AM
Messages
5
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 My Computer

At a glance

Windows 7 64 Bit
OS
Windows 7 64 Bit
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 My Computer

At a glance

Windows 7 ultimate x64
Computer Manufacturer/Model Number
Nothing specific....what ever the clients provide for Repair
OS
Windows 7 ultimate x64
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 My Computer

At a glance

Windows 7 64 Bit
OS
Windows 7 64 Bit
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 My Computer

At a glance

Windows 7 ultimate x64
Computer Manufacturer/Model Number
Nothing specific....what ever the clients provide for Repair
OS
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

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 My Computer

At a glance

Windows 7 64 Bit
OS
Windows 7 64 Bit
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 My Computer

At a glance

Windows 7 Ultimate x64Intel Core i7-740QM8 GB DDR3NVIDIA GeForce 330GT
Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
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 My Computer

At a glance

Windows 7 ultimate x64
Computer Manufacturer/Model Number
Nothing specific....what ever the clients provide for Repair
OS
Windows 7 ultimate x64
Back
Top