# VBForums CodeBank > CodeBank - Visual Basic .NET >  Remote Desktop Application Example

## uniquegodwin

_Hello everyone..
Here,this is a remote desktop kind of software...It isnt veryy effective..but,I think its not bad for my 1st beginner program on this field in vb.net.
I have used the readymade classes for sending files and messages provided by UNolibs.Net

Using this program,the desktop can be viewed,mouse can be controlled...Keyboard keystrokes cannot be controlled as of now...will be implemented soon.
As for speed,it is not very efficient right now.
_
*A very important Note:This program needs 2 computers to work..It cannot be tested on a single computer.A drawback with this program is that It will not work under different subnets*.

Special Thanks to
UNolibs.Net
for their functions and classes to sendfiles and messages.This is included in the following attachment too
SCREENSHOT OF REMOTE DESKTOP CLIENT


SCREENSHOT OF REMOTE DESKTOP SERVER

----------


## RobDog888

Maybe you could attach the files in .zip format as I think more members have winzip then winrar.  :Wink: 
I only have winzip.  :Frown:

----------


## uniquegodwin

oh..
Ok,Ill do that soon..
Im just working on submitting another code in few minutes  :Smilie:  Ill change the rar into zip right after that Robby.  :Smilie:

----------


## RobDog888

I just looked at the link and it looks interesting. No sockets needed.

----------


## uniquegodwin

yeah,Im a fan of his code... :Wink:  Its really great coding

----------


## uniquegodwin

I changed it to Zip now.I hope no one has problems downloading and extracting it anymore  :Smilie:

----------


## uniquegodwin

hmmm...I guess not many people out here like a remote desktop   :Ehh:

----------


## uniquegodwin

Heyyyy,THREE ppl have downloaded and seen so far...
Thank You guys  :Big Grin:  soo happyyy  :Big Grin: 
Please dont forget to post your comments too ...Be free to say anything bad or good...All for Good  :Wink:

----------


## tovbornotovb

Hey! great code u have here! very nice and cOOLLL!!!! :  :Smilie:  wave: 
when will u release ur next version of this? especially the viewing of the screen seems slow but i think i little coding of your should do!!! im gonna wait for it!!!

----------


## uniquegodwin

Thank you tovb...
You're really encouraging..
Yes I will do the next version very soon..I think I need to convert the picture into bytes and then convert it back..
If you have any ideas,you're welcomed.. :Smilie: 
And next version will also give you the power to send keyboard events...In this version,only mouse events are working  :Smilie:

----------


## tovbornotovb

wow, that would be great!!! im really looking forward to that new version of ur program. i can't wait!...ok! if  i have any ideas, i'll post it in here!! i think creating this kind of program is kind of cool  :Cool:   and say.. an achievement  :Thumb:   as for my part..hehehe. gud luck!  :wave:

----------


## sba-bazzaz

hi 
i'm really exited from your project  :Eek Boom:  
you are realy a professional programmer  :Thumb:  ;
this program is final project of my university term;
can you help me, how do you write this code,
& what are your resources for writing this program?  :wave:  

& i'll be too glad , if i can see new version of your software soon.
good luck  :Wink:   :Thumb:   :wave:

----------


## uniquegodwin

Hi Sba..
Thanks for all the encouraging stuff  :Smilie:   so happy..
I did get help from third party tools like unolibs.net too as mentioned on top..
Go through the code ...
If theres some specific thing you need help with,Ill be glad to help...its your turn to make an attempt on your project before asking help  :Smilie:  so that youll find the specific place where you need help.
Wish you success  :Smilie:

----------


## Lightmoon1992

many thanks for this sample,

i was just asking if i can add a new form in the client side to view the server side, can you please help me   :Cry:   :Cry:

----------


## uniquegodwin

Hi lightmoon...
Im not sure what you mean...
well,adding a new form causes no problem for me...
And I wonder why u need a new form? Theres already a new form to view the server side.
I dont understand what you mean ...can you tell me little more detailed and clearly if possible?  :Smilie:  Thanks for trying this out..contact me through this forum for any help :Smilie:

----------


## Lightmoon1992

hi there

maybe i didnt explain it so well, wish that this time i will.

your program has two sides, first one can control the second one, and i name the controlled side as client, and the side who do control and who can view the other by Server.

what im asking that how can i add new form on the client side" who is monitored by the other side" in which the client can view the server side also, i mean view its screen.

in simple word, i want both sides to have a form that they can view the other through it.

i was working on it, but really i couldnt make it better than this, i have many errors while trying to do it, so can you please post me a newer verson of it contain this, or to tell me how to do this??

many thanks bro  :wave:   :wave:   :Thumb:

----------


## uniquegodwin

Hi lightmoon,
I will definitely help u in anyway I can...
I cant right now immediatly get a newer version...but I will after a while  :Smilie: 
but,I will do all necessary help so you can make it yourself ..You could post the better version too  :Smilie: 

ok,the main concept ive used to do this is that...I use the sendmessage function to send command to the other computer and i check that command there...
for example...i can send the message "viewscreen" and when the other computer recieves it,i set it to send a picture of the screen.
please tell me what errors you are facing...I will help you out  :Smilie:

----------


## Lightmoon1992

many thanks for replay,

i got everything now ok, but the point is sometimes i got IOException on the side i add the new form on it to view the other side screen.

also if you remember that part, i got "error 5, use another file name" in message box.

wish that you will help me in this and many thanks for you.

waiting your answer

----------


## Lightmoon1992

the main error i have now, and i think it cause all the problems that in the client class, i have IOexception, which is "Unable to open file", i tried to comment the throw statment, but also i have null reference in the following line, i think you can remember it, its a part of Client class code

  Dim buffer(PacketSize - 1) As Byte
wd = fileStream.Read(buffer, 0, PacketSize)

in this line i have the exception, can you please tell me, what is the reference may has null value??

another thing, the other side view almost of the time one or two screen shots of my side, and then this exception occures.

can you please help me in this??

----------


## uniquegodwin

Hey..
Dont change anything in those server client class files...I didnt make them..I got them from unolibs...
http://www.codeproject.com/useritems/UnoLibsNet_V2.asp

And there is a small problem with the efficiency of my program...It is slow...and especially if you want it to work both sides at the same time,Its going to be more slow.
It captures the screen image and stores it on the c:\ on the other computer...
As soon as the file gets transferred,it requests for the next frame..
This happens continously...thats how this thing works  :Smilie:  So,if you use both sides at the same time,it would perform very badly I think

----------


## uniquegodwin

I need to use serialization or something to make it work better I guess  :Smilie:  Ive used a childs method now.

----------


## uniquegodwin

> i got everything now ok, but the point is sometimes i got IOException on the side i add the new form on it to view the other side screen.


Did you use the event handler which listens for the message? Did you declare a new instance of the class for listening??

----------


## dglienna

You'd have to check which byte has been changed, and only send the changed bytes.  That's how W2K's Terminal Server is.  It is super fast for most things.

----------


## Lightmoon1992

hi,

wish you help me in this part, cause i need your help here so hard.

what i was looking forward is to make server broadcast his screen for multi clients,i mean that server will display its screen on two clients monitor's or more, but at least im testing the applicatino on two clients.

i tried to send them the two files in same two messages,

  clsc.SendMessage(arr(0).ToString, 1234, "readyforcap")
  clsc.SendMessage(arr(1).ToString, 1234, "readyforcap")

  clsc.SendFiles(arr(0).ToString, 1234, dw.FileNames)
  clsc.SendFiles(arr(1).ToString, 1234, dw.FileNames)

the arr array contains the clients IP's which i will broadcast my screen to.

this caused many exceptions for me, the first one said "Stack Empty", and many other, most of them in the function " SendFilesTS()".

can you please help me in this, and tell me how can i solve this??

many thanks

----------


## uniquegodwin

sendfilesTS???
Ill just reply u soon buddy...Im in my office right now...in a hurry..Ill get back soon

----------


## marc180

this is great nice work i think this is extremely good for your first try.  :Thumb:   :big yellow:

----------


## uniquegodwin

Thanks Marc  :Smilie:

----------


## riteshjain1982

Hi,
  It's really one the best Application i have seen................do you have any idea about how to go for Keylogger thing........

Regards,
Ritesh

----------


## uniquegodwin

Hi,
Its very simple to make a keylogger if you use an API  :Smilie:

----------


## uniquegodwin

But I guess vbforums will not support u making such stuff  :Smilie:

----------


## anna7

I executed the application "remote desktop server " and now I have problems when I start the pc.   :Sick:  

it shows me the window for debugger this application. it has installed something to me in the start??


ERROR:




> 'svchost.exe': se cargó 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', no se pueden cargar símbolos.
> 'svchost.exe': se cargó 'C:\Archivos de programa\svchost.exe', no se pueden cargar símbolos.
> 'svchost.exe': se cargó 'c:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll'  , no se pueden cargar símbolos.
> 'svchost.exe': se cargó 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', no se pueden cargar símbolos.
> 'svchost.exe': se cargó 'c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll', no se pueden cargar símbolos.
> 'svchost.exe': se cargó 'c:\windows\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dl  l', no se pueden cargar símbolos.
> 'svchost.exe': se cargó 'c:\windows\assembly\gac\mscorlib.resources\1.0.5000.0_es_b77a5c561934e089\mscorlib.resources.dll', no se pueden cargar símbolos.
> Excepción no controlada del tipo 'System.TypeInitializationException' en svchost.exe
> 
> Información adicional: Se inició una excepción en el inicializador de tipo de "System.Net.Sockets.Socket"


Some help?

----------


## uniquegodwin

You have problems when you start your pc?
I will check the code again Anna,please keep me updated if you still have some problem...

----------


## anna7

Yes  I  still  have problems. 

I don't know if it has to see something, but since I tried this code  appears this message "*You're under attack*" when start the pc also, and  I cannot eliminate it.



regards,

Anna

----------


## uniquegodwin

I have recompiled the server code also..If possible,contact me on any IM ..Ill help you online...
Btw,yes you're right...there was an executable called svchost.exe..I really dont know how it got in there...I've fully freshly recompiled the code and uploaded.
If you have more problems,try contacting me online.
Thanks

----------


## anna7

I have solved the problem. Ultimately I found the copy of the file , what "*svchost.exe*" had create it. This one was the responsible of all the problems and the message: "You're under attack"

I deactivated this service and delete the file that it had created.


regards,

Anna

----------


## uniquegodwin

Awesome!! :-)

----------


## demon.KILER

thx for this code I own U  :Big Grin:

----------


## demon.KILER

but I have this error and I cannot see any thing wrong with that line 


VB Code:
wd = Client.Receive(buffer, PacketSize, Sockets.SocketFlags.None)
Error	42	Overload resolution failed because no accessible 'Receive' can be called without a narrowing conversion:
    'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'buffers' narrows from '1-dimensional array of Byte' to 'System.Collections.Generic.IList(Of System.ArraySegment(Of Byte))'.
    'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'socketFlags' narrows from 'Long' to 'System.Net.Sockets.SocketFlags'.
    'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'errorCode' narrows from 'System.Net.Sockets.SocketFlags' to 'System.Net.Sockets.SocketError'.
    'Public Function Receive(buffer() As Byte, size As Integer, socketFlags As System.Net.Sockets.SocketFlags) As Integer': Argument matching parameter 'size' narrows from 'Long' to 'Integer'.	C:\Documents and Settings\TEMP\Desktop\Remote Desktop Server\Remote Desktop Server\ServerClass.vb	192	22	WindowsApplication2




VB Code:
wd = Client.Receive(buffer, PacketSize, Sockets.SocketFlags.None)

Error	41	Overload resolution failed because no accessible 'Receive' can be called without a narrowing conversion:
    'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'buffers' narrows from '1-dimensional array of Byte' to 'System.Collections.Generic.IList(Of System.ArraySegment(Of Byte))'.
    'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'socketFlags' narrows from 'Long' to 'System.Net.Sockets.SocketFlags'.
    'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'errorCode' narrows from 'System.Net.Sockets.SocketFlags' to 'System.Net.Sockets.SocketError'.
    'Public Function Receive(buffer() As Byte, size As Integer, socketFlags As System.Net.Sockets.SocketFlags) As Integer': Argument matching parameter 'size' narrows from 'Long' to 'Integer'.	C:\Documents and Settings\TEMP\Desktop\Remote Desktop Server\Remote Desktop Server\ServerClass.vb	189	18	WindowsApplication2


VB Code:
client.Send(buffer, wd, Sockets.SocketFlags.None)

Error	3	Overload resolution failed because no accessible 'Send' can be called without a narrowing conversion:
    'Public Function Send(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'buffers' narrows from '1-dimensional array of Byte' to 'System.Collections.Generic.IList(Of System.ArraySegment(Of Byte))'.
    'Public Function Send(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'socketFlags' narrows from 'Long' to 'System.Net.Sockets.SocketFlags'.
    'Public Function Send(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'errorCode' narrows from 'System.Net.Sockets.SocketFlags' to 'System.Net.Sockets.SocketError'.
    'Public Function Send(buffer() As Byte, size As Integer, socketFlags As System.Net.Sockets.SocketFlags) As Integer': Argument matching parameter 'size' narrows from 'Long' to 'Integer'.	C:\Documents and Settings\TEMP\Desktop\Remote Desktop Server\Remote Desktop Server\ClientClass.vb	79	13	WindowsApplication2

----------


## demon.KILER

Any way I don't need those functions thx  :Smilie:

----------


## TTn

> And next version will also give you the power to send keyboard events...In this version,only mouse events are working


 You might try using this API:

VB Code:
Public Declare Function apiAttachThreadInput Lib "user32" Alias "AttachThreadInput" (ByVal idAttach As Integer, ByVal idAttachTo As Integer, ByVal fAttach As Integer) As Integer
To send keys to more than one window (x) at a time.  
I'm not sure if you can use it in this situation.

Oh, and no more attacking PC's, someone might think you're a terrorist!  lol  :Big Grin:  



> I don't know if it has to see something, but since I tried this code appears this message *"You're under attack"* when start the pc also, and I cannot eliminate it.

----------


## vuyiswamb

Thats a Rat,we dont Built harmfull programs here, Stop it or your Account will be deleted here. Be a good man :Frown:   :Embarrassment:   :wave:

----------


## bushramughal

> Maybe you could attach the files in .zip format as I think more members have winzip then winrar. 
> I only have winzip.


1:i found error in client class the code is  client.Send(buffer, wd, Sockets.SocketFlags.None)
2: in server class error is   wd = Client.Receive(buffer, PacketSize, Sockets.SocketFlags.None)
if anyone have solution of these problem plz contact me :Cry:   :Cry:

----------


## AkkeDaBest

> but I have this error and I cannot see any thing wrong with that line 
> 
> 
> VB Code:
> wd = Client.Receive(buffer, PacketSize, Sockets.SocketFlags.None)
> Error	42	Overload resolution failed because no accessible 'Receive' can be called without a narrowing conversion:
>     'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'buffers' narrows from '1-dimensional array of Byte' to 'System.Collections.Generic.IList(Of System.ArraySegment(Of Byte))'.
>     'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'socketFlags' narrows from 'Long' to 'System.Net.Sockets.SocketFlags'.
>     'Public Function Receive(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte)), socketFlags As System.Net.Sockets.SocketFlags, ByRef errorCode As System.Net.Sockets.SocketError) As Integer': Argument matching parameter 'errorCode' narrows from 'System.Net.Sockets.SocketFlags' to 'System.Net.Sockets.SocketError'.
> ...


I have the same problem.

And I use visual studio 2008

What could i change them to?

----------


## uniquegodwin

Hello,
It's been more than 2 years since I posted that code.
It's easier to do the same using remoting if you ask me now.
It takes fewer lines of code...and is much more simpler.

1.)Setup a remoting server
2.) set a remoting client
3.) In the remoting server class,make a function to take screenshot of the server and return it as a memorystream.
4.)In the remoting client,call that server function and display the picture on a picturebox. (use a timer to do it repeatedly)

It's that simple. If you have no clue about what I'm talking about....trust me and follow these steps...
1.) Search for "remoting in vb.net" on google....find how to do it...
2.) Search for "screenshot vb.net" ....you'll get the code for it somewhere online
3.) Use a timer on the remoting client and call the server's screenshot function repeatedly
4.) combine those two and rock it!! :-) (This is the best solution for beginners...not for people who ask for performance.This will not work well over the internet...it will work best only through LAN)


I'd love to help you with the code....but Unfortunately,I don't have the time to do the code and post it right now....but I will soon when I can....

Trust and try the steps mentioned above.....and Success is certainly yours!!!

Hope that helps....

----------


## jhon7001

hi Dear
           do you know something if i want to develop same applicatoin for web like msn messanger multiple users can view eachother desktop i think it will be interesting.

----------


## rajukrishna

hi godwin 
  i'm krishna i need ur newer version code ,i expect you anyway ur reply please send me ...........
         i have many problem please send me zip file  :Eek Boom:

----------


## allstarsdied4me

I have 3 erros and like 24 warnings! :s
Help.. Message me  :Wink:

----------


## allstarsdied4me

im still quit learning!

----------


## chris128

For anyone who is interested in improving the speed of such a program - you should look into how programs like VNC work (VNC is a remote computer control program - www.realvnc.com). From Wikipedia's VNC article:



> The server sends small rectangles of the framebuffer to the client. In its simplest form, the VNC protocol can use a lot of bandwidth, so various methods have been devised to reduce the communication overhead. For example, there are various encodings (methods to determine the most efficient way to transfer these rectangles). The VNC protocol allows the client and server to negotiate which encoding will be used. The simplest encoding, which is supported by all clients and servers, is the raw encoding where pixel data is sent in left-to-right scanline order, and after the original full screen has been transmitted, only transfers rectangles that change. This encoding works very well if only a small portion of the screen changes from one frame to the next (like a mouse pointer moving across a desktop, or text being written at the cursor), but bandwidth demands get very high if a lot of pixels change at the same time, such as when scrolling a window or viewing full-screen video.

----------


## rameioj13

will it run to vb6??

----------


## gowthamforever

Existing link to unolibs.net does't work so please use this link 
http://www.codeproject.com/KB/vb/UnoLibsNet_V2.aspx

----------


## alphacore

how can i view the code pls..

----------


## paki42o

i love tht code can i have in vb6 same code???

----------


## cctvofnj

Hello i gotyour code a while back i been playing with it and think its awesome  do you think one day you will make a newer ver of this one. maybe add a new opition in it like what teamviewer is doing instead of putting in ip addresses can put in like numbers or something but still can do the same thing? if so please let me know thank you.....  :wave:   :Alien Frog:

----------


## oliv7836

i've just downloaded it :-) Will try it out soon  :Big Grin: ...!

----------


## weshuiz13

i cant find the link i have looked evrywhare on the site but cant find it  :Frown:  but i like your idea about this its simple becuse it only needs the ip no port like also the msg option thing like ok and cancel mouse controll msg system and shut down his pc are my 3 favorite of rats dude i like it wish i could find it ps.i may maybe made some mistakes with writing this but im not english srry 4 it

----------


## suzey

where to download?

----------


## uniquegodwin

It was not a Trojan or RAT. A RAT would run hidden but this was fully visible and open and just an example. I guess the vbforums moderators have removed the attachment. I don't have a copy of that file for myself to see the code that I posted 10 years back.

----------


## Leary222

where can I download this ?

----------


## juuan16

Can i have the code for this app? I really really need it for my school. But i have no idea how to create it. This is exactly what i needed. Thanks!

----------


## jdc20181

What a bummer it had to be infected with a virus :/ I really need something like this handy and i can see the SC to...

----------


## bayarx

where  can i download the code?

----------


## babukp

Anyone have idea about multi remote display concept,to see upto 6systems in a single desktop at a time,like camera connected to tv

----------


## jdc20181

You should try google. If you need remote pairing with devices e.g.  like how Directv does you will need a Server to do such things.

----------

