我有一个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) 我们必须从Windows服务运行一个进程并从中获取屏幕截图.
我们尝试了BitBlt和PrintWindow Win32调用,但都给出了空白(黑色)位图.
如果我们从普通用户进程运行我们的代码,它就可以正常运行.
这有可能吗?或者可以尝试另一种方法吗?
我们尝试的事情:
我们还注意到PrintWindow对我们的情况更好,如果窗口在另一个窗口后面,它可以工作.
对于其他要求,父进程和子进程必须位于同一用户下.我们无法真正使用从一个进程到另一个进程的模拟.
我必须在每一秒后捕获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) 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)
我写了一个代码,打开浏览器并截图。但是当我通过远程桌面运行它时,它会拍摄空白图像。
谁能建议一下,如何通过 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) 我对 Microsoft 世界有点陌生。我已经阅读了这个答案和许多其他链接,我知道在 Vista 之后,Windows 服务无法与桌面交互。
但是,我遇到了紧急情况,必须快速找到解决方法。我需要我的 Windows 服务以某种方式打开带有 URL 的浏览器(现在任何类型的丑陋黑客都可以)。答案指出:
您需要编写一个单独的代理应用程序,它将在用户登录时自动启动,并与您的服务进行通信。然后代理可以启动浏览器或执行您需要的任何其他操作。
有人可以向我解释我如何以简单的方式做到这一点吗?该服务将如何与这个“代理”交谈?这个“代理”究竟是什么?
任何链接或建议将不胜感激。
编辑:目前。我的服务尝试运行以下代码:System.Diagnostics.Process.Start("www.google.com");
后来我发现,这不起作用