dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersDeepashri
Manoj Kumar
Danasegarane.A
Mohammad
Priya jain
Phagu Mahato
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Tools and Utilities » ASP.NET

Windows Service for taking screenshots


Posted Date:     Category: ASP.NET    
Author: Member Level: Bronze    Points: 35


This is a windows service which takes screenshots at a specific interval. This might be useful to monitor the activities of the user. This will be helful toapplication servers. This is created using C# .NET



 


Hi,
I have created a windows service which takes screenshots at sa defined interval which can be configured as per the requirement. These screenshots will be saved in a configurable location which can be the same system or any LAN folder.

1.Create a windows service project by selecting New->Project->Windows Service.
Name it ScreenShots.

2.In the service file ScreenShots.cs, place the following code :


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 image
Bitmap 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 copied
gImage.CopyFromScreen(upperLeftSource, upperLeftDestination, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

//Save the file with the current date and time file name as format as jpeg
string 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);
}
}
}


I have attached the service solution.

After installing the service : the property 'Allow service to interact with the desktop' should be set to true.

Steps : Go to Run -> Type Services.msc -> Find your service in the list of all the installed services -> Right click -> Go to LogOn tab-> Check the 'Allow service to interact with the desktop' property.

Start the service and here you go. The service will be taking the screenshots at any specified interval.

Regards,
Raman S V

Attachments
  • Windows Service for taking screenshots (43993-41522-Windows-Service-taking-screenshots.zip)





  • Did you like this resource? Share it with your friends and show your love!


    Responses to "Windows Service for taking screenshots"
    Guest Author: Nishant     18 Dec 2012
    It seems you have not tested it on Windows 7 or higher OS.

    It doesn't work in any case as you can't use System.Drawing/System.Drawing.Imaging inside Windows service. It gives black screen shot always.

    Run this program again if you have tested it.



    Feedbacks      

    Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Ninject - Open Source Dependency Injector for .Net
    Previous Resource: Connect Social Networks
    Return to Resources
    Post New Resource
    Category: ASP.NET


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.