From: Jano Svitok Date: 2007-07-13T01:01:03+09:00 Subject: Re: Win32-service: error 5: access denied On 7/12/07, Michael Dichtl 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.