none
How to capture ScreenShot of Desktop in windows service

    Question

  • I have just written the C# Code that is taking the screenshot of desktop but when i put that code in window service then that begin to take the black picture because service run in session 0 and our desktop run in session 1 kindly can u please tell me how would i take the screenshopt of desktop through session 1 as i don't have much knowledge about session of windows
    • Edited by Wahib1900 Monday, March 20, 2017 3:12 PM
    Monday, March 20, 2017 3:12 PM

All replies

  • Services do not have access to a user's desktop. Services run in an isolated session and each session has its own desktop. So if a service did snapshot the desktop it would be for session 0, not the user's desktop.

    I'm going to basically say that you cannot implement this via a service. In reality you could possibly get it to work but doing so would require that you use legacy components that MS will not be supporting going forward. You could also theoretically use the RDS functionality but you're going to have to have something between the service and the user to help identify things such that implementing the screenshot in the service really doesn't make any sense.

    If you can explain why it is necessary to use a windows service (which runs whether a user is logged in or not) to take a picture of a desktop specific to a user then we can probably provide a better approach. Even if you were able to get the service to see the user's desktop, the followup question would be which user? There can be any # of users logged in at the same time and they each get their own desktops.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Monday, March 20, 2017 6:49 PM
    Moderator
  • I have just written the C# Code that is taking the screenshot of desktop but when i put that code in window service then that begin to take the black picture because service run in session 0 and our desktop run in session 1 kindly can u please tell me how would i take the screenshopt of desktop through session 1 as i don't have much knowledge about session of windows

    This might give you the explanation you are looking for. click here

    Thanks

    Eswar

    Monday, March 20, 2017 6:58 PM
  • I have understood your point Michael but the thing i have do get done is that i need to monitor the activity of the logged in user so i had thought i should develop the service in which i would get the screenshot of the logged in user desktop .but kindly can you help me to guide the better approach to  get this done
    Tuesday, March 21, 2017 1:34 AM
  • What are you hoping to capture by grabbing a screenshot?

    If you want to monitor what programs a user is running then monitoring the running processes would be better. Even better would be to set up a GPO that prevents the user from running programs they shouldn't.

    If you want to monitor what sites a user is browsing to then that is better handled via your network infrastructure (i.e. router). You can also block things in your firewall.

    If you really just want to screenshot the user's desktop then you'll either need to use RDS or create an app that runs when the user logs in (i.e. Startup group or registry) that can screen capture the screen. Of course you'd need to lock it down to prevent the user from closing it. This could communicate with a service if you needed to but I don't really see that a service would add much. I guess you could have the service restart the program if they had stopped it but that isn't as trivial as you might imagine given that you'd need to start it in their session.

    Tuesday, March 21, 2017 2:48 AM
    Moderator
  • Hi Wahib1900,

    Thank you for posting here.

    Here is some code sample for reference.

    How to get a screen capture of a .Net WinForms control programmatically?

    Programmatically get a screenshot of a page

    Is there a way to take a screenshot of the user's Windows desktop?

    Programmatically Take Screenshot Using C#

    I hope this would be helpful.

    Best Regard,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 21, 2017 5:57 AM
    Moderator
  • I've gone through from these links Wendy Zang
    Tuesday, March 21, 2017 8:11 AM
  • let me roll up my sleeves to tell you in detail ,I need to Monitor the User Activities ,Firstly i need to get the opened Application which user  have been using ,Secondly Take the screen shot of desktop to monitor the activities ,This Appliction should be hidden and run in background ,User shouldn't be able to know about it ,That's why i thought to develop the service which would run in background and getting the information which i need ,

    Tuesday, March 21, 2017 8:20 AM
  • Hi Wahib1900,

    As Michael said, the whole purpose of creating a windows service is to limit the user access to the application so it can easily run without interrupting in the background. As for your screen capturing using service I don't think it is possible or wise doing this way. Because as service runs in the background there is no user interface to access it. So if you develop a program then either you set a timer that it will capture the screen shot every 5 min or something like this. Which isn't wise because whether user is working on the PC or not as long as the PC is running your service will still keep capturing the screen shot and filling up your hard disk memory.

    And what you are saying you want to achieve, I would advise the opposite because you are violating user privacy. Also we are not encourage any one here to do something like this.


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Tuesday, March 21, 2017 10:23 AM
    Moderator