相关疑难解决方法(0)

在服务器桌面会话上捕获屏幕

我开发了一个GUI测试框架,可以按计划对我们公司网站进行集成测试.当某些内容失败时,它会截取桌面的屏幕截图等.这在专用Windows Server 2008上的登录用户上无人值守.

问题是在我已断开远程桌面会话的桌面上截取屏幕截图.我得到以下异常:

System.ComponentModel.Win32Exception (0x80004005): The handle is invalid     
at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)     
at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)     
at IntegrationTester.TestCaseRunner.TakeScreenshot(String name) in C:\VS2010\IntegrationTester\IntegrationTester\Config\TestCaseRunner.cs:line 144     
at IntegrationTester.TestCaseRunner.StartTest() in C:\VS2010\IntegrationTester\IntegrationTester\Config\TestCaseRunner.cs:line 96
Run Code Online (Sandbox Code Playgroud)

TakeScreenshot()方法是这样的:

public static void TakeScreenshot(string name)
        {
            var bounds = Screen.GetBounds(Point.Empty);
            using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                }
                bitmap.Save("someFileName", ImageFormat.Jpeg);
            }
        }
Run Code Online (Sandbox Code Playgroud)

我确保屏幕保护程序设置为"无",没有超时.我还实现了一段代码,它可以执行一些pinvokes来发送鼠标移动,希望它能生成桌面图形处理..但是没有. …

.net c# pinvoke system.drawing windows-server-2008

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

如何在引发Timer事件时Windows服务启动进程?

我创建了一个带有Timer的Windows服务,并且在触发事件中timer.Elapsed我正System.Diagnostics.Process.Start(exe path)以5秒的间隔创建一个process().但是这个过程不会在事件发生时创建.

有没有其他方法这样做?

提前致谢.

private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{       

    Process pr = new Process();
    pr.StartInfo.FileName = @"C:\Program Files\Messenger\msmsgs.exe";
    pr.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    pr.StartInfo.CreateNoWindow = false;
    pr.Start();
}
Run Code Online (Sandbox Code Playgroud)

.net c# windows-services process process.start

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

windows服务屏幕截图返回黑屏

我正在尝试创建 Windows 服务应用程序来捕获屏幕。以前我在启动服务时遇到问题。无论如何,我能够解决它,现在我遇到了另一个问题。现在图像正在保存,但保存为黑屏。为此,在 SOF 中也有很多问题,但我无法解决我的问题。

这是我迄今为止尝试过的:

 public partial class ScreenCaptureService : ServiceBase
    {           
        private static Bitmap bmpScreenshot;
        //private static Graphics gfxScreenshot;
        System.Timers.Timer timer = new System.Timers.Timer();
        public ScreenCaptureService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {              
            TraceService();
            timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);

            timer.Interval = 60000;
            timer.Enabled = true;
        }

        protected override void OnStop()
        {
            timer.Enabled = false;
            TraceService();    
        }

        private void TraceService()
        {    
            Desktop userDesk = new Desktop();
            userDesk.BeginInteraction();
            string path = @"D:\Screen\";
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            string fileName …
Run Code Online (Sandbox Code Playgroud)

c# windows-services screen-capture

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