Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

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

, 1 Apr 2012
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)

Share

About the Author

Prateek Kaul
Web Developer
India India
No Biography provided

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