如何在.NET中启动远程协助会话?

时间:2009-02-23 20:34:14

标签: .net winapi rdp

我正在编写帮助台应用程序,并希望允许我的用户在远程PC上启动远程协助会话。这可以通过Windows XP中的“帮助”完成,但我无法在.NET中找到任何代码示例。谢谢!

3 个答案:

答案 0 :(得分:4)

它实际上非常简单,我写这个允许客户端下载一个小exe并单击一个按钮,它会生成远程协助请求票并在后台打开远程协助。然后通过ftp和boom将文件发送到我的服务台服务器,我只需点击一下即可访问客户端计算机。

请确保之后包含递归kill(),这样就不会在后台留下任何延迟进程。

System.Diagnostics.Process p = new System.Diagnostics.Process();
string fileurl = System.IO.Path.GetTempPath() + "Invitation.msrcincident";
p.StartInfo.UseShellExecute = true;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "Msra.exe";
p.StartInfo.Arguments = "/saveasfile " + fileurl + " MyPassword";
Console.WriteLine(p.StartInfo.Arguments);
p.Start();

while (File.Exists(fileurl) == false)
{
   Thread.Sleep(1000);
}

//CODE TO EMAIL/UPLOAD FILE HERE

答案 1 :(得分:1)

http://msdn.microsoft.com/en-us/library/ms811079.aspx

您可能需要P / Invoke来实际访问这些功能。


在进一步审核时,CodePlex上有一些来源可以生成远程协助票证。如果我错了,请纠正我,但是您希望在客户端生成远程协助的票证。查看http://www.codeplex.com/RemoteAssistHelper

答案 2 :(得分:0)

Remote Assistance using the MSRA Exe and its arguments.

Here I have desinged 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 folloiwng 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:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace RemoteAssist
{
    public partial class FrmConnect : Form
    {
        public FrmConnect()
        {
            InitializeComponent();
        }


        private void btnConnect_Click(object sender, EventArgs e)
        {
            RemoteConnect remoteConnect = new RemoteConnect();
            Boolean status;
status = remoteConnect.StartRemoteAssistance(txtComputerName.Text.ToString(), true,false);
            if (status == false)
            {
System.Windows.Forms.MessageBox.Show("Unable to Connect to the Remote Machine.Please try Again later.");
            }


        }

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

            if (status == false)
            {
                System.Windows.Forms.MessageBox.Show("Unable to Establish Connection, Please try Again later.");
            }
        }

        private void FrmConnect_Load(object sender, EventArgs e)
        {

        }

        private void txtComputerName_TextChanged(object sender, EventArgs e)
        {
            txtComputerName.CharacterCasing = CharacterCasing.Upper;
        }             


    }
}

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


Code under the Class File : RemoteConnect


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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 Assitance 
            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 Occured while trying to Connect" + ex.Message);
                return false;
            }           
        }
    }
}
相关问题