# 1053 Error about win32-service

**URL:** <https://www.ruby-forum.com/t/1053-error-about-win32-service/122785>\
**Category:** Ruby\
**Created:** [December 12, 2007, 4:51am UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785 "2007-12-12T04:51:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthrax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@anthrax](https://www.ruby-forum.com/u/anthrax)\
**Post date:** [December 12, 2007, 4:51am UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785/1 "2007-12-12T04:51:52Z")

</div>

Hi  
I have installed the gem of win32-service-0.6.0-x86-mswin32-60.gem.But  
when I run my test code such as:

require ‘rubygems’  
require ‘win32/service’  
include Win32

s = Service.new  
s.create\_service{ |srv|  
srv.service\_name = “foo”  
srv.binary\_path\_name = "D:\Ruby\bin\ruby "+File.expand\_path($0)  
srv.display\_name = “Test\_service”  
}  
s.close

Service.start(“foo”)

I will get a 1053 ERROR. How can I rescue the error?

---

<div class="post-metadata">

**Author:** ![anthrax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@anthrax](https://www.ruby-forum.com/u/anthrax)\
**Post date:** [December 12, 2007, 2:14pm UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785/2 "2007-12-12T14:14:06Z")

</div>

On Dec 12, 2007 4:51 AM, Kai G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> srv.service\_name = “foo”  
> srv.binary\_path\_name = "D:\Ruby\bin\ruby "+File.expand\_path($0)  
> srv.display\_name = “Test\_service”  
> }  
> s.close
> 
> Service.start(“foo”)
> 
> I will get a 1053 ERROR. How can I rescue the error?

I suggest you google for “1053 ERROR win32-service ruby”.

You may start the service from the command line (net start foo) to see  
if you get an additional debug info.

Then, try running your service in standalone mode (i.e. just run  
"D:\Ruby\bin\ruby "+File.expand\_path($0))

The error you get might be dependant on OS version (XP/2K3/vista) and  
the user it runs under (default is SYSTEM).

There are several constraints what you can and cannot do when running  
as service. Most notably, you won’t have access to  
stdin/stdout/stderr,  
and to any substed/mapped/network disks. The PATH might be different as  
well.

---

<div class="post-metadata">

**Author:** ![anthrax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@anthrax](https://www.ruby-forum.com/u/anthrax)\
**Post date:** [December 12, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785/3 "2007-12-12T19:09:06Z")

</div>

On Dec 11, 8:51 pm, Kai G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> srv.service\_name = “foo”  
> srv.binary\_path\_name = "D:\Ruby\bin\ruby "+File.expand\_path($0)  
> srv.display\_name = “Test\_service”}
> 
> s.close
> 
> Service.start(“foo”)

One thing you’ll want to be aware of is that there was an interface  
change in 0.6.0. Here’s an example that uses most of the available  
options:

# Create a new service

Service.create(‘some\_service’, nil,  
:service\_type =\> Service::WIN32\_OWN\_PROCESS,  
:description =\> ‘A custom service I wrote just for fun’  
:start\_type =\> Service::AUTO\_START,  
:error\_control =\> Service::ERROR\_NORMAL,  
:binary\_path\_name =\> ‘C:\path\to\some\_service.exe’,  
:load\_order\_group =\> ‘Network’,  
:dependencies =\> [‘W32Time’,‘Schedule’]  
:service\_start\_name =\> ‘SomeDomain\User’,  
:password =\> ‘XXXXXXX’,  
:display\_name =\> ‘This is some service’,  
)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![anthrax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@anthrax](https://www.ruby-forum.com/u/anthrax)\
**Post date:** [December 12, 2007, 8:41pm UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785/4 "2007-12-12T20:41:44Z")

</div>

On Dec 12, 2007 12:35 PM, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Or, you can merge them in one file, but distinguish among them using  
> command line options.  
> I mean, if you run my\_service --register or my\_service --unregister,  
> then it will to the register/unregister stuff.  
> Without option, it will run the Daemon stuff.

see mongrel\_service how they do it.

---

<div class="post-metadata">

**Author:** ![anthrax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@anthrax](https://www.ruby-forum.com/u/anthrax)\
**Post date:** [December 12, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785/5 "2007-12-12T20:00:19Z")

</div>

On Dec 12, 2007 4:51 AM, Kai G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> srv.service\_name = “foo”  
> srv.binary\_path\_name = "D:\Ruby\bin\ruby "+File.expand\_path($0)  
> srv.display\_name = “Test\_service”  
> }  
> s.close
> 
> Service.start(“foo”)
> 
> I will get a 1053 ERROR. How can I rescue the error?

After reading your other thread I see your problem now:

Just make TWO scripts: one for registering the service and the other  
for the service itself.  
You don’t need to register the service again when it’s just being  
started.

Or, you can merge them in one file, but distinguish among them using  
command line options.  
I mean, if you run my\_service --register or my\_service --unregister,  
then it will to the register/unregister stuff.  
Without option, it will run the Daemon stuff.

Note that in order to start the notepad, you might need to allow the  
service interact with desktop. (Though  
I don’t remember if this is valid for xp or for vista only. Have a  
look in the service’s properties.)

---

<div class="post-metadata">

**Author:** ![anthrax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@anthrax](https://www.ruby-forum.com/u/anthrax)\
**Post date:** [December 13, 2007, 5:27am UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785/6 "2007-12-13T05:27:47Z")

</div>

Daniel B. wrote:

> One thing you’ll want to be aware of is that there was an interface  
> change in 0.6.0. Here’s an example that uses most of the available  
> options:  
> …  
> Regards,
> 
> Dan

Thanks for your help and your win32-service gem 🙂

---

<div class="post-metadata">

**Author:** ![anthrax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@anthrax](https://www.ruby-forum.com/u/anthrax)\
**Post date:** [December 12, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/1053-error-about-win32-service/122785/7 "2007-12-12T22:34:35Z")

</div>

Jano S. å†™é“:

> 

Thanks for Jano S…I have rescued the problem with your help.
