为什么 Windows 服务中的打印屏幕返回黑色图像? [英] Why does print screen in a Windows Service return a black image?

查看:26
本文介绍了为什么 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);
}

  • 我检查了与桌面的交互
  • 尝试了localService账号&用户
  • 推荐答案

    这是添加到 Vista 的会话 0 隔离功能的一部分.服务现在使用自己的工作站和桌面运行自己的会话.与运行登录提示和屏幕保护程序的会话非常相似.您正在对该会话的桌面进行屏幕截图,其中没有任何内容.不再可能访问用户桌面.这是一项安全功能,可防止粉碎攻击.诚然,我不明白为什么没有删除与桌面交互"复选框.

    This is part of the session 0 isolation feature that was added to Vista. Services now run their own session with their own workstation and desktop. Much like the session that the login prompt and screen saver run in. You are taking a screenshot of that session's desktop, there's nothing in it. Getting access to the user desktop is no longer possible. It is a security feature, it prevents shatter attacks. Admittedly, I don't understand why the 'interact with desktop' checkbox wasn't removed.

    您需要将程序更改为作为Windows 应用程序"而不是服务运行.在启动文件夹中放置一个快捷方式或使用运行注册表项.没关系,当没有用户登录时,没有什么值得拍的.

    You'll need to change your program to run as a "windows application", not a service. Put a shortcut in the Startup folder or use the Run registry key. Which is okay, there's nothing much worth snapping when no user is logged in.

    这篇关于为什么 Windows 服务中的打印屏幕返回黑色图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆