Click here to Skip to main content
12,402,641 members (73,682 online)
Click here to Skip to main content

Tagged as

Stats

131.9K views
8.5K downloads
104 bookmarked
Posted

Remote Processes and Machine control of Windows NT based systems (2000/XP)

, 1 Apr 2012 CPOL
Control certain aspects of machines sitting remotely, without having to install and trigger an application on the remote machine.
#ifndef REMOTEADMINISTRATOR_H
#define REMOTEADMINISTRATOR_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>
#include "MachineInfo.h"

typedef CTypedPtrList<CPtrList, CString*>      CConnectionPendingList;
typedef CTypedPtrList<CPtrList, CMachineInfo*> CMachineInfoList;

#define  REMOTE_ADMIN_SERVICE              _T("RemoteAdminService")
#define  REMOTE_ADMIN_SERVICE_EXE          _T("RemoteAdminService.exe")
#define  REMOTE_ADMIN_SERVICE_PIPE         _T("RemoteAdminServivePipe")
#define  SERVICENAME                       _T("RemoteAdminService")
#define  LONGSERVICENAME                   _T("RemoteAdminService")
#define  REMOTE_ADMIN_PIPE                 _T("RempteAdminPipe")
#define  REMOTE_ADMIN_PROCESS_INFO_PIPE    _T("RemoteAdminProcessInfoPipe")
#define  REMOTE_ADMIN_PROCESS_EXECUTE_PIPE _T("RemoteAdminProcessExecutePipe")
#define  REMOTE_ADMIN_PROCESS_KILL_PIPE    _T("RemoteAdminProcessKillPipe")
#define  REMOTE_ADMIN_SYS_SHUTDOWN_PIPE    _T("RemoteAdminSysShutDownPipe")
 

class CRemoteAdministrator  
{
public:
	CRemoteAdministrator();
	virtual ~CRemoteAdministrator();

    BOOL EstablishAllConnections(CString strRemoteMachineIP, CString strPwd, BOOL bEstablish);
    void AddMachine(CMachineInfo& miMachineInfo);
    void DeleteMachine(CMachineInfo& miMachineInfo);
    BOOL CheckIfMachinePresent(CString strIP);
    void RefreshProcessList(CString strIP, CProcessInfoList& pilProcessList);
    CMachineInfo* GetMachineInfo(CString strIP);
    BOOL CopyServiceExeToRemoteMachine(CString strRenoteMachineIP);
    BOOL ConnectToRemoteService(CString strRemoteMachineIP, DWORD dwRetry, DWORD dwRetryTimeOut);
    BOOL InstallAndStartRemoteService(CString strRemoteMachineIP);
    CProcessInfoList* GetProcessInfoList(CString strRemoteMachineIP);
    void DeleteAndDisconnectAllMachines();
    void DeleteAndDisconnectMachine(CString strRemoteAdminMachine);
    void GetConnectedMachinesIP(CString** pstrConnctedMachinesIP /*out*/, int* piNumberOfConnectedMachines/*out*/);
    int GetTotalMachinesMonitored();
    BOOL AddToConnectionPendingList(CString strIP);
    BOOL RemoveFromConnecionPendingList(CString strIP);
    BOOL IsConnectionPending(CString strIP);

    HANDLE GetRemoteAdminPipe(CString strRemoteMachineIP);
    HANDLE GetRemoteAdminProcessInfoPipe(CString strRemoteMachineIP);
    HANDLE GetRemoteAdminProcessExecutePipe(CString strRemoteMachineIP);
    HANDLE GetRemoteAdminProcessKillPipe(CString strRemoteMachineIP);
    HANDLE GetRemoteAdminSysShutDownPipe(CString strRemoteMachineIP);
	CString GetPassword(CString strIP);
	UINT GetNumberOfMachineConnectionsStillInProgress();
	CString GetComputerNameFromIP(CString& strIP);
	CString GetComputerIPFromName(CString& strComputerName);
    
protected:
    CMachineInfoList m_milConnectedMachines;
    CConnectionPendingList m_cplPendingConnectionList;

    HANDLE m_hCommandPipe; 
    BOOL EstablishAdminConnection(CString strRemoteMachineIP, CString strPwd, BOOL bEstablish);
    BOOL EstablishIPCConnection(CString strRemoteMachineIP, CString strPwd, BOOL bEstablish);
    BOOL EstablishConnection(CString strResource, CString strLogon, CString strRemoteMachineIP, CString strPwd, BOOL bEstablish);
};


inline HANDLE CRemoteAdministrator::GetRemoteAdminPipe(CString strRemoteMachineIP)
{
    CMachineInfo* pMachineInfo = GetMachineInfo(strRemoteMachineIP);

    if (pMachineInfo != NULL)
        return pMachineInfo->GetRemoteAdminPipe();
    else
        return NULL;
}

inline HANDLE CRemoteAdministrator::GetRemoteAdminProcessInfoPipe(CString strRemoteMachineIP)
{
    CMachineInfo* pMachineInfo = GetMachineInfo(strRemoteMachineIP);

    if (pMachineInfo != NULL)
        return pMachineInfo->GetRemoteAdminProcessInfoPipe();
    else
        return NULL;
}

inline HANDLE CRemoteAdministrator::GetRemoteAdminProcessExecutePipe(CString strRemoteMachineIP)
{
    CMachineInfo* pMachineInfo = GetMachineInfo(strRemoteMachineIP);
    
    if (pMachineInfo != NULL)
       return pMachineInfo->GetRemoteAdminProcessExecutePipe();
    else
      return NULL;
}

inline HANDLE CRemoteAdministrator::GetRemoteAdminProcessKillPipe(CString strRemoteMachineIP)
{
    CMachineInfo* pMachineInfo = GetMachineInfo(strRemoteMachineIP);

    if (pMachineInfo != NULL)
        return pMachineInfo->GetRemoteAdminProcessKillPipe();
    else
        return NULL;
}

inline HANDLE CRemoteAdministrator::GetRemoteAdminSysShutDownPipe(CString strRemoteMachineIP)
{
    CMachineInfo* pMachineInfo = GetMachineInfo(strRemoteMachineIP);

    if (pMachineInfo != NULL)
        return pMachineInfo->GetRemoteAdminSysShutDownPipe();
    else
        return NULL;
}

#endif // REMOTEADMINISTRATOR_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Prateek Kaul
Web Developer
India India
No Biography provided

You may also be interested in...

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