How to start a service with the win32-service gem

K

Kai Geng

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top