title: C# Service Will not write files, no errors
body: <p>EDIT:</p>
  
  <p>Ok, as of now and looking through countless posts I this i've arrived to a solution, I cannot do what I need to do from a service, I wanted it to be a service so that it would always be on for the computer, but apparently with the way services are written I may not be able to run the commands I want to run because "The service does not run in the same space as the users desktop" so it wont be able to capture the desktop, at least, thats what im gathering so far.</p>
  
  <p>As for now, I'll leave this here and maybe find a way to start a program under the users name when they logon, to capture the desktop, rather than try and do it from the service directly.</p>
  
  <p>I've been banging my head on the wall for a couple hours now trying to figure this out, I've never made a service before, just forms applications, well my next project (Client Server Model Client Monitoring utility) needs to be installed as a service on the client machines and send data back to the main server.</p>
  
  <p>Having never written a service before I looked up how to write one and how to install it and whatnot. I got it all working fine, the current working version spits an event log out every 30 seconds to show its working.</p>
  
  <p>I started by running it in LocalSystem because I assumed it had the permissions to write to the file, but after that failed I tried LocalService, that didn't work either.</p>
  
  <p>Im specifying the Directory as C:\WatcherData\Test.jpg</p>
  
  <p>and tested it in a regular forms application (which works)</p>
  
  <p>OutputImage.Save("c:\watcherdata\test.jpg", ImageFormat.Jpeg);</p>
  
  <p>No exceptions, no events, it just doesn't happen, but the EventLog message is put in immediately before it,so it should be reaching that point, right?</p>
  
  <p>Any assistance would be appreciated, If you need to know anything else I would be happy to oblige </p>
  
  <p>EDIT:
  Here goes a little code:</p>
  
  <pre><code>private void ServiceWorkerThread(object state)
      {
          while (!this.stopping)
          {
              this.eventLog1.WriteEntry("This is a test2");
  
              CallMe();
  
              Thread.Sleep(30000);
          }
  
          this.stoppedEvent.Set();
      }
  
      private void CallMe()
      {
          try
          {
              int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
              int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
              Bitmap OutputImage = new Bitmap(screenWidth, screenHeight);
              Graphics gfx = Graphics.FromImage((Image) OutputImage);
              gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
              OutputImage.Save("c:\\watcherdata\\test.jpg", ImageFormat.Jpeg);
          }
          catch (Exception e)
          {
              this.eventLog1.WriteEntry(e.Message + "\r\n" + e.StackTrace, EventLogEntryType.Error);
          }
      }
  </code></pre>
  
  <p>most of it was taken from a Microsoft sample document, as I said, I'm new to services</p>
  
  <p>currently still trying to figure it out, will let you guys know if i get anywhere</p>
  
  <p>EDIT 2 </p>
  
  <p>After playing around some more I managed to get it to write to the file, After realizing that most of the problem was with my lack of knowledge on how to build services and installers, apparently i wasnt rebuilding the installers when i built my service.</p>
  
  <p>Now it just writes all black, a large, black picture. but at least its writing!</p>