Jump to content
Sign in to follow this  
JonnyThunder

Run a script as a service

Recommended Posts

JonnyThunder

Hello,

I've read various topics on here about running the script as a service but can't get it to work. Here is the test script I'm running....

#NoTrayIcon

While 1=1
    
    Beep(4000, 200)
    
    Sleep(400)
    
WEnd

Then I create a service with this....

sc.exe create "MyService" binpath= "C:\MyScript.exe" type= own type= interact start= auto DisplayName= "MyService"

The service is created fine. However, when I try to start the service with this....

sc.exe start "MyService"

... I get the following message...

The service did not respond to the start or control request in a timely fashion

Can anyone show me how to actually do this?

Cheers,

JT

Share this post


Link to post
Share on other sites
JonnyThunder

Thanks, I'd already read that earlier on - but I was trying to make use of SC.EXE which is 'meant' to be able to do this. I already tested the script with RunAsSvc and it works fine with that too. Just seems to be SC.EXE which is a problem, though I can't think why.

Share this post


Link to post
Share on other sites
Juvigy

sc create myservice c:\myprogram.exe

Thia is how you can install your exe to run as a service.

Share this post


Link to post
Share on other sites
JonnyThunder

Sadly it isn't that easy. The command I posted originally DOES install the service but it doesn't actually start.

Share this post


Link to post
Share on other sites
JonnyThunder

Yes, when I try to start the service I get the error above. I get it whether I use the UDF posted earlier or from the command line using SC.EXE. Or even if I try to start the service from the Services list.

Share this post


Link to post
Share on other sites
spudw2k

I believe SC is simply a commandline interface to the Service Control Manager. It has nothing to do with making non-service executables into services.

You can use the Services UDF mentioned by Whim to accomplish what you want. Else you have to use another tool to launch any exe as a service.

Edited by spudw2k

Share this post


Link to post
Share on other sites
Juvigy

What exactly does your script do?

OS ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.