相关疑难解决方法(0)

使用C#和远程桌面问题进行屏幕截图

我有一个C sharp控制台应用程序,可以多次捕获MS Word文档的屏幕截图.它工作得很好,但是当我将这个应用程序放在一个远程的Windows XP机器上它工作正常,我远程桌面是可见的,但如果我运行我的应用程序并离开远程桌面(最小化,甚至没有注销我想要做的)截图是空白的!

屏幕截图应用程序由作为SYSTEM用户运行的服务运行.

即使没有连接用户,如何让GUI保持活动状态?

这是我使用的代码:

public Image CaptureWindow(IntPtr handle)
{
    // get te hDC of the target window
    IntPtr hdcSrc = User32.GetWindowDC(handle);
    // get the size
    User32.RECT windowRect = new User32.RECT();
    User32.GetWindowRect(handle, ref windowRect);
    int width = windowRect.right - windowRect.left;
    int height = windowRect.bottom - windowRect.top;
    // create a device context we can copy to
    IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
    // create a bitmap we can copy it to,
    // using GetDeviceCaps to get the width/height
    IntPtr …
Run Code Online (Sandbox Code Playgroud)

.net c# windows system.drawing remote-desktop

14
推荐指数
1
解决办法
6554
查看次数

Windows服务下的进程截图

我们必须从Windows服务运行一个进程并从中获取屏幕截图.

我们尝试了BitBlt和PrintWindow Win32调用,但都给出了空白(黑色)位图.

如果我们从普通用户进程运行我们的代码,它就可以正常运行.

这有可能吗?或者可以尝试另一种方法吗?

我们尝试的事情:

  1. 作为本地系统运行的Windows服务,以本地系统运行进程 - >屏幕截图失败
  2. 以管理员身份运行的Windows服务以管理员身份运行 - >屏幕截图失败.
  3. 以用户XYZ身份运行的Windows应用程序以XYZ运行流程 - >截图适用于BitBlt或PrintWindow.
  4. 尝试从本地系统检查"允许服务与桌面交互"

我们还注意到PrintWindow对我们的情况更好,如果窗口在另一个窗口后面,它可以工作.

对于其他要求,父进程和子进程必须位于同一用户下.我们无法真正使用从一个进程到另一个进程的模拟.

.net c# windows-services screenshot process

5
推荐指数
3
解决办法
5001
查看次数

C#:从Windows服务捕获屏幕

我必须在每一秒后捕获Desktop的屏幕截图.在Winform应用程序中它运行正常.但在将代码移动到Windows服务后,它没有捕获屏幕截图.知道为什么不这样做吗?

这是代码

public partial class ScreenCaptureService : ServiceBase
    {
        System.Timers.Timer timer = new System.Timers.Timer();

        public ScreenCaptureService()
        {
            InitializeComponent();            
            this.timer.Interval = 1000;
            this.timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);

        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            CaptureScreen();
        }

        protected override void OnStart(string[] args)
        {
            if (!EventLog.SourceExists(this.ServiceName, Environment.MachineName))
            {
                EventLog.CreateEventSource(
                    new EventSourceCreationData(
                        this.ServiceName,
                        Environment.MachineName
                        )
                );
            }

            EventLog.WriteEntry(this.ServiceName, "The OnStart event has been called");
            this.timer.Enabled = true;
            CaptureScreen();
        }

        protected override void OnStop()
        {
            EventLog.WriteEntry(this.ServiceName, "The OnStop event has been called");
            this.timer.Enabled = false;
        } …
Run Code Online (Sandbox Code Playgroud)

c# image-capture

4
推荐指数
1
解决办法
4805
查看次数

为什么Windows服务中的打印屏幕返回黑色图像?

protected override void OnStart(string[] args)
{
    base.OnStart(args);
    CaptureScreen();

}

protected override void OnStop()
{
    base.OnStop();

}

private void CaptureScreen()
{

    Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

    Graphics graphics = Graphics.FromImage(printscreen as Image);

    graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);

    printscreen.Save(@"L:\" + Counter++ + ".jpg", ImageFormat.Jpeg);
}
Run Code Online (Sandbox Code Playgroud)
  • 我检查过与桌面交互
  • 尝试了localService帐户和用户

.net c# windows-services printscreen c#-4.0

3
推荐指数
1
解决办法
6425
查看次数

如何使用powershell在远程桌面上截屏

我写了一个代码,打开浏览器并截图。但是当我通过远程桌面运行它时,它会拍摄空白图像。

谁能建议一下,如何通过 PowerShell 在远程桌面上截取浏览器的屏幕截图?

例如,我需要在远程桌面上打开https://stackoverflow.com/并将屏幕截图保存在该远程服务器中。

代码

[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
   $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
   $graphics = [Drawing.Graphics]::FromImage($bmp)

   $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)

   $bmp.Save($path)

   $graphics.Dispose()
   $bmp.Dispose()
}
Run Code Online (Sandbox Code Playgroud)

windows powershell screenshot remote-desktop

3
推荐指数
1
解决办法
2633
查看次数

从 Windows 服务启动浏览器

我对 Microsoft 世界有点陌生。我已经阅读了这个答案和许多其他链接,我知道在 Vista 之后,Windows 服务无法与桌面交互。

但是,我遇到了紧急情况,必须快速找到解决方法。我需要我的 Windows 服务以某种方式打开带有 URL 的浏览器(现在任何类型的丑陋黑客都可以)。答案指出:

您需要编写一个单独的代理应用程序,它将在用户登录时自动启动,并与您的服务进行通信。然后代理可以启动浏览器或执行您需要的任何其他操作。

有人可以向我解释我如何以简单的方式做到这一点吗?该服务将如何与这个“代理”交谈?这个“代理”究竟是什么?

任何链接或建议将不胜感激。

编辑:目前。我的服务尝试运行以下代码:System.Diagnostics.Process.Start("www.google.com");

后来我发现,这不起作用

.net c# windows windows-services

2
推荐指数
1
解决办法
8223
查看次数