# How to start a service with the win32-service gem

**URL:** <https://www.ruby-forum.com/t/how-to-start-a-service-with-the-win32-service-gem/122803>\
**Category:** Ruby\
**Created:** [December 12, 2007, 11:00am UTC](https://www.ruby-forum.com/t/how-to-start-a-service-with-the-win32-service-gem/122803 "2007-12-12T11:00:57Z")\
**Posts on this page:** 1\
**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, 11:00am UTC](https://www.ruby-forum.com/t/how-to-start-a-service-with-the-win32-service-gem/122803/1 "2007-12-12T11:00:57Z")

</div>

Hi  
I have install the win32-service 0.6.0 and made some test code just like  
these:

require ‘rubygems’  
require “win32/service”  
require “Win32API”  
include Win32

begin  
srv = Service.new()  
srv.binary\_path\_name = "c:/ruby/bin/ruby " + File.expand\_path($0)  
srv.create\_service{|s|  
s.service\_name = “foo”

s.display\_name = “Test\_Demo”  
s.service\_description = “Greatest Service”  
}  
srv.configure\_service{|serv|  
serv.display\_name = “My Service”  
serv.start\_type = Service::AUTO\_START  
serv.service\_type = Service::WIN32\_OWN\_PROCESS  
}  
srv.close  
rescue  
end

class Daemon  
def service\_init  
sleep(200)  
end  
def service\_main  
system(‘notepad’)  
while running?  
#puts ‘the service in running’  
if state == RUNNING  
system(‘notepad’)  
sleep 5  
end  
end  
end  
d = Daemon.new  
d.mainloop  
end  
the service can be registered but can’t to be start.When I try to  
run(start) it in the Management Console that I will get the 1053 error  
with the service.How can I to rescue the problem.  
My OS is Windows XP SP2  
Any help will be very grateful.
