Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# RemoteControl Remote
Hi everyone,
I have one idea and I want to accomplish it to be real.
 
Let say I have two computer (running XP and Windows 7 or 8 or server 2k8).
Or let's give them a name:
timon : desktop
pumba : server
 
What I need to have is that make an application running as a service on "pumba" and another application (not a service) running on "timon".
When I launch timon_apps with some parameter pumba_apps make something (like opening "notepad.exe" or run a task any task scheduler.
Means that I want to execute the remote application service by executing a local application with a parameter.
For example :
C:\timon_apps.exe /param=notepad.exe /server=pumba
and then "pumba_apps.exe" run as a service on pumba open the notepad application.
 
Am I clear with my project ?
 
I do not really want to have a code for that but only the process on how can I achieve this and some suggestions on how to make it.
 
Any help would be appreciated.
 
Thanks in advance for all.
Posted 20-Sep-12 5:40am
Comments
Sergey Alexandrovich Kryukov at 20-Sep-12 12:01pm
   
I would say, even RDP and Windows Services. Please see my answer.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First, look how RDP service works. You can use it to launch some applications on the machine acting as a server. I'm not saying that you should use RDP. I'm just saying that to be able to run applications on the server on request of client, you apparently need to create a Windows Service (presumably, running with the "Auto" start-up option), which is a network service and which can take orders from the clients and launch applications on their behalf. As always with the custom network services, you will need to have your own application-level protocol, somewhat similar to RDP, only much simpler.
 
If you have any questions on how to proceed with this approach, I gladly explain more.
 
For now, you can start here:
http://msdn.microsoft.com/en-us/library/aa984464%28v=vs.71%29.aspx[^].
 
See also:
http://en.wikipedia.org/wiki/Remote_Desktop_Services[^],
http://en.wikipedia.org/wiki/Remote_Desktop_Protocol[^],
http://en.wikipedia.org/wiki/Application_layer[^].
 
However, running the UI applications like Notepad make no sense at all. You will start it on the server side, so what? Don't think it can be shown on the client screen or something like that. If this is what you need, simply use RDP. There are a couple of good CodeProject articles where the authors present their own RDP clients. Using them, you will see how can you use RDP protocol in your own client-side application:
Remote Desktop using C#.NET[^],
Palantir - Remote Desktop Manager[^].
 
The second one, Palantir, is my favorite; it once helped me in the situation where the Microsoft client was failing to do the job.
 
[EDIT: in response to the comment to this answer:]
 
Please see my comment below, about piping the input and output of the application to be executed on the server side. Instead of relying on some files (which would be just additional channel of data exchange which you would need to devise, care about synchronization, etc. — too boring stuff), you can use some applications which could work in the console-mode on the server.
 
To pass data to such application, you have two mechanism: first, you can pass a command line string which your service should pass to the application; second: if you have an application which can work with interactive console input from the user, you can pipe such input by redirecting the StandardInput stream.
 
To get output from the console application, you could redirect the streams StandardOutput and/or StandardError.
 
Please see the class System.Diagnostics.Process and code samples related to command line and redirection:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[^].
 
Two last MSDN page show the code sample for re-direction, and the command line is passed as a second parameter of this Start method:
http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx[^].
 
Or it can be passed in the ProcessStartInfo parameter:
http://msdn.microsoft.com/en-us/library/0w4h05yb.aspx[^].
 
If you can write the applications to be started on the server side, it can be much easier because you can design them to be convenient for working through your client-server code using your own application-level protocol designed according to your needs. In particular, for command line parsing I could recommend my utility (and another, alternative utility is recommended in my article):
Enumeration-based Command Line Utility[^].
 
For networking, there are a number of alternatives on different levels, from sockets to self-hosted WCF. In your case, I would rather recommend using the classes System.Net.Sockets.TcpListener and System.Net.Sockets.TcpClient:
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx[^].
 
Please also see my past answer on some basic ideas about networking service and related threading architecture:
Multple clients from same port Number[^].
 
Your follow-up questions are quite welcome.
 
—SA
  Permalink  
v4
Comments
vantoora at 21-Sep-12 3:59am
   
Thank you for your reply Sergey.
I think I would start from the links you provided and then come back to you for the situation status.
And I am conscious that notepad will not appear on my own screen, and this is not my approach. I just need to initiate the remote program to run something on the server hosting the program. Maybe I just need a log file, or something like that but it is not yet what I need for the moment.
 
Thanks again for your help.
Sergey Alexandrovich Kryukov at 21-Sep-12 11:01am
   
Thank you for the feedback.
 
Is this is what you describe, you can do everything with more simple custom service. You could do a bit more delicate thing. For example, you can execute some application on server side, feed some data provided by the client to it, collect data output from that application and send the output to the client. As soon as your application running on the server side is non-interactive (all almost non-interactive: it still could use console input; and such input can be piped into such application), such things could be easily transported through a simple custom protocol and marshaled the way which would look as a function call from the standpoint of some client application. You would not even need the command line shown in your example or log files. However, if you need, you would be able to use the log files, too, but it would be just the minor complication, not simplification. …Perhaps, I'll explain more by updating the answer.
--SA
Sergey Alexandrovich Kryukov at 21-Sep-12 11:21am
   
Done. Please see the update, after [EDIT...]. You already got a pretty detailed outline of the project you would need to do. Your follow-up questions are welcome.
--SA
vantoora at 21-Sep-12 11:45am
   
Thanks to you.
Yeah this is what I expected to have.
To tell you the truth I don't know yet what I'm going to do with this kind of project for a real use in my work but I just want to know something else. I'm not a guru in C# but tried to be one.
I'm now experiencing on creating many kind of Application Service and then will try to manipulate it with ServiceController and will back again here as I already have some question but better next time when I'll finish to study.
Thanks
Sergey Alexandrovich Kryukov at 21-Sep-12 12:10pm
   
Very good. You are welcome.
If you get more clear about your intents and have more problems, you are welcome to ask more questions. Next time, try to start question with explanation of your ultimate goals.
Good luck,
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is the alternative solution which might fit your purposes: Sysinternals PsExec tool.
 
First of all, Sysinternals is a set of utilities which a must-have for any developer on Windows. Please see:
http://technet.microsoft.com/en-us/sysinternals[^].
 
It would be good to download the whole suite and many utilities are very useful. This is the utility I mean:
http://technet.microsoft.com/en-us/sysinternals/bb897553[^].
 
This is the related article by the creator of Sysinternals Mark Russinovich (http://en.wikipedia.org/wiki/Russinovich[^], http://www.windowsitpro.com/author/5056226/MarkRussinovich[^]):
 
http://www.windowsitpro.com/article/remote-computing/psexec[^].
 
I knew the similar tool should exist, did not quite remember where to look…
 
Good luck,
—SA
  Permalink  
Comments
vantoora at 1-Oct-12 3:52am
   
Dear Sergey,
Thanks for your last solution but I think the first is more appropriate of what I need.
I'll stand by this project for 3 weeks from now as I'm working on a new project on Linux. It's on Centreon+Nagios (a monitoring web application).
And from this study, if you already heard about Nagios and/or Centreon you'll get exactly what will my goal. Centreon have a service permanently running on a server (a linux one) and to check the status of a remote server I need to install NSClient++ (permanently running as a service on a remote windows server) and the server ask NSClient++ to get some information (cpu usage, memory usage, disk space, ...) and it will return the desired information back.
So this is exactly what I need to achieve.
As I have this idea in my head I'll try to describe you what I'm going to do with this kind of software this afternoon so you can judge if it's feasible or not.
 
Thanks again for considering my project.
Sergey Alexandrovich Kryukov at 1-Oct-12 11:48am
   
I just tried to provide suggestions to cover possible options as fully as possible. Thank you for accepting one.
I never heard of Nagious or Centreon so far though.
--SA
vantoora at 1-Oct-12 7:35am
   
Dear Sergey,
So here I am for the details of my project that I was thinking to make with the process we discussed earlier.
I have 4 servers for production use, and 4 servers for backup (hot backup)
The productions server contains millions of files (most of them a xml and jpg files, means little files). I have to backup all of those files by using "robocopy" (a µsoft's program) every 30 minutes.
Files are classified as a project (e.g. ProjectA, ProjectB, ProjectC, ...) and my tasks scheduler are configured accordingly.
Everytime there is a new project, I need to make a new script for that project, and everytime a project is finished I need to delete data of that project on my backup server (once someone else informed me that they have finished the project and archived it).
For the backup I do not need to compare the source with the destination folder but only copy new files (incremental backup), so I need to check often the destination if it is not full (the space disk), and if it is full I need to make a mirroring one time.
So what I need to achieve is to centralize one system which :
1. can create a script automatically once a new project is added (done)
2. can create a mirroring script if there is a low disk space or a purge from the source was made (done but manually)
3. can verify if a new project is added but I was not informed (done)
4. send me the logs of backup process by mail (done)
5. send me the logs of errors happened during backup process by mail (done)
6. create a script which verify all space disk and create script for purge accordingly and execute the script once there is a full/low disk space (not yet done...)
... means a backup system management.
 
For the point (2) it's done manually everytime so need to check my 4 servers everyday.
For the point (6) this is where I need to develop a program like NSClient++ so I can run the script automatically. Just setting up a task scheduler on my box and it'll run automatically for me. I just need to check my mail so even at home I can have an idea of what happen on my servers.
 
So waiting for your suggestion for that.
If I am not more clear, you can ask.
 
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 225
1 BillWoodruff 200
2 OriginalGriff 191
3 Kornfeld Eliyahu Peter 175
4 CPallini 164


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100