473,666 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any 'Windows Service' Experts? Why can't I capture the screen??

I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreensho t() As System.Drawing. Bitmap
Dim Rect As System.Drawing. Rectangle =
System.Windows. Forms.Screen.Pr imaryScreen.Bou nds
Dim gDest As System.Drawing. Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreensho t = New System.Drawing. Bitmap(Rect.Rig ht,
Rect.Bottom)
gDest = gDest.FromImage (CreateScreensh ot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest. ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHd c(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

Apr 25 '06 #1
4 5366
gw*****@kc.rr.c om wrote:
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreensho t() As System.Drawing. Bitmap
Dim Rect As System.Drawing. Rectangle =
System.Windows. Forms.Screen.Pr imaryScreen.Bou nds
Dim gDest As System.Drawing. Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreensho t = New System.Drawing. Bitmap(Rect.Rig ht,
Rect.Bottom)
gDest = gDest.FromImage (CreateScreensh ot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest. ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHd c(hdcDest)
ReleaseDC(0, hdcSrc)
End Function


The windows service runs in it's own session. This is why you can't
make an interactive service and you can't screen capture.

Chris
Apr 25 '06 #2
On 24 Apr 2006 18:43:47 -0700, gw*****@kc.rr.c om wrote:
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreensho t() As System.Drawing. Bitmap
Dim Rect As System.Drawing. Rectangle =
System.Windows .Forms.Screen.P rimaryScreen.Bo unds
Dim gDest As System.Drawing. Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreensho t = New System.Drawing. Bitmap(Rect.Rig ht,
Rect.Bottom)
gDest = gDest.FromImage (CreateScreensh ot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest. ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHd c(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

I'm not sure if this is related, but:
With Windows Media Player ver 9 and earlier, you use to be able to
screen capture a running video via the PrintScreen key and the frame
that was playing at the time would show in the resulting capture. With
ver 10 (and possibly from an additional XP upgrade), you no longer can
capture the frame. All you get is a blank media player. Screen capture
of a running video on any other player that I have, here, works as
expected.

I don't recall what MS calls it, but I believe it has something to do
with their attempt to protect media licensing rights.

Gene
Apr 25 '06 #3
GWhite,

A service cannot reach (direct) the screen. (I never tried it, therefore it
was to often written here).

Cor

<gw*****@kc.rr. com> schreef in bericht
news:11******** *************@v 46g2000cwv.goog legroups.com...
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreensho t() As System.Drawing. Bitmap
Dim Rect As System.Drawing. Rectangle =
System.Windows. Forms.Screen.Pr imaryScreen.Bou nds
Dim gDest As System.Drawing. Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreensho t = New System.Drawing. Bitmap(Rect.Rig ht,
Rect.Bottom)
gDest = gDest.FromImage (CreateScreensh ot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest. ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHd c(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

Apr 25 '06 #4
Try perhaps to check the "allow service to interact with desktop" checkbox.

A service is generally not tied to the desktop. It runs in its own
context...

--
Patrice

<gw*****@kc.rr. com> a écrit dans le message de news:
11************* ********@v46g20 00...legro ups.com...
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreensho t() As System.Drawing. Bitmap
Dim Rect As System.Drawing. Rectangle =
System.Windows. Forms.Screen.Pr imaryScreen.Bou nds
Dim gDest As System.Drawing. Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreensho t = New System.Drawing. Bitmap(Rect.Rig ht,
Rect.Bottom)
gDest = gDest.FromImage (CreateScreensh ot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest. ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHd c(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

Apr 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3596
by: Sambucus | last post by:
Hi all!. I'm trying to capture a screen shot of a window. This works good until the window is partly or completley hidden, then i get the graphics of what is visible on my screen (the windows that cover my screen shot window). I have tried this in both MCF and pure win32 but with the same result. I know i can set the window i want to capture to the front/top with commands such as SetForegroundWindow() and SetWindowPos(). The
4
415
by: Madestro | last post by:
Hi guys, I have a little problem. I have a class that uses Windows API to capture a snapshot of the screen. I have this class in a library that I include in my projects. When I try to use this class in a windows service, the snapshot comes up as a black screen. Any idea why? or how do I get around it? The class works fine if I use it in a regular windows forms application.
9
2816
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am facing. Please please help me to solve this as soon as possible. So here we go ... I am not able to take the screen shot of the windows form based "Smart
7
3206
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I think the username can be read with user.identity.name.
1
1772
by: hanson | last post by:
How can i create the function of ScreenCapture in the windows service?????
1
2315
by: hemant | last post by:
I am trying to Caputre the screen in windows service with the GDI Api of Win32 in vb.net 1. CreateDc 2. CreateCompatibleDC 3. CreateCompatibleBitmapDc 4. Bitblt 5. SelectObject 6. DeleteDc The Caputured screen file is always black
4
13065
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
I know how to capture a keypress for a windows application, but how would I go about doing it for a windows service? Rather than having a form in focus all the time, I would prefer to have something running in the background. There are option such as having the form invisible (opacity set to zero) and settings it's location as -200, -200 so that it isn't on the screen, but this isn't the ideal solution.
3
2267
by: =?Utf-8?B?Zmh1bnRlcg==?= | last post by:
I have a Windows Service that should pop a windows form right before logoff, for the user to enter some information. I got things working fairly well except that the user does not get to see the form before logoff. But I know that it run properly because when I log back in the form is there and works fine. So the form opened and run, but windows was already in the "logoff" screen with no desktop showing, so I missed the form. Is there any...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.