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

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.
// RemoteAdmin.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "RemoteAdmin.h"
#include "AboutDlg.h"
#include "MainFrame.h"
#include "RemoteAdminDoc.h"
#include "MachineView.h"
#include "SplashWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRemoteAdminApp

BEGIN_MESSAGE_MAP(CRemoteAdminApp, CWinApp)
	//{{AFX_MSG_MAP(CRemoteAdminApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRemoteAdminApp construction

CRemoteAdminApp::CRemoteAdminApp()
{
	m_pstTrayIcon = NULL;
}


CRemoteAdminApp::~CRemoteAdminApp()
{
	if (m_pstTrayIcon != NULL)
	{
		delete m_pstTrayIcon;

		m_pstTrayIcon = NULL;
	}
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CRemoteAdminApp object

CRemoteAdminApp theApp;

CRITICAL_SECTION g_CriticalSection;

BOOL g_bUpdateProcessList  = TRUE;
UINT g_iUpdateProcessDelay = 10000;  // in milli secs
UINT g_iShutdownDelay      = 50000; // in milli secs

// << BLOCK START
// << Added by Prateek Kaul on May 21, 2003. to check the number of
// running instances of this application to only one
// Global variables in the shared 
#pragma data_seg("Shared")
LONG g_Counter = -1;
#pragma data_seg()

// Notice to the linker to make the Shared section readable, writable, and shared
#pragma comment(linker, "/section:Shared,rws")
// << BLOCK END


BOOL CRemoteAdminApp::InitInstance()
{
    // Check if another instance already running
    if (!(InterlockedIncrement(&g_Counter) == 0))
    {
        ::AfxMessageBox(IDS_APP_ALREADY_RUNNING);
        
        return FALSE;
    }
    // Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.


	// Initialize WinSock
	::AfxSocketInit();

    #ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CRemoteAdminDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CMachineView));
	AddDocTemplate(pDocTemplate);
    
    CSplashWnd::EnableSplashScreen(TRUE);
    CSplashWnd::ShowSplashScreen(CWnd::GetDesktopWindow());
    ::Sleep(2500);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

 	// The one and only window has been initialized, so show and update it.
	///m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
	m_pMainWnd->UpdateWindow();
    //m_pMainWnd->CenterWindow();
    
    // Used in the thread which updates processes
    ::InitializeCriticalSection(&g_CriticalSection);
    
	return TRUE;
}

void CRemoteAdminApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}


BOOL CRemoteAdminApp::ShowBalloonMsgInTray(CString strTitle, CString strMsgTxt)
{
	return m_pstTrayIcon->ShowBalloon(1, strTitle.GetBuffer(0), strMsgTxt.GetBuffer(0), NIIF_WARNING);
}

BOOL CRemoteAdminApp::CreateAndShowSystemTrayIcon()
{
	// This is supposed to called only once, if this assert triggers it means the function
	// has been called more than once
	ASSERT(m_pstTrayIcon == NULL); 

	if (m_pstTrayIcon == NULL)
	{
		// Create and show the system tray icon
		HICON hTrayIcon = ::AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_MACHINE_ON_NETWORK));
		
		TCHAR szAppName[_MAX_PATH];
		::LoadString(::AfxGetApp()->m_hInstance, IDS_APP_NAME, szAppName, _MAX_PATH);
		
		m_pstTrayIcon = new CRemoteAdminTrayIcon;

		if (m_pstTrayIcon != NULL)
		{
			BOOL bTrayIconCreated = m_pstTrayIcon->CreateIcon(hTrayIcon, 1, szAppName);
			BOOL bTrayIconShown   = m_pstTrayIcon->ShowIcon(1);

			return (bTrayIconCreated && bTrayIconShown);
		}
	}

	// Shouldn't reach here
	return FALSE;
}

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 | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 1 Apr 2012
Article Copyright 2003 by Prateek Kaul
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid