Win32 service - daemon

i think i understand how the process works,

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

Create a new service

Service.delete(‘netcat’)
Service.create(‘netcat’, nil,
:service_type => Service::WIN32_OWN_PROCESS,
:description => ‘just descriptgion’,
:start_type => Service::AUTO_START,
:error_control => Service::ERROR_NORMAL,
:binary_path_name => ‘c:\test\rscript.exe’,
:load_order_group => ‘Network’,
:dependencies => [‘W32Time’,‘Schedule’],

  :display_name       => 'just displayg'

)

this writes to the registry, it also executes the the file as a service
which confuses me because i dont see Service.start anywhere and the
process only last for like 10…

the reason it only last for a few seconds, The service did not respond
to the start or control request in a timely fashion… sounds simple
right? so, i need to add code to the rscript.exe

require “rubygems”
require ‘win32/daemon’
include Win32

class Daemon
def service_main
while running?
sleep 3
File.open(“c:\test.log”, “a”){ |f| f.puts “service is running”
}
# my program will do stuff here ? ? ? Right ???
end
end
def service_stop
exit!
end
end
Daemon.mainloop

this script wont compile with rubyscript2exe

I need my executable to communicate with the service manager… this
daemon script wont compile so now im stumped… idk what else to try…

Ill bump this thread one time before i give up with this method…

Trie to add the following to your daemon (service) script

require ‘RUBYSCRIPT2EXE’ and exit if RUBYSCRIPT2EXE.is_compiling? (see
below)

require “rubygems”
require ‘RUBYSCRIPT2EXE’
require ‘win32/daemon’
include Win32

exit if RUBYSCRIPT2EXE.is_compiling?

the ‘exit if RUBYSCRIPT2EXE.is_compiling?’ will stop the script from
running and compile the code in the a exe file with the required gems.

Good luck

if you are using gem version 1.3, Rubyscript2exe doesn’t work anymore
with this version. Try to downgrade if that’s the case otherwise try
using OCRA it does the same as Rubyscript2exe.

Cheers

the ‘exit if RUBYSCRIPT2EXE.is_compiling?’ will stop the script from
running and compile the code in the a exe file with the required gems.

Good luck

I just tried this, i get a long error when i try to compile…

C:\decoy>ruby rubyscript2exe.rb netcat.rbruby netcat.rb
Tracing netcat.rbruby …
netcat.rbruby doesn’t exist.

C:\decoy>ruby rubyscript2exe.rb netcat.rb
Tracing netcat …
Gathering files…
C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/requir
e2lib.rb:60:in gatherlibs': undefined methodlist’ for
Gem::Specification:Clas
s (NoMethodError)
from
C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscri
pt2exe/require2lib.rb:30
from netcat.rb:7
C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/requir
e2lib.rb:60:in gatherlibs': undefined methodlist’ for
Gem::Specification:Clas
s (NoMethodError)
from
C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscri
pt2exe/require2lib.rb:30
from netcat.rb:7
Couldn’t execute this command (rc=256):
C:\Program Files\Metasploit\Framework3\bin\ruby -I
‘C:/Users/BiGMaC/AppData/Loc
al/Temp/tar2rubyscript.d.1808.1/rubyscript2exe’ -I
‘C:/Users/BiGMaC/AppData/Loca
l/Temp/tar2rubyscript.d.1808.1’ -I ‘C:/Program
Files/Metasploit/Framework3/lib/r
uby/site_ruby/1.8’ -I ‘C:/Program
Files/Metasploit/Framework3/lib/ruby/site_ruby
/1.8/i386-msvcrt’ -I ‘C:/Program
Files/Metasploit/Framework3/lib/ruby/site_ruby’
-I ‘C:/Program Files/Metasploit/Framework3/lib/ruby/1.8’ -I ‘C:/Program
Files/M
etasploit/Framework3/lib/ruby/1.8/i386-mswin32’ -I ‘.’ -I ‘C:/decoy’ -I
‘C:/User
s/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe’ -I
‘C:/Users
/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/lib’
-I ‘C:/Us
ers/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe’ -I
‘C:/Use
rs/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/lib’
-r ‘C:/
Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/require2l
ib.rb’ ‘netcat.rb’
Stopped.

C:\decoy>

Ilias bankai wrote:

if you are using gem version 1.3, Rubyscript2exe doesn’t work anymore
with this version. Try to downgrade if that’s the case otherwise try
using OCRA it does the same as Rubyscript2exe.

Cheers

ok, i found my problem… ruby2exe and ocra work just fine… I dont
know how to properly install gems and library’s… im not sure were the
correct download is for this daemon lib is…

C:\Users\BiGMaC>irb
irb(main):001:0> require ‘win32/daemon’
LoadError: no such file to load – win32/daemon
from (irb):1:in `require’
from (irb):1

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs