Jano Svitok
7/12/2007 4:01:00 PM
On 7/12/07, Michael Dichtl <mdi@meta-1.com> wrote:
> require 'rubygems'
> require 'win32/service'
> include Win32
>
> SERVICE_NAME = "cProjectsOutlookEventsListener3"
> SERVICE_DISPLAYNAME = "cProjectsOutlookEventsListener3"
Offtopic: You can write the following as
case ARGV[0]
when "register"
...
when "start"
...
else
...
end
> if ARGV[0] == "register"
> #startet den service
> svc = Service.new
...
> # hier ist der eigentliche Service-code
> class Daemon
> def service_init
> # Wartezeit bis der Service richtig initialisiert worden ist
> sleep 10
> end
Try this: (the only possible place where it can raise "access denied"
exception is when you rename the file (I suppose you can't do that
while it's open). If it does not help, create a log file and store the
exception stack trace to it (i.e. enclose everything in begin /
rescue.
> def service_main
- fileCount = 0
+ fileCount = 0
> watchForFile = "C:\findme.txt"
> while state == RUNNING
> sleep 5
> if File.exists? watchForFile
- fileCount += 1
- File.rename watchForFile, watchForFile + "." + fileCount.to_s
+ begin
+ File.rename watchForFile, watchForFile + "." + fileCount.to_s
+ fileCount += 1
+ rescue
+ end
> end
> end
> end
Of course, I assume the program works when run standalone, from the cmd.exe.
Access permissions of NTFS might be in the game as well. You may try
playing with runas /user:SYSTEM, too.
J.