Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / MFC

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

Rate me:
Please Sign up or sign in to vote.
4.80/5 (35 votes)
1 Apr 2012CPOL5 min read 156.8K   8.9K   103  
Control certain aspects of machines sitting remotely, without having to install and trigger an application on the remote machine.
#include "stdafx.h"
#include "ConnectionThread.h"
#include "Command.h"
#include "RemoteAdminView.h"
#include "RemoteAdminDoc.h"
#include "MachineView.h"
#include "GlobalHelperFunc.h"


UINT __stdcall ThreadConnection::ConnectToMachine(void* pParam)
{
    SConnectInfo* pConnectInfo = reinterpret_cast<SConnectInfo*>(pParam);

    CRemoteAdminDoc* pDoc              = pConnectInfo->pDoc;
    CRemoteAdminView* pRemoteAdminView = pConnectInfo->pRemoteAdminView;
    CMachineView* pMachineView         = pConnectInfo->pMachineView;
    CString strIP                      = pConnectInfo->strIP;
    CString strPwd                     = pConnectInfo->strPwd;
    
    // Add to the connection pending list, so that even if someone requests
    // connection for the same machine it will fail.
    pDoc->AddToConnectionPendingList(strIP);

    BOOL bConnectOk = pDoc->EstablishAllConnections(strIP, strPwd, TRUE, pMachineView, pRemoteAdminView);

    if (!bConnectOk)
    {
        //:AfxMessageBox(IDS_CONNECTION_NOT_ESTABLISHED);
        CString strFromatAPIMsg = ErrorHandling::FormatLastError();
        CString strDisplayMsg;
        strDisplayMsg.Format("Machine IP %s: %s", strIP.GetBuffer(0), strFromatAPIMsg.GetBuffer(0));
    }
    else
    {
        // Since one machine has connected, resume the process updation thread
        // This will be called more than once, when every new nachine is conncted.
        // It will only be an extra call, but dosen't harm, we just need to
        // trigger iti
        ::ResumeThread(pDoc->m_hUpdateProcessList);
        
        int iTotalMachineBeingMonitored = pDoc->GetTotalMachinesMonitored();
           
        if (iTotalMachineBeingMonitored == 0) 
        {
            // Clean the list view
            pRemoteAdminView->GetListCtrl().DeleteAllItems();
        }
        else  // Select the latest machine added and show it's processes
        {
            HTREEITEM h = pMachineView->GetTreeItemForText(strIP);

            if (h != NULL)
            {
                //pMachineView->GetTreeCtrl().Select(h, TVGN_CARET);
                pRemoteAdminView->RefreshProcesses(strIP);
            }
        }
    }
 
    // Since the pending connection request is over (failed or succeded), now remove
    // it from the pending connection list
    pDoc->RemoveFromConnecionPendingList(strIP);

	if (pConnectInfo)
	{
		delete pConnectInfo;
	}
    
    return 0;
}

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)


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions