public partial class ScreenShots : ServiceBase { Timers.Timer timer1 = new Timers.Timer(); public ScreenShots() { InitializeComponent(); } protected override void OnStart(string[] args) { try { timer1.Enabled = true; timer1.Elapsed += new Timers.ElapsedEventHandle(timer1_Elapsed); timer1.Interval = 2000; timer1.Start(); } catch (Exception exp) { File.AppendAllText@"D:\LoggerForScrnShotService.txt",exp.Message); } } protected override void OnStop() { try { File.AppendAllText(@"D:\LoggerForScrnShotService.txt", "Service Stopped"); timer1.Enabled = false; } catch (Exception exp) { File.AppendAllText(@"D:\LoggerForScrnShotService.txt", exp.Message); } } private void timer1_Elapsed(object sender, EventArgs e) { try {//Initialise a Bitmap object with the working area of the desktop as the imageBitmap bmp = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);//Creates a graphics object from the bitmap image.Graphics gImage = Graphics.FromImage(bmp);Point upperLeftSource = new Point(Screen.PrimaryScreen.WorkingArea.X, Screen.PrimaryScreen.WorkingArea.Y);Point upperLeftDestination = new Point(0, 0);//The source i.e. the desktop working area will be copiedgImage.CopyFromScreen(upperLeftSource, upperLeftDestination, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); //Save the file with the current date and time file name as format as jpegstring fileName = DateTime.Now.ToString("ddMMMyyyy_hhmmss") + ".jpeg";bmp.Save(@"D:\SaveScreenShots\" + fileName, ImageFormat.Jpeg);File.AppendAllText(@"D:\LoggerForScrnShotService.txt", "Screenshottaken"); } catch (Exception exp) {File.AppendAllText(@"D:\LoggerForScrnShotService.txt", exp.InnerException.Message);File.AppendAllText(@"D:\LoggerForScrnShotService.txt", exp.StackTrace); } } }