Click here to Skip to main content
Click here to Skip to main content

Remote processes and machine control of Windows NT based systems (2000/XP)

By , 1 Apr 2012
 

Fig. 1 Client application running with various context menu(s)

Introduction

There are times as a Windows network administrator you would like to control certain aspects of machines sitting remotely, without having to install and trigger an application on the remote machine which will communicate with the administrator's machine.

How to use the client application for control

  • Ctrl + A (or File -> Add machine):

    Add a machine whose control is required and processes to be monitored (refer fig. 2).

    Fig. 2 Adding a machine

    In case of an error, an information balloon will be shown in the system tray as shown in fig. 3.

    Fig. 3 Information balloon

  • Context menu(s) on for a connected machine: Refer fig. 1
    • Refresh the process list.
    • Execute a process on the connected machine.
    • Delete the machine from being monitored.
    • Shutdown: Halt/reboot the machine or cancel the halt/reboot request.
  • Context menu on any process on a machine: Refer fig. 1
    • End process
  • Timer Settings (or Settings->Timers): Refer fig. 4
    • Process refresh: Wait for “x” seconds before querying all connected machines for their processes list. This is apart from what time will be taken to query the processes on remote machines.
    • Shut down delay: Wait for “x” seconds before executing a shutdown or reboot command on the remote machine.

    Fig. 4 Timer refresh rate

  • File -> Save /Save As

    Save the connected machine(s) information to the requested directory. All machine monitoring can again be loaded while using the File -> Open command, without adding all machines individually.

Security note:- Currently the administrator passwords are just serialized to a file without encryption. Hence, one can see the passwords by just opening the file in a normal text editor.

The how of controlling machines remotely

  • There is one client application that displays all the processes of the requested remote machines with a pre-determined refresh rate.
  • There is one server application (one per remote machine), which has to be triggered on the remote machine automatically (without any user intervention), when a request for monitoring and control is made to it. This server application will send periodic processes updates to the client. For example, if there are 5 remote machines being monitored then there are 5 remote server applications, which keep sending periodic process updates and one client application from where all remote machines are being monitored.
  • The client can also request certain other tasks to the server application like triggering a new process, kill an existing process on the remote machine. If required, requests to reboot or shut down the remote machine can also be made.

Basic implementation scheme

Fig. 5 Client application with the server executable embedded in it's resources

The client application holds the server application (executable) in it’s resource section, like any other resource, viz., bitmaps, icons, menus etc. (refer fig. 5).

  • When the client asks to connect and monitor any remote machine, it has to supply it’s IP address and Administrator logon’s password.
  • The client application makes an attempt to connect to the ADMIN and IPC resources using the Windows API WNetAddConnection2(). (CRemoteAdministrator::EstablishAllConnections() in the accompanying project).
  • After connecting to the remote machine through the ADMIN and IPC connections, the client application loads the server executable from the it’s resource section. The client application copies the server executable to the remote machine’s System32 directory. (CRemoteAdministrator:: CopyServiceExeToRemoteMachine() in the accompanying project)

Refer fig. 6 for the remote copying scheme

Fig. 6 Server executable copying scheme

The client application gets the HANDLE to the service manager of the remote machine, as an IPC connection has been established above. The client application then starts the server executable copied in the remote machine’s System32 directory as a service. This all is independent, done automatically and is unknown to user of the remote machine.

  • Once the server application gets triggered as a service, it starts sending the list of processes to the client application through named pipes.
  • Each server application has a minimum of four threads that service a single client.
    • sending the list of processes to the client application (Thread function RemoteAdminProcessInfoThread())
    • to process a request from the client to start a process on the remote machine (Thread function RemoteAdminExecuteProcessThread())
    • to process a request from the client to end a process on the remote machine (Thread function RemoteAdminKillProcessThread())
    • to process a request from the client to reboot or shutdown the remote machine (Thread function RemoteAdminSysShutdownThread())

Implementation details of the client application

The client is a standard SDI application based on MFC’s document/view architecture. The important classes in the client application are :

  • CMachineInfo : This class holds the HANDLES to four named pipes with which a remote machine connection has been established for requesting different tasks (remote process read, start, kill and machine shutdown/reboot). This class also holds a list of current processes on the remote machine. It also contains strings for password, IP and logon type (which has to be Administrator only). CMachineInfo is derived from MFC’s Cobject so that it can be serialized.
  • CRemoteAdministrator : This class handles all the network communication based on named pipes with different remote machines. This class holds a list of CMachineInfo objects. This CMachineInfo list can be serialized to a file and loaded later.
  • CRemoteAdminDoc : This is the MFC’s CDocument derived class which holds all data regarding the application. This class holds the only object of CRemoteAdministrator.

Implementation details of the server application

  • Once the server application has been started as a service on the remote machine, the client application makes a connection to the server through four named pipes. These four HANDLES of named pipes service the client requests through 4 threads (RemoteAdminProcessInfoThread(), RemoteAdminExecuteProcessThread(), RemoteAdminKillProcessThread(), RemoteAdminSysShutdownThread()).
  • There is another thread that is constantly updating the processes list (UpdateProcessInfoList()).
  • When there is a new named pipe connection the counter lServicePipeInstanceCount is incremented. Similarly, when a named pipe is disconnected, it is decremented. When there are no named pipes (lServicePipeInstanceCount == 0), the server application is stopped and deleted from the remote machine.

Acknowledgements

Inspired by the tools at Sysinternals. Thanks to Zoltan Csizmadia for sharing his code).

License

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

About the Author

Prateek Kaul
Web Developer
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionPls help me start this!memberGomika26 May '10 - 1:35 
I'd really like to try this app, but I guess i'm too noobish to get it to work. i've built the project. Its time to run it, but i cant.
 
How do I connect to the remote pc?
Do I need to install any service on the remote pc? (Ive read the post, and it says something about it installs the service for itself? then deletes it when its closed. I dont understand this.. I keep getting errors like "could not copy the service application to the remote pc" "could not start remote service" "could not connect")
 
Last question: what is the Administrator account in the client app? Is it an admin account on the remote pc, or is it an account of the application itself?
 
All help is very much appriciated!
Regards
Gomika.
AnswerRe: Pls help me start this!memberPrateek Kaul9 Jun '10 - 3:42 
You just need to run the exe on any machine. Now, add the machine IP of the Windows machine that you are trying to connect and give that machine's login name and password(obviously who has administrative privileges)
 
The machine on which you are running the program will now
use the cedentials of the remote machine (which you supplied) and will install the service on the remote machine and start monitoring it.
GeneralProblems : Start Connect !memberoverload25 Apr '05 - 19:37 
Thanks for giving good program !!
I like your program.I have used your program but I have some errors :
1. Can't connect to remote service . ...
I checked admin$,ipc$ on remote pc have already shared.My OS is Windows XP.
when I used GetLastError(), I received system error : 5 (access is deny ). My username and password (administrator account) is correct. I have used them to login my pc with administrator right. Can you help me how to install and run your program ! Thank you very much !Confused | :confused:
 
anh
GeneralRe: Problems : Start Connect !memberPrateek Kaul27 Apr '05 - 18:44 
Is there is firewall between the PCs you are trying to connect? I suppose because of Windows XP SP2 having a firewall ON by default this may be a problem. Try turning off the firewall and try again. If possible try on Windows 2000 also.
 
Let me know.
 

 
Prateek Kaul

QuestionWindows CE Platform ?memberPaulJ9 Dec '04 - 6:51 
Could this be accomplished in Windows CE or Windows CE .NET ?
 
Paul Jahans
Generali can run the promemberv_anh9 Mar '04 - 16:08 
i build the code and has no error but the pro still can't run. because:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\psapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comdlg32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shlwapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shell32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winspool.drv', no matching symbolic information found.
Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.10.0_x-ww_f7fb5805\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.
The thread 0xF3C has exited with code 0 (0x0).
The program 'D:\Internet\RemoteAdmin_demo\RemoteAdmin\Remote Admin Client\Res\RemoteAdminService.exe' has exited with code 0 (0x0).
why????? i'm a new in VC++ can you tell me to run the pro.
and do you have the source code write in VB. Can you share for me
 
viet anh
Generalerror in connectingsusspanbu21 Feb '04 - 0:02 
which platform sdk we have to down load inorder to run this under windows 98.even in some xp based based machines also its not running. there also its having the same errors.the platform sdk consists nearly 750MB space. so would u like to say minimum dlls,files which we need to run this program,so that we can copy them to projects directory from any .NET files or .NET directory files.i tried once by copying the psapi.h,psapi.lib,psapi.dll from vc7 include files,dlls. but still its displaying the error like 'NIIF_NONE' ,for this which i have to copy?may be any process header file & systray icon header files?


QuestionGetting Connected?memberperryb9 Sep '03 - 5:18 
This program is really useful!
 
I was able to connect to a remote machine once, but I can't do it again.
I can ping the remote computer, repeatedly. Any idea what could be the problem? Timeout?
 
I get the following error every time I try:
Connection Error!
Could not copy the service executable to the remote machine!
 
When I was able to connect, I was unable to execute a process. Could you explain how to do it?
 
Again, this is a really great utility.
Thanks in advance for your help.
 
Also, building the project. I get errors of 'undeclared identifier' for NIIF_NONE in systrayicon.h
AnswerRe: Getting Connected?memberPrateek Kaul9 Sep '03 - 18:58 
1. The machine you are trying to connect should be Win 2000 and above.
2. If it is Win 2000 and above, just try restarting the machine you are
trying to connect. May be the service execuatble, that runs secerlty on
the machine you are trying to connect, has not shutdown properly.
3. If the error is "could not copy the service executable to the remote
machine", it means that somebody else has already started the service
executable on the machine. It is just a warning kind of message.
4. You need to get the latest Platform SDK from Microsoft's website, for the
NIIF_NONE error, in case you are using VC++ 6. If you are using
Visual C++ .NET 2002/2003, then the latest files are included with it.
 
Prateek Kaul
Centre for Development of Advanced Computing (C-DAC),
Pune,India
GeneralGreat but where is 'psapi.h'memberbonthuis2 Sep '03 - 21:08 
The demo program works great, but I can not built the code, I'm missing the psapi.h and probably also the .lib and .dll
Where can I find these files?
GeneralRe: Great but where is 'psapi.h'memberPrateek Kaul2 Sep '03 - 21:51 
You will get it when you download the latest Platform SDK from Microsoft's website.
 

 
Prateek Kaul
Centre for Development of Advanced Computing (C-DAC),
Pune,India

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 1 Apr 2012
Article Copyright 2003 by Prateek Kaul
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid