Author Topic: [Source/Tutorial] Remote Desktop Viewer [VB.Net]  (Read 31739 times)

Offline JokeBOx

  • Advanced Member
  • *
  • Topic Author
  • Posts: 206
  • Karma: +8/-27
  • HELLO!!!!!!!!!!!!!!!
  • Awards Winner of 1 Photoshop Challenge Contest [COMMON]
    • View Profile
    • Awards
[Source/Tutorial] Remote Desktop Viewer [VB.Net]
« on: February 07, 2012, 20:16 »
Remote Desktop Viewer


Hello HF, this will be a fairly simple tutorial on how to code a Remote Desktop Viewer. You can use this to either make your own Team Viewer or implement it in a RAT for different purposes... it will be coded in reverse-connection and will use object serialization. I hope you will enjoy this  8)  If you find any errors, please post and I will fix.

Client (Sender)

-Create a windows form project in VS or VB 2010/2008 and call it RDV Client.
-Add 2 buttons and label them Connect and Stream respectively.
-Add a timer and set it to 1000.
-Right click the form and select "View Code"

Header Code required to shortcut your main code.

Code: [Select]
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary

This goes right below "Public Class Form1". They are global TCPClient and Networkstream to allow connection and streaming.

Code: [Select]
Dim client As New TcpClient
Dim nstream As NetworkStream

Now we make a function which returns the screenshot when called.

Code: [Select]
Public Function Desktop() As Image
  Dim bounds As Rectangle = Nothing
  Dim screenshot As System.Drawing.Bitmap = Nothing
  Dim graph As Graphics = Nothing
  bounds = Screen.PrimaryScreen.Bounds
  screenshot = New Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
  graph = Graphics.FromImage(screenshot)
  graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
  Return screenshot
    End Function

Code: [Select]
Image sending function through serialization. It will call the screenshot and send it using the networkstream.
Code: [Select]
Private Sub SendImage()
  Dim bf As New BinaryFormatter
  nstream = client.GetStream
  bf.Serialize(nstream, Desktop())
    End Sub

Double click the timer and type this in to call SendImage function.

Code: [Select]
SendImage()
Double click the Connect button and add this. This will connect to localhost on port 8085.

Code: [Select]
Try
client.Connect("127.0.0.1", 8085)
Catch ex As Exception
MsgBox("Failed to connect...")
End Try

Double click the Stream button and add this to start the timer.

Code: [Select]
Timer1.start()
Conclusion: The client will connect to the server and stream images every 1 second. Done, now moving on to the server.

Server (Receiver)

-Create a windows form project in VS or VB 2010/2008 and call it RDV Server.
-Add a picturebox, fill dock it and change the sizemode to Stretch.
-Add 1 buttons and label it Listen. (if it dissapears try to bring it to front from the control panel)
-Right click the form and select "View Code"

Same imports as the last one.

Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary


Global Variables.. the only difference is that we make 2 threads now to prevent our window from lagging. One for listening and the other for receiving. Also we have the listening server.
Code: [Select]
Dim client As New TcpClient
    Dim server As New TcpListener(8085)
    Dim nstream As NetworkStream
    Dim listening As New Thread(AddressOf Listen)
    Dim getImage As New Thread(AddressOf receiveImage)

Receive Image and deserialize function (opposite to SendImage)
Code: [Select]
Private Sub receiveImage()
  Dim bf As New BinaryFormatter
  While client.Connected = True
    nstream = client.GetStream
    picturebox1.Image = bf.Deserialize(nstream)
  End While
    End Sub

Listening function to accept clients.
Code: [Select]
Private Sub Listen()
  While client.Connected = False
    server.Start()
    client = server.AcceptTcpClient
  End While
  getImage.Start()
    End Sub

Double click the Listen button.
Code: [Select]
listening.Start()
Conclusion: The server is ready to listen and accept any incoming connection. It will receive the images sent by the client.

How to use: Seriously? Open the client and server, click listen (server), then connect (client) and stream(client).

Note: If you wish to use this outside the local network, you might need to portforward the port you used and change the IP address.


I work on this 2 days and finaly finish!

Offline Drk-Shady

  • Junior Member
  • *
  • Posts: 22
  • Karma: +4/-2
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #1 on: April 18, 2012, 02:10 »
Nice tutorial bro...

« Last Edit: April 18, 2012, 17:05 by Drk-Shady »

Offline Drk-Shady

  • Junior Member
  • *
  • Posts: 22
  • Karma: +4/-2
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #2 on: April 23, 2012, 18:23 »
doesn't matter - if people are too lazy to research on it, it is easily accessible here.

Offline Drk-Shady

  • Junior Member
  • *
  • Posts: 22
  • Karma: +4/-2
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #3 on: April 27, 2012, 21:36 »
good point...  :P

Offline Saito.Najumi

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #4 on: January 15, 2013, 06:54 »
nice tut master, I used it to multiple client and one server, just little modification but I want to know how to control it since that the program is just capturing the image only?.
_[']
   (,")
 <,>
 _/ '[_ saito najumi

Offline mvinz03

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #5 on: February 09, 2013, 03:40 »
Excellent Post master..

Offline jackendra

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #6 on: May 17, 2013, 01:37 »
I was hoping you could tell me how to get rid of the mirror effect?

I was trying to fix this (Make it the way I wanted)
for example the client should be the one viewing the picturebox from the pc with the server on it.

At last I didnt get exactly what I wanted but its good enough

then I noticed the infinite mirror effect

where in the image it doubles on whatever windows is open
is there a way to fix this?



@lancasterjacob7@gmail.com

Offline Staff

  • Newbie Member
  • *
  • Posts: 6
  • Karma: +0/-2
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #7 on: July 08, 2013, 16:59 »
I'll try to create this program latter, good tut.

Offline fritchie

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #8 on: November 14, 2013, 15:01 »
i try this code but i need to have 12 clients and view each clients desktop to one server form..

this is the flow that i want:
1. open server
2. once client pc is opened it automatically connect to server
3. then accept client 1 then view its desktop to picturebox 1
4. then client 2 to picturebox 2
5. client 3 to picture box 3 and so on,..

i try to do this but its not working

if clients.ipaddress="127.0.0.1" then
 While clients.Connected = True
            ns = client1.GetStream
            PictureBox1.Image = bf.Deserialize(ns)
        End While
else if  clients.ipaddress="192.168.10.25" then
 While clients.Connected = True
            ns = clients.GetStream
            PictureBox2.Image = bf.Deserialize(ns)
 end while
else if  clients.ipaddress="102.168.10.34" then
 While clients.Connected = True
            ns = clients.GetStream
            PictureBox3.Image = bf.Deserialize(ns)
  end while
end if.

i will make all clients ip static so the server can identify which client will getstream to a specif picture box..

i badly need your help..i hope you can reply as soon as possible..thanks in advance

Offline unaffected

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #9 on: December 05, 2013, 15:20 »
hi sir! this is a good tutorial. thanks! i was trying to modify a little bit by having it support multiple receivers. a little help would be appreciated. thanks!

Offline AJ

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Awards
Re: [Source/Tutorial] Remote Desktop Viewer [VB.Net]
« Reply #10 on: April 09, 2016, 04:53 »


i cant get it to work

« Last Edit: April 09, 2016, 05:01 by AJ »