VB desde tarea programada
Publicado por HDM (3 intervenciones) el 31/12/2009 11:24:10
Hola a todos.
Quiero realizar una tarea programada en la que se ejecuta un codigo VB para capturar la pantalla y guardar la imagen en disco para su posterior analisis. El codigo VB funciona correctamente desde windows o en un batch desde el 'simbolo de sistema' pero no es el caso cuando se ejecuta desde 'tareas programadas'. He comprobado que efectivamente se ejecuta (no da error) pero parte del codigo no funciona, p.e. la captura de pantalla (no copia el contenido al portapapeles). Alguien me puede ayudar ?
Saludos,
HDM
el programa :
<<
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyStartupArguments() _
As String
Dim intCount As Integer
Dim activeWindow As Boolean
Dim save As Boolean
Dim fileName = "default.bmp"
MyStartupArguments = _
System.Environment.GetCommandLineArgs
For intCount = 0 To UBound(MyStartupArguments)
If MyStartupArguments(intCount).ToString = "active" Then
activeWindow = True
ElseIf MyStartupArguments(intCount).ToString = "saveas" Then
If UBound(MyStartupArguments) > intCount Then
save = True
fileName = MyStartupArguments(intCount + 1).ToString
End If
End If
Next
If activeWindow Then
Windows.Forms.SendKeys.SendWait("{PRTSC}")
Else
Windows.Forms.SendKeys.SendWait("+{PRTSC}")
End If
My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
If save Then
Dim d As IDataObject = Clipboard.GetDataObject()
Dim counter As Integer = 0
While Not d.GetDataPresent(DataFormats.Bitmap) And counter < 10
System.Threading.Thread.Sleep(500)
counter = counter + 1
End While
If (d.GetDataPresent(DataFormats.Bitmap)) Then
Dim b As Bitmap = d.GetData(DataFormats.Bitmap)
b.Save(fileName)
End If
End If
Me.Dispose()
Application.Exit()
End Sub
>>
Quiero realizar una tarea programada en la que se ejecuta un codigo VB para capturar la pantalla y guardar la imagen en disco para su posterior analisis. El codigo VB funciona correctamente desde windows o en un batch desde el 'simbolo de sistema' pero no es el caso cuando se ejecuta desde 'tareas programadas'. He comprobado que efectivamente se ejecuta (no da error) pero parte del codigo no funciona, p.e. la captura de pantalla (no copia el contenido al portapapeles). Alguien me puede ayudar ?
Saludos,
HDM
el programa :
<<
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyStartupArguments() _
As String
Dim intCount As Integer
Dim activeWindow As Boolean
Dim save As Boolean
Dim fileName = "default.bmp"
MyStartupArguments = _
System.Environment.GetCommandLineArgs
For intCount = 0 To UBound(MyStartupArguments)
If MyStartupArguments(intCount).ToString = "active" Then
activeWindow = True
ElseIf MyStartupArguments(intCount).ToString = "saveas" Then
If UBound(MyStartupArguments) > intCount Then
save = True
fileName = MyStartupArguments(intCount + 1).ToString
End If
End If
Next
If activeWindow Then
Windows.Forms.SendKeys.SendWait("{PRTSC}")
Else
Windows.Forms.SendKeys.SendWait("+{PRTSC}")
End If
My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
If save Then
Dim d As IDataObject = Clipboard.GetDataObject()
Dim counter As Integer = 0
While Not d.GetDataPresent(DataFormats.Bitmap) And counter < 10
System.Threading.Thread.Sleep(500)
counter = counter + 1
End While
If (d.GetDataPresent(DataFormats.Bitmap)) Then
Dim b As Bitmap = d.GetData(DataFormats.Bitmap)
b.Save(fileName)
End If
End If
Me.Dispose()
Application.Exit()
End Sub
>>
Valora esta pregunta


0