为什么在Windows服务打印屏幕返回一个黑色的形象?屏幕、黑色、形象、Windows

2023-09-02 21:39:43 作者:玖天揽月

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);
}

在我检查与桌面交互 试过用本地帐户并用户

推荐答案

这是添加到Vista中的会话0隔离功能的一部分。服务现在用自己的工作站和台式机上运行他们自己的会话。就像是在登录提示和屏幕保护程序的运行。你正在服用的会话的桌面截图的会话,没有什么在里面。获得访问用户桌面不再可能。这是一个安全功能,它prevents粉碎攻击。诚然,我不明白为什么与桌面交互复选框没有被清除。

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应用程序,而不是一个服务运行。把一个快捷方式在启动文件夹或使用Run注册表项。这是好的,没有什么太大的价值时,记录在没有用户抢购。

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.