매 초마다 바탕 화면 캡쳐 화면을 캡처해야합니다. Winform 응용 프로그램에서 잘 실행됩니다. 그러나 코드를 Windows 서비스로 옮긴 후에는 스크린 샷을 캡처하지 않습니다. 왜 그렇게하지 않는지? 여기C# : 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;
}
static int count = 1;
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(@"C:\printscreen" + count++ + ".jpg", ImageFormat.Jpeg);
EventLog.WriteEntry(this.ServiceName, "Screenshot Captured");
}
}
도 참조하십시오. http://stackoverflow.com/questions/1002064/screen-capture-from-windows-service – rogerdpack
참조 http://stackoverflow.com/questions/5200341/capture-screen-on-server-desktop -session/12851218 – Theraot