65.9K
CodeProject is changing. Read more.
Home

Remote Assistance in Windows 7 Using C#.NET

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (2 votes)

Jan 23, 2015

CPOL
viewsIcon

14611

Remote Assistance using the MSRA EXE and its arguments

Introduction

Here, I have designed a class and a form, and it gives you the following functionalities:

  1. Offer Remote Assistance to a Machine
  2. Ask for Remote Help (Invite someone to help you)

Design a form with the following controls:

  1. Textbox for taking the IP or computer name to Connect
  2. Button 1. To connect to the Remote Machine for offering Remote Assistance
  3. Button 2. To ask or invite someone to help

Code behind in the Form is as given below:

private void btnConnect_Click(object sender, EventArgs e)
        {
            RemoteConnect remoteConnect = new RemoteConnect();
            Boolean status;
			status = remoteConnect.StartRemoteAssistance
					(txtComputerName.Text.ToString(), true, false);
            System.Windows.Forms.MessageBox.Show(status.ToString());
        }

			private void BtnInvite_Click(object sender, EventArgs e)
        {
            RemoteConnect remoteConnect = new RemoteConnect();
            Boolean status;
            status = remoteConnect.StartRemoteAssistance
			(txtComputerName.Text.ToString(), false, true);
        }

We have two buttons here and they are sending the Boolean variable to the class function for differentiating between Offer Help and Ask for Help.

Code under the Class File: RemoteConnect is as follows:

namespace RemoteAssist
{
    class RemoteConnect
    {
	public Boolean StartRemoteAssistance
		(String strMachinename, Boolean offerHelp, Boolean askForHelp)
        {            
	System.Diagnostics.Process process = new System.Diagnostics.Process();

	System.Diagnostics.ProcessStartInfo startInfo = 
				new System.Diagnostics.ProcessStartInfo();
	startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;            
            startInfo.FileName = "msra.exe";

            // Offer Remote Assistance 
            if (offerHelp == true)
            {
                startInfo.Arguments = "/offerRA " + strMachinename;
            }

            //ASK for Remote Assistance
            if (askForHelp == true)
            {
                startInfo.Arguments = "novice";
            }

            try
            {
                process.StartInfo = startInfo;
                process.Start();
                return true;
            }

            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show
                ("Error Occurred while processing Remote Assistance" + ex.Message);
                return false;
            }       
        }
    }
}