1

I have a Windows Service consisting of a timer with 4000 Interval, in tick method of timer a save method run and save a bitmap file in specific path, it is like the following:

 protected override void OnStart(string[] args) {
        CaptureTimer.Start();
    }

private void CaptureTimer_Tick(object sender, EventArgs e) {
        DateTime dt = DateTime.Now;
        Bitmap capture = Capture.GetImage();
        capture.Save(@"D:\Doc\Temp\GeoServiceFiles\" + Environment.MachineName +
        dt.Ticks.ToString() + ".bmp");
    }

but there is not any saved file, I test the exact code in Win Application and that worked correctly replaced OnStart method with button1_Click. also for test my service add an eventlog: eventLog1.WriteEntry("test service"); and log saved correctly but yet there isn't any saved file, So is there any special way to saved files with Windows Services?

Saeid
  • 13,224
  • 32
  • 107
  • 173
  • 4
    It is amazing to me how many people on this site are creating Windows Services that draw/save bitmap images. I can't really think of very many applications for this, but I see an average of 2-3 questions per day on the subject! – Cody Gray - on strike Dec 22 '11 at 06:58
  • possible duplicate of [Use of Timer in Windows Service](http://stackoverflow.com/questions/5495842/use-of-timer-in-windows-service) – Cody Gray - on strike Dec 23 '11 at 00:19

2 Answers2

2

Have you checked the permissions on the folder D:\Doc\Temp\GeoServiceFiles\?

The windows service usually run as Local System, Network Service or similar depending on how you set it up, but it will not have the same rights as the win application you run as your own user.

Try setting the folder to Full control for Everyone just to check that it works, and refine the permissions afterwards if that is the source of the problems.

Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
  • I use Local System in Account property, and the folder doesn't any special permission is there any other settings that must be checked? – Saeid Dec 22 '11 at 07:11
  • Have you tried setting Full control for Everyone and then running the service? By default Local System services does not have permission to save files iirc – Øyvind Bråthen Dec 22 '11 at 07:24
  • How can Set Full Control to Everyone? – Saeid Dec 22 '11 at 07:47
  • Right click folder, click properties, go to security tab, click edit, click Add, write Everyone and click Ok. Select Everyone from the list, put a checkmark in Full control -> Allow. Click ok to close the permissions window, and ok to close the properties window. – Øyvind Bråthen Dec 22 '11 at 07:58
  • I do Exactly as you said but not work, there isn't any Saved Files. – Saeid Dec 22 '11 at 09:37
  • Saeid - It was worth a try anyway ;) – Øyvind Bråthen Dec 22 '11 at 13:05
  • I have the same issue... I have also changed what user the service uses, to Administrator and other things, but the file never appears anywhere. If I install the service on mu local computer, and tell it to write a file to C:\bla.txt, then I see an exception in the Event Viewer. But when I put the same code on a server elsewhere, then there is no exception in the Eventview, and no files created . – Ted May 21 '13 at 14:14
1

What Timer you use? I think you must use System.Threading.Timer look at this Use of Timer in Windows Service

Community
  • 1
  • 1
Saeid
  • 13,224
  • 32
  • 107
  • 173