屏幕捕获代码在WinForms中运行正常,但不作为服务运行

时间:2017-06-11 17:56:32

标签: vb.net

我想创建一个用于屏幕捕获的Windows服务,但它无法正常工作。

进程到达ScrenCapture.Start()但它没有做任何事情并且不会抛出错误。

如果我在Windows窗体中测试它,相同的代码效果很好:

代码:

Imports Microsoft.Expression.Encoder.ScreenCapture
Imports isc.isc_utility
Public Class isc_utility_screen_capture
Dim ScrenCapture As ScreenCaptureJob = New ScreenCaptureJob()
Shared SrvDir As String =   System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
Function StartRecording(ByVal FileName As String)
    Dim Dir = SrvDir
    Dim FileToRecord As String
    FileToRecord = Dir + "\" + FileName + ".wmv"
    Try
        ScrenCapture.OutputScreenCaptureFileName = FileToRecord
        ScrenCapture.CaptureMouseCursor = True
        ScrenCapture.Start()
        WriteEventLogInformation("Capturing Video.... " + FileName + " " + Date.Now)
        Return FileName
    Catch ex As Exception
        WriteEventLogError(ex.Message)
        Return "-1"
    End Try
End Function

Function StopRecording()
    Try
        ScrenCapture.Stop()
        Return 1
    Catch ex As Exception
        WriteEventLogError(ex.Message)
        Return -1
      End Try
   End Function
End Class

可能会发生什么?

0 个答案:

没有答案